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




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

   def changeColor(self, amt = 8):
       self._color += amt
       if self._color >=360:
           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:
           self.addCircle()

       # 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:
               circ.grow()
               circ.changeColor()

       self._step+=amt
       # don't let our step counter grow endlessly
       if self._step>=100:
           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))

usage
Code:
anim = CirclePop(led)
anim.run(max_steps = 2000, fps = 20, max_cycles=1)


Attached Files
.txt   circlepop.txt (Size: 2.29 KB / Downloads: 5)
#2
Nice! That just topped the list of one of my favorite animations Smile
#3
Curious... what hardware are you driving the display with? I always like to see how people use BiblioPixel.
#4
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.

grtz


Forum Jump:


Users browsing this thread: 1 Guest(s)