Commit ae9412e
authored
Quantise colour before writing (#1247)
closes
RaspberryPiFoundation/digital-editor-issues#871
Code used to test -
```
from sense_hat import SenseHat
from time import sleep
sense = SenseHat()
# --- Quantisation helper to match set_pixel ---
def quantise_rgb(r, g, b):
r = (r >> 3) << 3
g = (g >> 2) << 2
b = (b >> 3) << 3
return (r, g, b)
# --- Colours ---
colours = [
(255, 255, 255), # White
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(245, 245, 245), # WhiteSmoke
(220, 220, 220), # Gainsboro
(192, 192, 192), # Silver
(105, 105, 105), # DimGray
(169, 169, 169), # DarkGray
(0, 0, 0), # Black
(100, 149, 237), # CornflowerBlue
(70, 130, 180), # SteelBlue
(0, 0, 205), # MediumBlue
(25, 25, 112), # MidnightBlue
(0, 0, 139), # DarkBlue
(0, 191, 255), # DeepSkyBlue
(30, 144, 255), # DodgerBlue
(135, 206, 250), # LightSkyBlue
(0, 255, 255), # Cyan
(64, 224, 208), # Turquoise
(0, 128, 128), # Teal
(143, 188, 143), # DarkSeaGreen
(60, 179, 113), # MediumSeaGreen
(46, 139, 87), # SeaGreen
(0, 255, 127), # SpringGreen
(34, 139, 34), # ForestGreen
(50, 205, 50), # LimeGreen
(154, 205, 50), # YellowGreen
(128, 128, 0), # Olive
(85, 107, 47), # DarkOliveGreen
(240, 230, 140), # Khaki
(255, 255, 0), # Yellow
(255, 215, 0), # Gold
(184, 134, 11), # DarkGoldenrod
(139, 69, 19), # SaddleBrown
(210, 105, 30), # Chocolate
(255, 140, 0), # DarkOrange
(255, 69, 0), # OrangeRed
(178, 34, 34), # Firebrick
(255, 0, 0), # Red
(220, 20, 60), # Crimson
(255, 192, 203), # Pink
(255, 105, 180), # HotPink
(255, 20, 147), # DeepPink
(199, 21, 133), # MediumVioletRed
(153, 50, 204), # DarkOrchid
(148, 0, 211), # DarkViolet
(138, 43, 226), # BlueViolet
(75, 0, 130), # Indigo
]
passed_count = 0
failed_count = 0
for c in colours:
r, g, b = c
sense.clear()
sense.set_pixel(3, 3, r, g, b)
actual = tuple(sense.get_pixel(3, 3))
expected = quantise_rgb(r, g, b) # match set_pixel quantization
if actual == expected:
print(f"✅ PASS: Requested {c} -> Quantised {expected} -> Actual {actual}")
passed_count += 1
else:
print(f"❌ FAIL: Requested {c} -> Quantised {expected} -> Actual {actual}")
failed_count += 1
sleep(0.3)
sense.clear()
print(f"\n🎉 Tests complete! Passed: {passed_count}, Failed: {failed_count}")
```1 parent ea1a608 commit ae9412e
2 files changed
+11
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
1098 | 1105 | | |
1099 | 1106 | | |
1100 | 1107 | | |
| |||
0 commit comments