Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Created February 2, 2013 18:12
Show Gist options
  • Save hilukasz/4698649 to your computer and use it in GitHub Desktop.
Save hilukasz/4698649 to your computer and use it in GitHub Desktop.
int time = 1000;
int[] fromRGB = { 100, 0, 255 };
int[] toRGB = { 50, 0, 0 };
void setup() {
makeTransition(fromRGB, toRGB, 1000);
}
boolean singleStep(int[] fromRGB,int[] toRGB) {
boolean keepGoing = true;
for(int i = 0; i < 3; ++i){
keepGoing |= (fromRGB[i] != toRGB[i]);
fromRGB[i] += ((fromRGB[i] > toRGB[i]) ? -1 : 1);
println(fromRGB[i]);
}
return keepGoing;
}
void makeTransition(int[] fromRGB,int[] toRGB,int time){
while(singleStep(fromRGB, toRGB)){
delay(time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment