diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2019-05-19 11:19:46 -0500 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-05-19 09:19:46 -0700 |
commit | 270b39b2eb44247cff75ddd216a8e67f8f264991 (patch) | |
tree | afa46c2588ddbeff3b7820cef323251226f0536d /lib/lib8tion | |
parent | a0d6c5a1136e2c56aa4a57eac08355c2b5d79ad5 (diff) | |
download | qmk_firmware-270b39b2eb44247cff75ddd216a8e67f8f264991.tar.gz qmk_firmware-270b39b2eb44247cff75ddd216a8e67f8f264991.zip |
Spirals, Pinwheels, and Documentation....Oh My! RGB Matrix Effects (#5877)
* Spirals, Pinwheels, and Documentation....Oh My!
* Spiral effect band thickness adjustments
* Fixing animation spin directions
Diffstat (limited to 'lib/lib8tion')
-rw-r--r-- | lib/lib8tion/trig8.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/lib8tion/trig8.h b/lib/lib8tion/trig8.h index 6ef3ce625..cfba6373f 100644 --- a/lib/lib8tion/trig8.h +++ b/lib/lib8tion/trig8.h | |||
@@ -255,5 +255,30 @@ LIB8STATIC uint8_t cos8( uint8_t theta) | |||
255 | return sin8( theta + 64); | 255 | return sin8( theta + 64); |
256 | } | 256 | } |
257 | 257 | ||
258 | /// Fast 16-bit approximation of atan2(x). | ||
259 | /// @returns atan2, value between 0 and 255 | ||
260 | LIB8STATIC uint8_t atan2_8(int16_t dy, int16_t dx) | ||
261 | { | ||
262 | if (dy == 0) | ||
263 | { | ||
264 | if (dx >= 0) | ||
265 | return 0; | ||
266 | else | ||
267 | return 128; | ||
268 | } | ||
269 | |||
270 | int16_t abs_y = dy > 0 ? dy : -dy; | ||
271 | int8_t a; | ||
272 | |||
273 | if (dx >= 0) | ||
274 | a = 32 - (32 * (dx - abs_y) / (dx + abs_y)); | ||
275 | else | ||
276 | a = 96 - (32 * (dx + abs_y) / (abs_y - dx)); | ||
277 | |||
278 | if (dy < 0) | ||
279 | return -a; // negate if in quad III or IV | ||
280 | return a; | ||
281 | } | ||
282 | |||
258 | ///@} | 283 | ///@} |
259 | #endif | 284 | #endif |