Skip to content

Commit 5f66f81

Browse files
committed
Finalize effects and refactoring
1 parent e791c0e commit 5f66f81

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

displayio_effects/colorwheel_effect.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,21 @@
3131

3232
COLORWHEEL_WIDGET_VALUES = {
3333
WidgetType.DIAL: {
34-
"path": ("_needle", "_palette"),
34+
"path": ["_needle", "pixel_shader"],
3535
"index": 0,
3636
},
3737
WidgetType.GAUGE: {
38-
"path": ("_palette"),
38+
"path": ["_palette"],
3939
"index": 2,
4040
},
4141
}
4242

4343
COLORWHEEL_COLORS = cycle([colorwheel(color_value) for color_value in range(256)])
4444

4545

46-
def update_colorwheel(self):
47-
"""Updates the widget value and propagates the fluctuation effect refresh"""
48-
49-
palette_map = getattr(self, WIDGET_TYPE_ATTR)
50-
palette_attr = self
51-
for attr_path in palette_map["path"]:
52-
palette_attr = getattr(palette_attr, attr_path)
53-
palette_attr[palette_map["index"]] = next(COLORWHEEL_COLORS)
46+
def get_widget_value(instance):
47+
widget_type = getattr(instance, WIDGET_TYPE_ATTR)
48+
return COLORWHEEL_WIDGET_VALUES[widget_type]
5449

5550

5651
def hook_colorwheel_effect(widget_class, widget_type):
@@ -81,3 +76,13 @@ def hook_colorwheel_effect(widget_class, widget_type):
8176
setattr(widget_class, WIDGET_TYPE_ATTR, widget_type)
8277

8378
setattr(widget_class, "update_colorwheel", update_colorwheel)
79+
80+
81+
def update_colorwheel(self):
82+
"""Updates the widget value and propagates the fluctuation effect refresh"""
83+
84+
palette_map = get_widget_value(self)
85+
palette_attr = self
86+
for attr_path in palette_map["path"]:
87+
palette_attr = getattr(palette_attr, attr_path)
88+
palette_attr[palette_map["index"]] = next(COLORWHEEL_COLORS)

displayio_effects/fluctuation_effect.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
WidgetType.GAUGE: "level",
3434
}
3535

36+
def get_value_name(instance):
37+
widget_type = getattr(instance, WIDGET_TYPE_ATTR)
38+
return FLUCTUATION_WIDGET_VALUES[widget_type]
39+
3640

3741
@property
3842
def fluctuation_amplitude(self):
@@ -44,7 +48,7 @@ def fluctuation_amplitude(self):
4448

4549
@fluctuation_amplitude.setter
4650
def fluctuation_amplitude(self, amplitude):
47-
value_name = getattr(self, WIDGET_TYPE_ATTR)
51+
value_name = get_value_name(self)
4852
if amplitude < 0:
4953
raise ValueError("Fluctuation effect setting must be larger than 0")
5054
if amplitude:
@@ -68,7 +72,8 @@ def fluctuation_move_rate(self, rate):
6872
def update_fluctuation(self):
6973
"""Updates the widget value and propagates the fluctuation effect refresh"""
7074

71-
value_name = getattr(self, WIDGET_TYPE_ATTR)
75+
value_name = get_value_name(self)
76+
7277
if self._fluctuation_amplitude == 0:
7378
self._fluctuation_destination = None
7479
return
@@ -130,6 +135,6 @@ def hook_fluctuation_effect(widget_class, widget_type):
130135
setattr(widget_class, "fluctuation_amplitude", fluctuation_amplitude)
131136
setattr(widget_class, "_fluctuation_amplitude", 0)
132137
setattr(widget_class, "fluctuation_move_rate", fluctuation_move_rate)
133-
setattr(widget_class, "_fluctuation_move_rate", 0.1)
138+
setattr(widget_class, "_fluctuation_move_rate", 0.01)
134139

135140
setattr(widget_class, "update_fluctuation", update_fluctuation)

0 commit comments

Comments
 (0)