Adds min_intensity and max_intensity support back to Pulse animation. Introduces a 'breath' value (default 0) to give a duration to hold the minimum and maximum intensity during the animation for smoother changes in direction.
This commit is contained in:
parent
0f24be5dad
commit
fc1aefafca
3 changed files with 17 additions and 3 deletions
|
|
@ -37,12 +37,18 @@ class Pulse(Animation):
|
||||||
:param float speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
:param float speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
||||||
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
|
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
|
||||||
:param period: Period to pulse the LEDs over. Default 5.
|
:param period: Period to pulse the LEDs over. Default 5.
|
||||||
|
:param breath: Duration to hold minimum and maximum intensity levels. Default 0.
|
||||||
|
:param min_intensity: Lowest brightness level of the pulse. Default 0.
|
||||||
|
:param max_intensity: Highest brightness elvel of the pulse. Default 1.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, pixel_object, speed, color, period=5, name=None):
|
def __init__(self, pixel_object, speed, color, period=5, breath=0, min_intensity=0, max_intensity=1, name=None):
|
||||||
super().__init__(pixel_object, speed, color, name=name)
|
super().__init__(pixel_object, speed, color, name=name)
|
||||||
self._period = period
|
self._period = period
|
||||||
|
self._breath = breath
|
||||||
|
self._min_intensity = min_intensity
|
||||||
|
self._max_intensity = max_intensity
|
||||||
self._generator = None
|
self._generator = None
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class SparklePulse(Sparkle):
|
||||||
:param int speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
:param int speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
||||||
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
|
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
|
||||||
:param period: Period to pulse the LEDs over. Default 5.
|
:param period: Period to pulse the LEDs over. Default 5.
|
||||||
|
:param breath: Duration to hold minimum and maximum intensity. Default 0.
|
||||||
:param max_intensity: The maximum intensity to pulse, between 0 and 1.0. Default 1.
|
:param max_intensity: The maximum intensity to pulse, between 0 and 1.0. Default 1.
|
||||||
:param min_intensity: The minimum intensity to pulse, between 0 and 1.0. Default 0.
|
:param min_intensity: The minimum intensity to pulse, between 0 and 1.0. Default 0.
|
||||||
"""
|
"""
|
||||||
|
|
@ -49,6 +50,7 @@ class SparklePulse(Sparkle):
|
||||||
speed,
|
speed,
|
||||||
color,
|
color,
|
||||||
period=5,
|
period=5,
|
||||||
|
breath=0,
|
||||||
max_intensity=1,
|
max_intensity=1,
|
||||||
min_intensity=0,
|
min_intensity=0,
|
||||||
name=None,
|
name=None,
|
||||||
|
|
@ -56,6 +58,7 @@ class SparklePulse(Sparkle):
|
||||||
self._max_intensity = max_intensity
|
self._max_intensity = max_intensity
|
||||||
self._min_intensity = min_intensity
|
self._min_intensity = min_intensity
|
||||||
self._period = period
|
self._period = period
|
||||||
|
self._breath = breath
|
||||||
dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float)
|
dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
pixel_object, speed=speed, color=color, num_sparkles=1, name=name
|
pixel_object, speed=speed, color=color, num_sparkles=1, name=name
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,8 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False):
|
||||||
:param animation_object: An animation object to interact with.
|
:param animation_object: An animation object to interact with.
|
||||||
:param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control.
|
:param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control.
|
||||||
"""
|
"""
|
||||||
period = int(period * MS_PER_SECOND)
|
period = int((period + (animation_object._breath * 2)) * MS_PER_SECOND)
|
||||||
|
breath = int(animation_object._breath * MS_PER_SECOND)
|
||||||
half_period = period // 2
|
half_period = period // 2
|
||||||
|
|
||||||
last_update = monotonic_ms()
|
last_update = monotonic_ms()
|
||||||
|
|
@ -338,7 +339,11 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False):
|
||||||
last_pos = pos
|
last_pos = pos
|
||||||
if pos > half_period:
|
if pos > half_period:
|
||||||
pos = period - pos
|
pos = period - pos
|
||||||
intensity = pos / half_period
|
intensity = animation_object._min_intensity + ((pos / (half_period - breath)) * (animation_object._max_intensity - animation_object._min_intensity))
|
||||||
|
if pos < half_period and pos > (half_period - breath):
|
||||||
|
intensity = animation_object._max_intensity
|
||||||
|
if pos > (period - breath):
|
||||||
|
intensity = animation_object._min_intensity
|
||||||
if dotstar_pwm:
|
if dotstar_pwm:
|
||||||
fill_color = (
|
fill_color = (
|
||||||
animation_object.color[0],
|
animation_object.color[0],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue