bugfixes and rainbowcomet adjustments
This commit is contained in:
parent
c9c7e1490a
commit
1a59bc869b
3 changed files with 54 additions and 37 deletions
|
|
@ -64,14 +64,14 @@ class Comet(Animation):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
pixel_object,
|
pixel_object,
|
||||||
speed,
|
speed,
|
||||||
color,
|
color,
|
||||||
tail_length=0,
|
tail_length=0,
|
||||||
reverse=False,
|
reverse=False,
|
||||||
bounce=False,
|
bounce=False,
|
||||||
name=None,
|
name=None,
|
||||||
):
|
):
|
||||||
if tail_length == 0:
|
if tail_length == 0:
|
||||||
tail_length = len(pixel_object) // 4
|
tail_length = len(pixel_object) // 4
|
||||||
|
|
@ -98,9 +98,10 @@ class Comet(Animation):
|
||||||
def _comet_recompute_color(self, color):
|
def _comet_recompute_color(self, color):
|
||||||
self._comet_colors = [BLACK]
|
self._comet_colors = [BLACK]
|
||||||
for n in range(self._tail_length):
|
for n in range(self._tail_length):
|
||||||
self._comet_colors.append(calculate_intensity(color, n * self._color_step + 0.05))
|
self._comet_colors.append(
|
||||||
|
calculate_intensity(color, n * self._color_step + 0.05)
|
||||||
|
)
|
||||||
self._computed_color = color
|
self._computed_color = color
|
||||||
print(self._comet_colors)
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
for pixel_no in range(self._tail_length + 1):
|
for pixel_no in range(self._tail_length + 1):
|
||||||
|
|
@ -113,8 +114,10 @@ class Comet(Animation):
|
||||||
|
|
||||||
if self._tail_start < self._left_side or self._tail_start > self._right_side:
|
if self._tail_start < self._left_side or self._tail_start > self._right_side:
|
||||||
self.reverse = not self.reverse
|
self.reverse = not self.reverse
|
||||||
self._direction = - self._direction
|
self._direction = -self._direction
|
||||||
self._tail_start += self._direction
|
self._tail_start += self._direction
|
||||||
|
if self.reverse == self._initial_reverse:
|
||||||
|
self.cycle_complete = True
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Implementation Notes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from adafruit_led_animation.animation.comet import Comet
|
from adafruit_led_animation.animation.comet import Comet
|
||||||
from adafruit_led_animation.color import colorwheel, BLACK
|
from adafruit_led_animation.color import colorwheel, BLACK, calculate_intensity
|
||||||
|
|
||||||
|
|
||||||
class RainbowComet(Comet):
|
class RainbowComet(Comet):
|
||||||
|
|
@ -60,6 +60,7 @@ class RainbowComet(Comet):
|
||||||
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
|
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
|
||||||
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
|
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
|
||||||
:param int colorwheel_offset: Offset from start of colorwheel (0-255).
|
:param int colorwheel_offset: Offset from start of colorwheel (0-255).
|
||||||
|
:param int step: Colorwheel step (defaults to automatic).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
|
|
@ -71,30 +72,27 @@ class RainbowComet(Comet):
|
||||||
reverse=False,
|
reverse=False,
|
||||||
bounce=False,
|
bounce=False,
|
||||||
colorwheel_offset=0,
|
colorwheel_offset=0,
|
||||||
|
step=0,
|
||||||
name=None,
|
name=None,
|
||||||
):
|
):
|
||||||
self._colorwheel_is_tuple = isinstance(colorwheel(0), tuple)
|
if step == 0:
|
||||||
|
self._colorwheel_step = int(256 / tail_length)
|
||||||
|
else:
|
||||||
|
self._colorwheel_step = step
|
||||||
self._colorwheel_offset = colorwheel_offset
|
self._colorwheel_offset = colorwheel_offset
|
||||||
|
|
||||||
super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name)
|
super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name)
|
||||||
|
|
||||||
def _calc_brightness(self, n, color):
|
|
||||||
brightness = (n * self._color_step) + self._color_offset
|
|
||||||
if not self._colorwheel_is_tuple:
|
|
||||||
color = (color & 0xFF, ((color & 0xFF00) >> 8), (color >> 16))
|
|
||||||
return [int(i * brightness) for i in color]
|
|
||||||
|
|
||||||
def _comet_recompute_color(self, color):
|
def _comet_recompute_color(self, color):
|
||||||
factor = int(256 / self._tail_length)
|
self._comet_colors = [BLACK]
|
||||||
self._comet_colors = [BLACK] + [
|
for n in range(self._tail_length):
|
||||||
self._calc_brightness(
|
invert = self._tail_length - n - 1
|
||||||
n,
|
self._comet_colors.append(
|
||||||
colorwheel(
|
calculate_intensity(
|
||||||
int((n * factor) + self._color_offset + self._colorwheel_offset)
|
colorwheel(
|
||||||
% 256
|
int((invert * self._colorwheel_step) + self._colorwheel_offset)
|
||||||
),
|
% 256
|
||||||
|
),
|
||||||
|
n * self._color_step + 0.05,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
for n in range(self._tail_length - 1)
|
|
||||||
]
|
|
||||||
self._reverse_comet_colors = list(reversed(self._comet_colors))
|
|
||||||
self._computed_color = color
|
self._computed_color = color
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,28 @@ def calculate_intensity(color, intensity=1.0):
|
||||||
:return: color
|
:return: color
|
||||||
"""
|
"""
|
||||||
if isinstance(color, int):
|
if isinstance(color, int):
|
||||||
return ((int((color & 0xff0000) * intensity) & 0xff0000) |
|
return (
|
||||||
(int((color & 0xff00) * intensity) & 0xff00) |
|
(int((color & 0xFF0000) * intensity) & 0xFF0000)
|
||||||
(int((color & 0xff) * intensity) & 0xff))
|
| (int((color & 0xFF00) * intensity) & 0xFF00)
|
||||||
|
| (int((color & 0xFF) * intensity) & 0xFF)
|
||||||
|
)
|
||||||
|
|
||||||
if len(color) == 3:
|
if len(color) == 3:
|
||||||
return int(color[0] * intensity), int(color[1] * intensity), int(color[2] * intensity)
|
return (
|
||||||
|
int(color[0] * intensity),
|
||||||
|
int(color[1] * intensity),
|
||||||
|
int(color[2] * intensity),
|
||||||
|
)
|
||||||
elif len(color) == 4 and isinstance(color[3], float):
|
elif len(color) == 4 and isinstance(color[3], float):
|
||||||
return int(color[0] * intensity), int(color[1] * intensity), int(color[2] * intensity), color[3]
|
return (
|
||||||
return int(color[0] * intensity), int(color[1] * intensity), int(color[2] * intensity), int(color[3] * intensity)
|
int(color[0] * intensity),
|
||||||
|
int(color[1] * intensity),
|
||||||
|
int(color[2] * intensity),
|
||||||
|
color[3],
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
int(color[0] * intensity),
|
||||||
|
int(color[1] * intensity),
|
||||||
|
int(color[2] * intensity),
|
||||||
|
int(color[3] * intensity),
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue