Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

#reusable helper class
class Circle():
   def __init__(self, posy, posx, color, frameratio, radius):
       self._color= color
       self.frameratio=frameratio # animation speed of a single circle relative to the fps of the actual animation.
   def grow(self, amt = 1):
       self._radius += amt

   def changeColor(self, amt = 8):
       self._color += amt
       if self._color >=360:

#animation class
class CirclePop(BaseMatrixAnim):
   def __init__(self, led, bgcolor=colors.Off):
       super(CirclePop, self).__init__(led)
       self.cont = [] # list for storing Circle objects
       self.max_circ = 3 # max number of cirles in the list
       self.prob_circ = 8 # probability for adding a new Circle to the list. higher values make it less probable.
       self.bgcolor = bgcolor
       self.addCircle() # add a first circle to our list
   def step(self, amt=1):
       self._led.fillScreen(self.bgcolor) #background color
       # check if we may add a new circle to the list
       if not random.randrange(self.prob_circ) and len(self.cont) <= self.max_circ:

       # loop through our circles, draw and update them
       for circ in self.cont:
           self._led.drawCircle(circ._x, circ._y, circ._radius, colors.hue2rgb_360(circ._color))

           if not self._step%circ.frameratio:

       # don't let our step counter grow endlessly
       if self._step>=100:

       # remove circles that have grown bigger than our matrix
       self.cont = [c for c in self.cont if c._radius != max(self._led.height, self._led.width)+1]

   def addCircle(self):
       # let's add some randomness. You can play with these values.
       posx = random.randint(3, self._led.width-3)
       posy = random.randint(3, self._led.height-3)
       color = random.randint(1, 359)
       frameratio = random.choice([1,2]) # choose between 2 speeds fps/1 and fps/2.
       radius = 1
       self.cont.append(Circle(posy, posx, color, frameratio, radius))

anim = CirclePop(led) = 2000, fps = 20, max_cycles=1)

Attached Files
.txt   circlepop.txt (Size: 2.29 KB / Downloads: 5)
Nice! That just topped the list of one of my favorite animations Smile
Curious... what hardware are you driving the display with? I always like to see how people use BiblioPixel.
Hi there,

I'm just using my raspberry pi to drive the leds. My matrix is made from LPD8806 led strip. Since everything is running smooth I don't need an extra micro controller to drive the leds. However I might grab my teensy if I want to do something more fancy.


Forum Jump:

Users browsing this thread: 1 Guest(s)