I have tried using 3 methods to create a blinking effect.
- The value shifting from @purpule +5f*(float)Math.sin(alpha) + .5f
- My suggestion using Math.abs(Math.sin(alpha));
- Alternate modulus method.
The Code used to test:
long startTime = System.currentTimeMillis();
System.out.println(startTime);
for(int i = 0; i < 10000000; i++){
float val = +5f*(float)Math.sin(i/1000) + 0.5f;
}
long endtime = System.currentTimeMillis();
System.out.println("Total time:"+(endtime - startTime));
startTime = System.currentTimeMillis();
System.out.println(startTime);
for(int i = 0; i < 10000000; i++){
float val = (float) Math.abs(Math.sin(i/1000));
}
endtime = System.currentTimeMillis();
System.out.println("Total time:"+(endtime - startTime));
startTime = System.currentTimeMillis();
System.out.println(startTime);
for(int i = 1; i < 10000001; i++){
float val = i%2;
float alpha = val>1?1-(val-1):val;
}
endtime = System.currentTimeMillis();
System.out.println("Total time:"+(endtime - startTime));
The outcome of the tests show that the first 2 methods take about 550-570ms and achive the same sinus wave alpha.
The 3rd method using module takes about 9-15ms which is a lot faster but is not a sine wave, instead it is a saw wave and still achieves the blinking affect.
I suggest you try these and see which one suits you needs the best.