Last active
December 27, 2015 03:19
-
-
Save TheEmpty/7258361 to your computer and use it in GitHub Desktop.
Color fading for Java UI
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
int[] rgb = {0,0,0}; | |
int i = 0; // current working index | |
int step = 25; | |
while(true) { | |
// so raise R, raise G, drop R, raise B, drop G, etc? | |
int p = (i + 2) % 3; // previous index | |
if(rgb[i] >= 255 && rgb[p] > 0) { | |
rgb[p] -= step; | |
if(rgb[p] < 0) rgb[p] = 0; | |
} else { | |
if(rgb[i] >= 255) { | |
i = (i+1) % 3; | |
} | |
rgb[i] = (rgb[i] + step); | |
if(rgb[i] >= 255) rgb[i] = 255; | |
} | |
java.awt.Color clr = new java.awt.Color(rgb[0],rgb[1],rgb[2]); | |
try { Thread.sleep( 250 ); } catch(Exception ex) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment