Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from dastels/master
Example additions and edits
- Loading branch information
Showing
11 changed files
with
214 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import board | ||
from adafruit_turtle import turtle | ||
|
||
turtle = turtle(board.DISPLAY) | ||
turtle.pendown() | ||
|
||
for _ in range(32): | ||
turtle.circle(50, steps=6) | ||
turtle.right(11.1111) | ||
|
||
while True: | ||
pass |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import board | ||
from adafruit_turtle import turtle | ||
|
||
def hilbert2(step, rule, angle, depth, t): | ||
if depth > 0: | ||
a = lambda: hilbert2(step, "a", angle, depth - 1, t) | ||
b = lambda: hilbert2(step, "b", angle, depth - 1, t) | ||
left = lambda: t.left(angle) | ||
right = lambda: t.right(angle) | ||
forward = lambda: t.forward(step) | ||
if rule == "a": | ||
left() | ||
b() | ||
forward() | ||
right() | ||
a() | ||
forward() | ||
a() | ||
right() | ||
forward() | ||
b() | ||
left() | ||
if rule == "b": | ||
right() | ||
a() | ||
forward() | ||
left() | ||
b() | ||
forward() | ||
b() | ||
left() | ||
forward() | ||
a() | ||
right() | ||
|
||
turtle = turtle(board.DISPLAY) | ||
turtle.penup() | ||
|
||
turtle.goto(-80, -80) | ||
turtle.pendown() | ||
hilbert2(5, "a", 90, 5, turtle) | ||
|
||
while True: | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import board | ||
from adafruit_turtle import turtle | ||
|
||
def f(side_length, depth, generation): | ||
if depth == 0: | ||
side = turtle.forward(side_length) | ||
else: | ||
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() | ||
|
||
num_generations = 3 | ||
top_side = lambda: f(top_len, num_generations, 0) | ||
|
||
top_side() | ||
turtle.right(120) | ||
top_side() | ||
turtle.right(120) | ||
top_side() | ||
|
||
while True: | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import board | ||
from adafruit_turtle import turtle | ||
|
||
turtle = turtle(board.DISPLAY) | ||
|
||
|
||
# turtle.penup() | ||
# turtle.right(45) | ||
# turtle.forward(90) | ||
# turtle.right(75) | ||
|
||
turtle.pendown() | ||
for _ in range(21): | ||
for _ in range(6): | ||
turtle.forward(50) | ||
turtle.right(61) | ||
turtle.right(11.1111) | ||
|
||
while True: | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import board | ||
from adafruit_turtle import turtle, Color | ||
|
||
generation_colors = [Color.RED, Color.BLUE, Color.GREEN] | ||
|
||
def f(side_length, depth, generation): | ||
if depth == 0: | ||
side = turtle.forward(side_length) | ||
else: | ||
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): | ||
top_side = lambda: f(top_len, num_generations, 0) | ||
turtle.pencolor(generation_color) | ||
top_side() | ||
turtle.right(120) | ||
top_side() | ||
turtle.right(120) | ||
top_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() | ||
|
||
for generations in range(3): | ||
snowflake(generations, generation_colors[generations]) | ||
turtle.right(120) | ||
|
||
while True: | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import board | ||
from adafruit_turtle import turtle | ||
|
||
def getMid(p1, p2): | ||
return ((p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2) #find midpoint | ||
|
||
def triangle(points, depth): | ||
|
||
turtle.penup() | ||
turtle.goto(points[0][0], points[0][1]) | ||
turtle.pendown() | ||
turtle.goto(points[1][0], points[1][1]) | ||
turtle.goto(points[2][0], points[2][1]) | ||
turtle.goto(points[0][0], points[0][1]) | ||
|
||
if depth > 0: | ||
triangle([points[0], | ||
getMid(points[0], points[1]), | ||
getMid(points[0], points[2])], | ||
depth-1) | ||
triangle([points[1], | ||
getMid(points[0], points[1]), | ||
getMid(points[1], points[2])], | ||
depth-1) | ||
triangle([points[2], | ||
getMid(points[2], points[1]), | ||
getMid(points[0], points[2])], | ||
depth-1) | ||
|
||
turtle = turtle(board.DISPLAY) | ||
big = min(board.DISPLAY.width / 2, board.DISPLAY.height / 2) | ||
little = big / 1.4 | ||
seed_points = [[-big, -little], [0, big], [big, -little]] #size of triangle | ||
triangle(seed_points, 4) | ||
|
||
while True: | ||
pass |
This file contains 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
This file contains 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