Skip to content

Fix koch examples #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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