def fire_sources(intensity_generator=constant(1)): slow = squared( clamped( triangular(gaussian(40 / TIME_FACTOR, 10 / TIME_FACTOR), gaussian(30 / TIME_FACTOR, 10 / TIME_FACTOR), gaussian(0.7, 0.1)), 0, 1)) fast = squared( clamped( triangular(gaussian(7 / TIME_FACTOR, 2 / TIME_FACTOR), gaussian(6 / TIME_FACTOR, 2 / TIME_FACTOR), gaussian(0.7, 0.1), gaussian(8 / TIME_FACTOR, 3 / TIME_FACTOR)), 0, 1)) ( intensity_r_f, intensity_g_f, ) = tee(intensity_generator, 2) (slow_r, slow_g) = tee(slow, 2) (fast_r, fast_g) = tee(fast, 2) slow_r = scale_and_clamp(slow_r, constant(1), 0.2, 1) slow_g = scale_and_clamp(slow_g, constant(1), 0, 0.1) fast_r = scale_and_clamp(fast_r, intensity_r_f, 0.5, 1.5) fast_g = scale_and_clamp(fast_g, intensity_g_f, -0.2, 0.6) source_r = maxed(slow_r, fast_r) source_g = maxed(slow_g, fast_g) return dense(source_r, TIME_FACTOR), dense(source_g, TIME_FACTOR), constant(0)
def __init__(self, device_id, pix_from, num_pixels, name, neopixel_strip): Component.__init__(self, device_id, name) LightSourceMixin.__init__(self) self._setting = 'rgb' self._sources = [(constant(0), constant(0), constant(0)) for _ in range(num_pixels)] self._setting_params.update({ "r": 0.5, "g": 0.5, "b": 0.5, "brightness": 0.5, "speed": 0.5, "intensity": 0.5, }) self._device = _NeopixelDevice(neopixel_strip, pix_from, num_pixels, self._param_generator("brightness")) self._num_pixels = num_pixels
def rainbow_sources(speed_generator=constant(1), offset=0): s1, s2, s3 = tee(speed_generator, 3) return ( rainbow_source_color("r", s1, offset), rainbow_source_color("g", s2, offset), rainbow_source_color("b", s3, offset) )
def __init__(self, device_id, pin, name): Component.__init__(self, device_id, name) SourceConsumerMixin.__init__(self) LightSourceMixin.__init__(self) self._setting = 'const' self._setting_params.update({"brightness": 0.5}) self._device = PWMLED(pin) self._source = constant(0)
def _wrap_sources_in_turn_off_effect(self, sources): effect = self._setting_params['turn_off_effect'] if effect == 'fade_out': return [ fade_out(source, int(200 * self._setting_params['fade_out_duration'])) for source in sources ] else: return [constant(0) for _ in sources]
def rainbow_source_color(color, speed_generator=constant(1), offset=0): pos = offset while True: r, g, b = color_wheel(pos) if color == "r": yield r elif color == "g": yield g elif color == "b": yield b pos = (pos + BASE_SPEED * next(speed_generator)) % 255
def _turn_off(self, effect=True): if effect: self.source = self._wrap_source_in_turn_off_effect( self._wrap_source_in_additional_effect(self._source)) else: self.source = constant(0)
def fire_source(intensity_generator=constant(1)): (r, g, b) = fire_sources(intensity_generator) return zip(r, g, b)
def _turn_off(self, effect=True): if effect: self._device.set_sources([self._wrap_source_in_turn_off_effect(self._wrap_source_in_additional_effect(s)) for s in self._sources]) else: self._device.set_sources([(constant(0), constant(0), constant(0)) for _ in range(self._num_pixels)])
def rainbow_source(speed_generator=constant(1), offset=0): pos = offset while True: yield(color_wheel(pos)) pos = (pos + BASE_SPEED * next(speed_generator)) % 255