Skip to content

Commit

Permalink
Merge pull request #34 from adafruit/tannewt-fix-koch
Browse files Browse the repository at this point in the history
Fix koch examples
  • Loading branch information
FoamyGuy authored Jul 29, 2023
2 parents 751760e + 480352b commit 93ea97b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
21 changes: 11 additions & 10 deletions examples/turtle_koch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@


def f(side_length, depth, generation):
if depth != 0:
side = lambda: f(side_length / 3, depth - 1, generation + 1)
side()
turtle.left(60)
side()
turtle.right(120)
side()
turtle.left(60)
side()
if depth == 0:
turtle.forward(side_length)
return
side = lambda: f(side_length / 3, depth - 1, generation + 1)
side()
turtle.left(60)
side()
turtle.right(120)
side()
turtle.left(60)
side()


turtle = turtle(board.DISPLAY)

unit = min(board.DISPLAY.width / 3, board.DISPLAY.height / 4)
top_len = unit * 3
print(top_len)
turtle.penup()
turtle.goto(-1.5 * unit, unit)
turtle.pendown()
Expand Down
24 changes: 13 additions & 11 deletions examples/turtle_overlayed_koch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
import board
from adafruit_turtle import turtle, Color

generation_colors = [Color.RED, Color.BLUE, Color.GREEN]
generation_colors = [Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW]


def f(side_length, depth, generation):
if depth != 0:
side = lambda: f(side_length / 3, depth - 1, generation + 1)
side()
turtle.left(60)
side()
turtle.right(120)
side()
turtle.left(60)
side()
if depth == 0:
turtle.forward(side_length)
return
side = lambda: f(side_length / 3, depth - 1, generation + 1)
side()
turtle.left(60)
side()
turtle.right(120)
side()
turtle.left(60)
side()


def snowflake(num_generations, generation_color):
Expand All @@ -42,7 +44,7 @@ def snowflake(num_generations, generation_color):
turtle.goto(-1.5 * unit, unit)
turtle.pendown()

for generations in range(3):
for generations in range(4):
snowflake(generations, generation_colors[generations])
turtle.right(120)

Expand Down

0 comments on commit 93ea97b

Please sign in to comment.