Refactor rainbow pattern to travel along the length of LED strip
- Modified rainbow() to distribute colors along the physical length - Each LED gets a different hue based on its position - n1 parameter controls how many times the rainbow cycles (nodes) - Split rainbow tests into test/rainbow/ directory with 9 numbered test files - Each test runs forever until interrupted - Added main.py to run all tests in sequence repeatedly
This commit is contained in:
@@ -209,13 +209,14 @@ class Patterns(PatternBase): # Inherit from PatternBase
|
||||
# Clear all LEDs
|
||||
self.n.fill((0, 0, 0))
|
||||
|
||||
# Create rainbow effect with n1 nodes
|
||||
# Rainbow travels along the length - distribute colors along the strip
|
||||
for i in range(self.num_leds):
|
||||
# Calculate hue based on LED position, number of nodes, and time
|
||||
hue_per_node = 360 // num_nodes
|
||||
node_index = i * num_nodes // self.num_leds
|
||||
base_hue = node_index * hue_per_node
|
||||
hue = (base_hue + self.step) % 360
|
||||
# Calculate hue based on LED position along the strip
|
||||
# Distribute full 360 degrees across the strip, repeat num_nodes times
|
||||
# Position along the strip (0.0 to 1.0)
|
||||
position = i / self.num_leds
|
||||
# Hue cycles based on position and number of nodes
|
||||
hue = int((position * 360 * num_nodes + self.step) % 360)
|
||||
|
||||
# Convert HSV to RGB
|
||||
rgb = self.hsv_to_rgb(hue, 255, self.brightness)
|
||||
|
||||
Reference in New Issue
Block a user