Precalculated tables??
in
Programming Questions
•
2 years ago
Hi there
I have some code I would like to optimize using precalculated value table to avoid redundant operations.
Here is the code, it's pupose is to set a moving particle's color based on its speed :
- float vRatio = vel.mag()/MAX_VEL;
- float cLevel = TWO_PI*vRatio;
- if (heatVision)
- {
- //float rPhase = TWO_PI/4;
- //float gPhase = 3*TWO_PI/4;
- float bPhase = PI/2;
- int R = int(255 / (1 + pow(2.718, 10 * (0.4 - vRatio)))); //int(128*sin(cLevel*0.5-rPhase)+127);
- int G = int(220 / (1 + pow(6, 12 * (0.8 - vRatio)))); //R-int(128*sin(cLevel*0.25-gPhase)+255);
- int B = int(128*sin(cLevel*1.35-bPhase)+127);
- pig = color(R, G, B);
- }
I'm guessing I need to compile this table at start time and save it in an extarnal file but I'm at a loss on how to accomplish this.
Your help is greatly appreciated!!! I will post the full source once it is complete.
Thanks,
nico
1