|
| 1 | +# Turtle Gizmo Sierpinski Triangle |
| 2 | +#==| Turtle Gizmo Setup start |======================================== |
| 3 | +import board |
| 4 | +import busio |
| 5 | +import displayio |
| 6 | +from adafruit_st7789 import ST7789 |
| 7 | +from adafruit_turtle import turtle |
| 8 | +displayio.release_displays() |
| 9 | +spi = busio.SPI(board.SCL, MOSI=board.SDA) |
| 10 | +display_bus = displayio.FourWire(spi, command=board.TX, chip_select=board.RX) |
| 11 | +display = ST7789(display_bus, width=240, height=240, rowstart=80, |
| 12 | + backlight_pin=board.A3, rotation=180) |
| 13 | +turtle = turtle(display) |
| 14 | +#==| Turtle Gizmo Setup end |========================================= |
| 15 | + |
| 16 | +def getMid(p1, p2): |
| 17 | + return ((p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2) #find midpoint |
| 18 | + |
| 19 | +def triangle(points, depth): |
| 20 | + |
| 21 | + turtle.penup() |
| 22 | + turtle.goto(points[0][0], points[0][1]) |
| 23 | + turtle.pendown() |
| 24 | + turtle.goto(points[1][0], points[1][1]) |
| 25 | + turtle.goto(points[2][0], points[2][1]) |
| 26 | + turtle.goto(points[0][0], points[0][1]) |
| 27 | + |
| 28 | + if depth > 0: |
| 29 | + triangle([points[0], |
| 30 | + getMid(points[0], points[1]), |
| 31 | + getMid(points[0], points[2])], |
| 32 | + depth-1) |
| 33 | + triangle([points[1], |
| 34 | + getMid(points[0], points[1]), |
| 35 | + getMid(points[1], points[2])], |
| 36 | + depth-1) |
| 37 | + triangle([points[2], |
| 38 | + getMid(points[2], points[1]), |
| 39 | + getMid(points[0], points[2])], |
| 40 | + depth-1) |
| 41 | + |
| 42 | +big = min(display.width/2, display.height/2) |
| 43 | +little = big / 1.4 |
| 44 | +seed_points = [[-big, -little], [0, big], [big, -little]] #size of triangle |
| 45 | +triangle(seed_points, 4) |
| 46 | + |
| 47 | +while True: |
| 48 | + pass |
0 commit comments