Created
September 7, 2018 15:39
-
-
Save arkag/3ed8c207102d7dbb4f8d27025e869754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Color mod_color(Color current_color, bool should_add, uint16_t change_amount) { | |
uint16_t addlim = 359 - change_amount; | |
uint16_t sublim = change_amount; | |
uint16_t leftovers; | |
if (should_add) { | |
if (current_color.h <= addlim) { | |
current_color.h += change_amount; | |
} else { | |
leftovers = (359 + change_amount) % 359; | |
current_color.h = 0 + leftovers; | |
} | |
} else { | |
if (current_color.h >= sublim) { | |
current_color.h -= change_amount; | |
} else { | |
leftovers = change_amount - current_color.h; | |
current_color.h = 359 - leftovers; | |
} | |
} | |
return current_color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment