From d70d57abca4cb48572114fb0dfc79e8e24006a3c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 10:55:38 -0700 Subject: [PATCH 1/2] Fix koch example --- examples/turtle_koch.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/turtle_koch.py b/examples/turtle_koch.py index 9332a36..f04c919 100644 --- a/examples/turtle_koch.py +++ b/examples/turtle_koch.py @@ -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() From 480352b7b9464ffb0dfda99907bc64c588a5f732 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 10:57:41 -0700 Subject: [PATCH 2/2] Fix overlayed koch --- examples/turtle_overlayed_koch.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/turtle_overlayed_koch.py b/examples/turtle_overlayed_koch.py index cd92939..0bfe018 100644 --- a/examples/turtle_overlayed_koch.py +++ b/examples/turtle_overlayed_koch.py @@ -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): @@ -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)