Skip to content

Instantly share code, notes, and snippets.

Last active February 1, 2021 15:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save seantibor/e533b1a1baaab28bff566108acdf89d6 to your computer and use it in GitHub Desktop.
# Write your code here :-)
# idea from this YouTube video:
import random
import turtle as t
def midpoint(point1, point2):
# given two coordinates, find the point halfway between them
x1, y1 = point1
x2, y2 = point2
x = (x1 + x2) / 2
y = (y1 + y2) / 2
return (x, y)
def plot_point(x, y, label=None, radius=2):
# plots a single point in turtle
t.goto(x, y)
if label:
t.goto(x+10, y)
t.write(label, font=('Arial', 16, 'normal'))
#make three points of a triangle
triangle = {"a": (0, 200), "b": (-200, -100), "c": (200, -100)}
# make it go fast
# plot the initial triangle
for label, point in triangle.items():
plot_point(*point, label=label)
# start at a point halfway between a and b
current_point = midpoint(triangle['a'], triangle['b'])
# make a list of the vertices for later
vertices = list(triangle.values())
for i in range(1000):
#pick one of the vertices at random
destination = random.choice(vertices)
# find a point halfway between the current point and the random vertex
# make that the new current point
current_point = midpoint(current_point, destination)
input("Type Enter to end")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment