In this project, the restriction is: next vertex has to be immediate neighbors of the previous vertex or the same vertex as the previous vertex. This restriction should draw following figures from pentagon to decagon.
In a previous project, you drew a Sierpinski Triangle with Chaos Game. Instead of a triangle, use four points of a square as the target points and play the chaos game. There is restriction: you can’t choose a vertex that is 2 places away. That is: you can only move to the same vertex as the last move or the immediate neighbor of the last move. It should draw something like this after 100,000 iterations:
In a previous project, you drew a Sierpinski Triangle with Chaos Game. Instead of a triangle, use four points of a square as the target points and play the chaos game. There is restriction: you can’t choose the same direction as the last move. It should draw something like this after 100,000 iterations:
Draw three points to form a triangle. Draw the fourth point in a random position. In each of the following step, this point will move halfway towards one of the three randomly chosen points of the original triangle. Repeat the above step 1000, 10,000, and 100,000 times. You will see a Sierpinski Triangle! This process is an example of Chaos Game.
Solution:
import turtle
import random
screen = turtle.Screen()
screen.title('Triangle Chaos Game with Python Turtle')
screen.setup(1000,1000)
screen.tracer(0,0)
turtle.hideturtle()
turtle.speed(0)
turtle.up()
A = (0,350)
B = (-300,-200)
C = (300,-200)
V = (A,B,C) # list of three vertices
for v in V:
turtle.goto(v)
turtle.dot('red')
n = 10000 # number of points to draw
p = (random.uniform(-200,200),random.uniform(-200,200)) # random starting point
t = turtle.Turtle()
t.up()
t.hideturtle()
for i in range(n):
t.goto(p)
t.dot(2,'blue')
r = random.randrange(len(V)) # pick a random vertex
p = ((V[r][0]+p[0])/2,(V[r][1]+p[1])/2) # go to mid point between the random vertex and point
if i % 1000 == 0: # update for every 1000 moves, this part is for performance reason only
t = turtle.Turtle() # use new turutle
t.up()
t.hideturtle()
screen.update()
Develop the Asteroids Game with Python Turtle. Because this project is fairly large, you may want to use Object Oriented Programming by defining several classes and put them in separate files. You may also need to know how to detect collisions. These projects will help you develop this game:
Write a program that finds the closest point of a line segment to another point. Randomly pick a point and color it in blue. Also, randomly generate several lines. Find the closest points on these lines to the blue point and mark these closest points in red as show in the picture below:
Generate a random polygon with many sides and randomly drop point on the screen. If the point falls inside the polygon color it in red, otherwise color it in blue.
Continuing from previous Accelerating and Rotating Spaceship project, make the spaceship fire the bullets. Each bullet have limited range and there should be some time gap between the firings so that spaceship won’t destroy asteroids too easily in the future game. You may need to use list structure in Python to store the bullets.