Skip to content

Instantly share code, notes, and snippets.

@quackduck
Created June 10, 2022 03:48
Show Gist options
  • Save quackduck/82d7a9f96d7cd1227aa47213732b2b2e to your computer and use it in GitHub Desktop.
Save quackduck/82d7a9f96d7cd1227aa47213732b2b2e to your computer and use it in GitHub Desktop.
random color sierpinski triangle
import turtle
import random
def randColor():
t.color(random.random(), random.random(), random.random())
def draw_sierpinski(length, depth):
if depth==0:
for i in range(0,3):
t.fd(length)
t.left(120)
return
# t.color("red")
randColor()
draw_sierpinski(length/2,depth-1)
t.fd(length/2)
# t.color("blue")
randColor()
draw_sierpinski(length/2,depth-1)
t.bk(length/2)
t.left(60)
t.fd(length/2)
t.right(60)
# t.color("green")
randColor()
draw_sierpinski(length/2,depth-1)
t.left(60)
t.bk(length/2)
t.right(60)
t = turtle.Turtle()
t.width(1)
t.speed(15)
t.penup()
t.goto(-170, -170)
t.pendown()
draw_sierpinski(400, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment