Reputation: 36
How gradually change the color of the some shape with the time on Android using openGl? For example, I want dynamically change the color of the triangle.
Upvotes: 1
Views: 417
Reputation: 207
I think, you mean something like this:
Measure time and get only remainder of the division on concrete module, in my example, I use module = 10000 = 10 seconds, so each 10 seconds the set of colors will be repeated
int module = 10000;
long time = SystemClock.uptimeMillis() % module;
And, then you can use this value, as you want - I create the next scenario, but you can modify it for obtaining the best result:
int shift = module/5;
Color c = new Color();
int red = (int)((float)time/module)*256,
green =(int)(((float)time+shift)/module)*256,
blue = (int)(((float)time+2*shift)/module)*256;
c.rgb(red, green, blue);
if you would find better way, please inform me!
Upvotes: 1