Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Icicle Dripping
#1
Hello All,

I am trying to create an animation that will "drip" down an icicle while changing colors. I guess I am not following on how to make an animation. Here is what I put together.

Code:
import bibliopixel
from bibliopixel.drivers.serial_driver import *
from bibliopixel.led import *


from bibliopixel.animation import BaseStripAnim

class Icicle(BaseStripAnim):
    
    def _init_(self, led, start, end):
        super(Icicle, self).__init__(led, start, end)
        #color starts at blue
        self._color = (0,0,255)
        #sets current pixel to the start
        self._current = start
        #Converts tuple to RGB
        R,G,B = (0,0,255)
        #gets the incraments the color has to move to get to white
        self._RColorIncrament = (255 - R)/self._size
        self._GColorIncrament = (255 - G)/self._size
        self._BColorIncrament = (255 - B)/self._size
    
    def step(self, amt = 1):
        amt = 1
        R,G,B = self._color
        if self._current == self._start:
            self._led.setRGB(self._current,R,G,B)
            
        if self._current < self._end:
            self._led.setRGB(self._current,R,G,B)
        
        if self._current == self._end:
            self._led.set(self._current, (255,255,255))
        else:
            self._led.all_off()
            
        self._current += amt
        R += self._RColorIncrament
        G += self._GColorIncrament
        B += self._BColorIncrament
    
    
driver = DriverSerial(num = 300, type = LEDTYPE.WS2812B)
led = LEDStrip(driver)

anim = Icicle(led,0,10)
anim.run()
#2
Hi markarr,

First thing first... your class init. It should be __init__, not _init_. That is: 2 underscores on each side, not one. This is just a python thing. It didn't complain because BaseStripAnim has it's own __init__ so as far as python was concerned it had an __init__ to call, but it never setup your code. So when I first ran it there was an error that self._color did not exist. This is why.

As for the rest of it, I'm not sure I follow your code. I understand what you are trying to achieve, I think... you setup 300 LEDs but have start and end limiting it to 10 pixels total. Maybe there was a misunderstanding in how that's supposed to work. The start and end parameters are intended to tell an animation where it can draw pixels. Normally start is automatically set to 0 and end is set to the last index, so these parameters are there to override those defaults. But I'm going to guess that your intent was to have 30, 10 pixel long icicles on your 300 pixel strip?? In that case, ditch start and end, replacing it with a single parameter called "length" or something and then do multiple icicles of that length.
#3
I was trying to get the animation working and then use it in another program that works out all the math for which pixels to light up when. The final icicle string will have 5 across, 5 down, 5 across 10 down and repeat that sequence across the strip. So the last 4 lines will be removed and run elsewhere.
#4
Why not just do the math in BiblioPixel? Not sure what you are going for there...
I get the icicle layout though... should be easy to do. You just want it to start with a random color and then go to white as it falls?


Forum Jump:


Users browsing this thread: 2 Guest(s)