34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import time
|
|
class FadeHandler():
|
|
def __init__(self):
|
|
self.fades = []
|
|
|
|
|
|
class RGBFade():
|
|
def __init__(self, dmx, address, target, time):
|
|
self.address = address
|
|
self.target = target
|
|
self.before = dmx.get_rgb(address)
|
|
self.time = time
|
|
self.start = time.ticks_ms()
|
|
self.finished = False
|
|
|
|
def step(self, dmx):
|
|
if dmx.get_rgb(address) == target:
|
|
self.finished = True
|
|
return
|
|
fadeprogress = time.ticks_diff(time.ticks_ms(), self.start)/self.time
|
|
dmx.dmx_values[address] = self.target['r'] - self.before['r'] * fadeprogress
|
|
dmx.dmx_values[address+1] = self.target['g'] - self.before['g'] * fadeprogress
|
|
dmx.dmx_values[address+2] = self.target['b'] - self.before['b'] * fadeprogress
|
|
|
|
def addrgbfade(self, dmx, address, target, time):
|
|
self.fades.append(self.RGBFade(dmx, address, target, time))
|
|
|
|
def checkfades(self, dmx):
|
|
for fadei in self.fades:
|
|
if self.fades[fadei].finished:
|
|
self.fades = self.fades.pop(fadei)
|
|
continue
|
|
self.fades[fadei].step(dmx)
|
|
|