Massive Chasing Game (with Source Code)

In this Python Turtle project, you are going create a fun and beautiful animation. First, you are going to create a list of 100 turtles and put them into random positions. Set the color of these turtles gradually from hue value 0 to hue value 1. In each iteration, each turtle will move toward a small step toward the next turtle in the list. The last turtle in the list will move toward the first turtle. Repeat the iteration forever. These turtles will converge into a beautiful rainbow colored shape!

Video of this animation:

Source Code:

import turtle
import random
import colorsys

screen = turtle.Screen()
screen.tracer(0,0)
screen.setup(1000,1000)
turtle.hideturtle()

n=100
chasers = []
for i in range(n):
    chasers.append(turtle.Turtle())

h = 0
for i in range(n):
    c = colorsys.hsv_to_rgb(h,1,0.8)
    h += 1/n
    chasers[i].color(c)
    chasers[i].up()
    chasers[i].goto(random.uniform(-500,500), random.uniform(-500,500))

def chase():
    for i in range(n-1):
        angle = chasers[i].towards(chasers[i+1])
        chasers[i].seth(angle)
    angle = chasers[n-1].towards(chasers[0])
    chasers[n-1].seth(angle)
    for i in range(n):
        chasers[i].fd(2)
    screen.update()
    screen.ontimer(chase,1000//20)
    
chase()

Capture The Flags Game

In this Python Turtle project, you are going to develop a simple game. In this game, you create 11 flags in random positions. The player will control an emoji by keyboard to collect as many flags as possible before the timer expires.

To be able to finish this project, you need to know the basics of animation, timer and keyboard events in Turtle. You will also need to know list in Python and how to display unicode characters.

Check out animation of this project here:

Random Rectangles with Python Turtle (with Solution)

In this project, you are going to one hundred random rectangles filled with random colors. You will learn for loop, function, random library, and setting color with (r,g,b).

Video demo of this project can be found here:

Solution:

import turtle
import random

def draw_retangle(x,y,w,h,color):
    turtle.up()
    turtle.seth(0)
    turtle.goto(x-w/2,y-h/2)
    turtle.fillcolor(color)
    turtle.down()
    turtle.begin_fill()
    for i in range(2):
        turtle.fd(w)
        turtle.left(90)
        turtle.fd(h)
        turtle.left(90)
    turtle.end_fill()

turtle.setup(700,700)
turtle.title("Random Rectangles - PythonTurtle.Academy")
turtle.speed(0)
turtle.hideturtle()
n = 100
for i in range(n):
    draw_retangle(random.randint(-300,300),random.randint(-300,300),
                     random.randint(5,100),random.randint(5,100),
                     (random.uniform(0,1),random.uniform(0,1),random.uniform(0,1)))

Circle Matrix with Python Turtle (with Solution)

In this simple python turtle project, you are going to draw a 10×10 matrix of connected circles. You can either use nested loops or define a function that draws a line of circles and and call this function in a single loop.

Solution

import turtle

def draw_circle(x,y,r):
    turtle.up()
    turtle.seth(0)
    turtle.goto(x,y-r)
    turtle.down()
    turtle.circle(r)

def draw_a_line_of_circles(x,y,r,n):
    for i in range(n):
        draw_circle(x,y,r)
        x += 2*r
    
turtle.setup(900,900)
turtle.title("Circle Matrix - PythonTurtle.Academy")
turtle.speed(0)
turtle.hideturtle()
y = 300
radius=30
for i in range(10):
    draw_a_line_of_circles(-300,y,radius,10)
    y -= radius*2

Rainbow Colored Tree with Python Turtle (with Solution)

In this python turtle project, you are going to draw a beautifully colored tree with recursion.

Related Projects:

Solution

import turtle
import colorsys

def draw_stick(x,y,length,pensize,color,angle):
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(angle)
    turtle.pensize(pensize)
    turtle.down()
    turtle.color(color)
    turtle.fd(length)

def draw_tree(x,y,length,pensize,hue,angle,fat_angle,n):
    if n == 0:
        return
    (r,g,b) = colorsys.hsv_to_rgb(hue,1,1)
    draw_stick(x,y,length,pensize,(r,g,b),angle)
    tx = turtle.xcor()
    ty = turtle.ycor()
        
    draw_tree(tx,ty,length*0.7,pensize*0.7,hue-1/13,angle+fat_angle,fat_angle,n-1)
    draw_tree(tx,ty,length*0.7,pensize*0.7,hue-1/13,angle-fat_angle,fat_angle,n-1)
    
turtle.setup(800,800)
turtle.title("Rainbow Colored Tree - PythonTurtle.Academy")
turtle.speed(0)
turtle.hideturtle()
turtle.tracer(0)
turtle.bgcolor('black')

draw_tree(0,-300,200,10,12/13,90,25,12)
turtle.update()

Drawing Rainbow with Python Turtle (Solution Included)

In this python turtle project, you are going to draw a 7-color rainbow and a 49-color rainbow. You need to know for loop, drawing circle, and converting HSV (Hue-Saturation-Value) colorspace to RGB colorspace using the colorsys library.
7 Color Rainbow
49 Color Rainbow

Code:

import turtle
import colorsys

def draw_one_color_arc(x,y,r,pensize,color):
    turtle.up()
    turtle.goto(x+r,y)
    turtle.down()
    turtle.seth(90)
    turtle.pensize(pensize)
    turtle.pencolor(color)
    turtle.circle(r,180)
    

turtle.speed(0)
turtle.hideturtle()
turtle.bgcolor('light blue')
turtle.title('49-Color Rainbow')
turtle.setup(700,700)
num_colors = 49

radius = 300
penwidth = 20*7/num_colors
hue = 0
for i in range(num_colors):
    (r,g,b) = colorsys.hsv_to_rgb(hue,1,1)
    draw_one_color_arc(0,-100,radius,penwidth,(r,g,b))
    radius -= (penwidth-1) #overlapping a little removes the gaps
    hue += 0.9/num_colors

Related Projects: