Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. from bibliopixel import *
  2. from bibliopixel.led import *
  3. from bibliopixel.animation import BaseCircleAnim
  4.  
  5. class DiskBloom(BaseCircleAnim):
  6.  
  7. def __init__(self, led, spread = 1):
  8. super(DiskBloom, self).__init__(led)
  9. self._dir = dir
  10. self.spread = spread
  11.  
  12. def step(self, amt = 8):
  13. for i in range(self.ringCount):
  14. c = colors.hue_helper(i, int(self.ringCount * self.spread), self._step)
  15. self._led.fillRing(i, c)
  16.  
  17. self._step += amt
  18. if(self._step >= 255):
  19. self._step = 0
  20.  
  21. class ArcRotate(BaseCircleAnim):
  22.  
  23. def __init__(self, led, colors, arc = 180, outterRing = -1):
  24. super(ArcRotate, self).__init__(led)
  25. if outterRing < 0 or outterRing > self._led.lastRing:
  26. outterRing = self._led.lastRing
  27. self.outterRing = outterRing
  28. self.colors = colors
  29. self.arcCount = len(self.colors)
  30. self.arc = arc/2
  31.  
  32. def step(self, amt = 1):
  33. led.all_off()
  34. ci = 0
  35. for r in range(self.outterRing, self.outterRing - self.arcCount, -1):
  36. c = self.colors[ci]
  37. ci += 1
  38. self._led.fillRing(r, c, startAngle=self._step-self.arc, endAngle=self._step+self.arc)
  39. self._step += amt
  40. self._step %= 360
  41.  
  42. class PacMan(BaseCircleAnim):
  43.  
  44. def __init__(self, led, color, maxOpen = 90, outterRing = -1):
  45. super(PacMan, self).__init__(led)
  46. if outterRing < 0 or outterRing > self._led.lastRing:
  47. outterRing = self._led.lastRing
  48. self.outterRing = outterRing
  49. self.color = color
  50. self.eyeColor = (0,0,0)
  51. self.eyePoint = int((self.outterRing+1)/2)
  52. self.maxOpen = maxOpen/2
  53. self._dir = 1
  54.  
  55. def step(self, amt = 8):
  56. led.all_off()
  57. for r in range(self.outterRing + 1):
  58. self._led.fillRing(r, self.color, startAngle=90+self._step+self._led.ringSteps[self.outterRing], endAngle=90-self._step)
  59.  
  60. self._led.drawRadius(self._led.ringSteps[self.outterRing]*3, self.eyeColor, self.eyePoint, self.eyePoint)
  61.  
  62. if self._step >= self.maxOpen or (self._dir < 1 and self._step < 5):
  63. self._dir = self._dir * -1
  64. self._step += (amt * self._dir)
  65.  
  66.  
  67. import time
  68. class ArcClock(BaseCircleAnim):
  69.  
  70. def __init__(self, led, secRing = -1, minRing = -1, hourRing = -1):
  71. super(ArcClock, self).__init__(led)
  72. self._internalDelay = 250 #only run 4 times per second
  73. self.hourRing = hourRing
  74. self.secRing = secRing
  75. if self.secRing < 0:
  76. self.secRing = self.lastRing
  77. self.minRing = minRing
  78. if self.minRing < 0:
  79. self.minRing = self.lastRing - 1
  80. if self.hourRing < 0:
  81. self.hourRing = self.lastRing - 2
  82.  
  83.  
  84. def step(self, amt = 1):
  85. led.all_off()
  86. t = time.localtime()
  87. h = t.tm_hour
  88. m = t.tm_min
  89. s = t.tm_sec
  90.  
  91. self._led.fillRing(self.hourRing, colors.Red, startAngle=0, endAngle=(h%12)*(360/12))
  92. self._led.fillRing(self.minRing, colors.Green, startAngle=0, endAngle=m*(360/60))
  93. self._led.fillRing(self.secRing, colors.Blue, startAngle=0, endAngle=s*(360/60))
  94.  
  95. class RadiusClock(BaseCircleAnim):
  96.  
  97. def __init__(self, led, secRing = -1, minRing = -1, hourRing = -1):
  98. super(RadiusClock, self).__init__(led)
  99. self._internalDelay = 250 #only run 4 times per second
  100. self.hourRing = hourRing
  101. self.secRing = secRing
  102. if self.secRing < 0:
  103. self.secRing = self.lastRing
  104. self.minRing = minRing
  105. if self.minRing < 0:
  106. self.minRing = self.lastRing - 1
  107. if self.hourRing < 0:
  108. self.hourRing = self.lastRing - 2
  109.  
  110.  
  111. def step(self, amt = 1):
  112. led.all_off()
  113. t = time.localtime()
  114. h = t.tm_hour
  115. m = t.tm_min
  116. s = t.tm_sec
  117.  
  118. self._led.drawRadius(angle=(h%12)*(360/12), color = colors.Red, endRing = self.hourRing)
  119. self._led.drawRadius(angle=m*(360/60), color = colors.Green, endRing = self.minRing)
  120. self._led.drawRadius(angle=s*(360/60), color = colors.Blue, endRing = self.secRing)
  121.  
  122. class PinWheel(BaseCircleAnim):
  123.  
  124. def __init__(self, led, colors, blades = 3, startRing=0, endRing = -1):
  125. super(PinWheel, self).__init__(led)
  126. self.colors = colors;
  127. self.blades = blades
  128. self.sepDegrees = 360.0 / self.blades;
  129. self.startRing = startRing
  130. self.endRing = endRing
  131.  
  132. def step(self, amt = 1):
  133. led.all_off()
  134. for i in range(self.blades):
  135. self._led.drawRadius(angle=self._step + (i * self.sepDegrees), color = self.colors[i%len(self.colors)], startRing = self.startRing, endRing = self.endRing)
  136.  
  137. self._step += amt
  138. self._step %= 360
  139.  
  140. rings = [
  141. [254,254], #0 - Center Point
  142. [248,253], #1
  143. [236,247], #2
  144. [216,235], #3
  145. [192,215], #4
  146. [164,191], #5
  147. [132,163], #6
  148. [92,131], #7
  149. [48,91], #8
  150. [0,47], #9 - Outer Ring
  151. ]
  152.  
  153. full_rings = []
  154. for r in rings:
  155. full_rings.append(range(r[0], r[1]+1, 1))
  156.  
  157. def frange(start, end, step):
  158. while start < end:
  159. yield start
  160. start += step
  161.  
  162. if __name__ == '__main__':
  163. import bibliopixel.log as log
  164. log.setLogLevel(log.DEBUG)
  165.  
  166. from bibliopixel.drivers.serial_driver import *
  167. import bibliopixel.gamma as gamma
  168. driver = DriverSerial(LEDTYPE.APA102, 255, c_order=ChannelOrder.BGR, gamma=gamma.APA102, SPISpeed=12)
  169.  
  170. led = LEDCircle(driver, full_rings, threadedUpdate=False, rotation=0, maxAngleDiff = 0)
  171. led.setMasterBrightness(64)
  172.  
  173. rainbow = [colors.Red, colors.Orange, colors.Yellow, colors.Green, colors.Blue, colors.Purple]
  174. try:
  175.  
  176. while True:
  177. anim = PinWheel(led, colors = rainbow, blades = 6, startRing=2)
  178. anim.run(amt = 7.5, fps = 45, max_steps=48*6)
  179. anim = PacMan(led, colors.Yellow, maxOpen=90, outterRing=-1)
  180. anim.run(amt=4, fps=45, max_steps=160)
  181. anim = DiskBloom(led, spread = 1)
  182. anim.run(amt=-6, fps=45, max_steps=160)
  183. anim = ArcRotate(led, colors = rainbow, arc=120, outterRing=-1)
  184. anim.run(amt=15, fps=30, max_steps=180)
  185. anim = ArcClock(led, secRing=-1, minRing=-1, hourRing=-1)
  186. anim.run(max_steps=50)
  187. # anim = RadiusClock(led, secRing=-1, minRing=-1, hourRing=-1)
  188. # anim.run(max_steps=50)
  189.  
  190. except KeyboardInterrupt:
  191. led.all_off()
  192. led.update()
  193. time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement