Skip to content

Instantly share code, notes, and snippets.

@arkag
Created September 7, 2018 15:39
Show Gist options
  • Save arkag/3ed8c207102d7dbb4f8d27025e869754 to your computer and use it in GitHub Desktop.
Save arkag/3ed8c207102d7dbb4f8d27025e869754 to your computer and use it in GitHub Desktop.
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