Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Spiral Graphics for Pimoroni Pico Display 2 320x240 pixels
- # Uses Pimoroni Pico Graphics system
- # Tony Goodhew 6th Febrary 2023
- import time
- import math
- from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P4
- from pimoroni import RGBLED
- # Reduced colours to save RAM
- display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P4, rotate=0)
- display.set_backlight(0.8)
- display.set_font("bitmap8") # Lower case included
- led = RGBLED(6, 7, 8)
- led.set_rgb(0,0,0) # Turn RGBLED OFF
- # ==== Board now setup ====
- def end_point(theta, long): # Calculate end of line offsets - angle & length
- theta_rad = math.radians(theta)
- theta_rad = math.radians(theta)
- xx = int(long * math.sin(theta_rad))
- yy = -int(long * math.cos(theta_rad))
- return xx,yy
- # === Main Program ===
- BLACK = display.create_pen(0,0,0)
- w = display.create_pen(255,255,255)
- r = display.create_pen(255,0,0)
- g = display.create_pen(0,255,0)
- b = display.create_pen(0,0,255)
- y = display.create_pen(255,255,0)
- c = display.create_pen(0,255,255)
- m = display.create_pen(255,0,255)
- gr = display.create_pen(180,180,180)
- o = display.create_pen(255,128,30)
- display.set_pen(BLACK)
- display.clear()
- display.update()
- display.set_font("bitmap8")
- display.set_pen(g)
- display.text("Spiral Lines", 20, 70, 200, 4)
- display.set_pen(w)
- display.text("Tony Goodhew", 20, 120, 200, 2)
- display.update()
- time.sleep(1.5)
- colours = [r,y,g,c,b,m,w,o,gr]
- alpha = [0,1,2,119,89,72,59,51,43] # Turn angles
- dl = [0,0,0,2,1,1,1,1,1] # Extra length
- for cc in range(3,9,1):
- display.set_pen(BLACK)
- display.clear() # Clear the screen
- display.update()
- xold = 159 # Coordinates of start point
- yold = 119
- l = 1
- theta = 0
- for i in range(120):
- xx, yy = end_point(theta, l) # Get offset
- xnext = xold+xx
- ynext = yold+yy
- display.set_pen(colours[i % cc])
- display.line(xold,yold,xnext,ynext)
- display.update()
- xold = xnext
- yold = ynext
- l = l + dl[cc]
- theta = theta + alpha[cc]
- time.sleep(0.01)
- time.sleep(1.5)
- # Finish & tidy up
- display.set_pen(BLACK)
- display.clear()
- display.set_pen(g)
- display.text("All Done!", 50, 70, 200, 4)
- display.update()
- time.sleep(2)
- display.set_pen(BLACK)
- display.clear()
- display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement