We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9646d3f commit edac675Copy full SHA for edac675
shared-module/rainbowio/__init__.c
@@ -27,16 +27,20 @@
27
#include "shared-bindings/rainbowio/__init__.h"
28
29
int32_t colorwheel(mp_float_t pos) {
30
- if (pos > 255) {
31
- pos = pos - ((uint32_t)(pos / 256) * 256);
32
- }
+ pos = pos - ((uint32_t)(pos / 256) * 256);
+ int shift1, shift2;
33
if (pos < 85) {
34
- return (uint8_t)(255 - (pos * 3)) << 16 | (uint8_t)(pos * 3) << 8;
+ shift1 = 8;
+ shift2 = 16;
35
} else if (pos < 170) {
36
pos -= 85;
37
- return (uint8_t)(255 - (pos * 3)) << 8 | (uint8_t)(pos * 3);
+ shift1 = 0;
38
+ shift2 = 8;
39
} else {
40
pos -= 170;
- return (uint8_t)(pos * 3) << 16 | (uint8_t)(255 - (pos * 3));
41
+ shift1 = 16;
42
+ shift2 = 0;
43
}
44
+ int p = (int)(pos * 3);
45
+ return (p << shift1) | ((255 - p) << shift2);
46
0 commit comments