Created
June 10, 2022 03:48
-
-
Save quackduck/82d7a9f96d7cd1227aa47213732b2b2e to your computer and use it in GitHub Desktop.
random color sierpinski triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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