Advertisement
TonyGo

Spiral Lines

Feb 7th, 2023
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | Software | 0 0
  1. # Spiral Graphics for Pimoroni Pico Display 2 320x240 pixels
  2. # Uses Pimoroni Pico Graphics system
  3. # Tony Goodhew 6th Febrary 2023
  4.  
  5. import time
  6. import math
  7.  
  8. from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P4
  9. from pimoroni import RGBLED
  10. # Reduced colours to save RAM
  11. display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P4, rotate=0)
  12. display.set_backlight(0.8)
  13. display.set_font("bitmap8") # Lower case included
  14.  
  15. led = RGBLED(6, 7, 8)
  16. led.set_rgb(0,0,0)     # Turn RGBLED OFF
  17.  
  18. # ==== Board now setup ====
  19. def end_point(theta, long): # Calculate end of line offsets - angle & length
  20.     theta_rad = math.radians(theta)                      
  21.     theta_rad = math.radians(theta)    
  22.     xx = int(long * math.sin(theta_rad))
  23.     yy = -int(long * math.cos(theta_rad))                    
  24.     return xx,yy
  25.  
  26. # === Main Program ===
  27. BLACK = display.create_pen(0,0,0)
  28. w = display.create_pen(255,255,255)
  29. r = display.create_pen(255,0,0)
  30. g = display.create_pen(0,255,0)
  31. b = display.create_pen(0,0,255)
  32. y = display.create_pen(255,255,0)
  33. c = display.create_pen(0,255,255)
  34. m = display.create_pen(255,0,255)
  35. gr = display.create_pen(180,180,180)
  36. o = display.create_pen(255,128,30)
  37.        
  38. display.set_pen(BLACK)
  39. display.clear()
  40. display.update()
  41. display.set_font("bitmap8")
  42. display.set_pen(g)
  43. display.text("Spiral Lines", 20, 70, 200, 4)
  44. display.set_pen(w)
  45. display.text("Tony Goodhew", 20, 120, 200, 2)
  46. display.update()
  47. time.sleep(1.5)
  48. colours = [r,y,g,c,b,m,w,o,gr]
  49. alpha = [0,1,2,119,89,72,59,51,43] # Turn angles
  50. dl = [0,0,0,2,1,1,1,1,1]           # Extra length
  51.  
  52. for cc in range(3,9,1):
  53.     display.set_pen(BLACK)
  54.     display.clear()  # Clear the screen
  55.     display.update()
  56.     xold = 159  # Coordinates of start point
  57.     yold = 119
  58.     l = 1
  59.     theta = 0
  60.     for i in range(120):
  61.         xx, yy = end_point(theta, l) # Get offset
  62.         xnext = xold+xx
  63.         ynext = yold+yy
  64.         display.set_pen(colours[i % cc])
  65.         display.line(xold,yold,xnext,ynext)
  66.         display.update()
  67.         xold = xnext
  68.         yold = ynext
  69.         l = l + dl[cc]
  70.         theta = theta + alpha[cc]  
  71.         time.sleep(0.01)
  72.     time.sleep(1.5)
  73.    
  74. # Finish & tidy up    
  75. display.set_pen(BLACK)
  76. display.clear()
  77. display.set_pen(g)
  78. display.text("All Done!", 50, 70, 200, 4)
  79. display.update()
  80. time.sleep(2)
  81. display.set_pen(BLACK)
  82. display.clear()
  83. display.update()
Tags: graphics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement