Add flicker
This commit is contained in:
parent
4178746858
commit
9fa954d8cf
|
@ -25,6 +25,7 @@ class Patterns:
|
||||||
"random_theater_chase": self.random_theater_chase_step,
|
"random_theater_chase": self.random_theater_chase_step,
|
||||||
"random_blink": self.random_blink_step,
|
"random_blink": self.random_blink_step,
|
||||||
"color_transition": self.color_transition_step,
|
"color_transition": self.color_transition_step,
|
||||||
|
"flicker": self.flicker_step, # Added the new flicker pattern
|
||||||
"external": None
|
"external": None
|
||||||
}
|
}
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
|
@ -150,8 +151,9 @@ class Patterns:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def apply_brightness(self, color):
|
def apply_brightness(self, color, brightness_override=None):
|
||||||
return tuple(int(c * self.brightness / 255) for c in color)
|
effective_brightness = brightness_override if brightness_override is not None else self.brightness
|
||||||
|
return tuple(int(c * effective_brightness / 255) for c in color)
|
||||||
|
|
||||||
def select(self, pattern):
|
def select(self, pattern):
|
||||||
if pattern in self.patterns:
|
if pattern in self.patterns:
|
||||||
|
@ -364,3 +366,16 @@ class Patterns:
|
||||||
self.hold_start_time = current_time
|
self.hold_start_time = current_time
|
||||||
|
|
||||||
self.last_update = current_time
|
self.last_update = current_time
|
||||||
|
|
||||||
|
def flicker_step(self):
|
||||||
|
current_time = utime.ticks_ms()
|
||||||
|
if utime.ticks_diff(current_time, self.last_update) >= self.delay/5:
|
||||||
|
base_color = self.colors[0]
|
||||||
|
# Increase the range for flicker_brightness_offset
|
||||||
|
# Changed from self.brightness // 4 to self.brightness // 2 (or even self.brightness for max intensity)
|
||||||
|
flicker_brightness_offset = random.randint(-int(self.brightness // 1.5), int(self.brightness // 1.5))
|
||||||
|
flicker_brightness = max(0, min(255, self.brightness + flicker_brightness_offset))
|
||||||
|
|
||||||
|
flicker_color = self.apply_brightness(base_color, brightness_override=flicker_brightness)
|
||||||
|
self.fill(flicker_color)
|
||||||
|
self.last_update = current_time
|
||||||
|
|
Loading…
Reference in New Issue