Assign color to multiple cubes

I’ve been messing around with the Tokamak physics engine. I place many solid cubes in a stack 10 across and as high as needed for the num of cubes I select.

Now, I want the cubes to be different colors.
Easily done. But they were, well, not random enough.

So, I commented out the lines and made the colors random.

				k = ( (rand()*1.0)/RAND_MAX ) * 5;

				if(k == 1)
				if(k == 2)
				if(k == 3)
				if(k == 4)
				//if(k == 4)


Due to the framerate, the colors blink - change colors that is while playing.

Is there a way to assign a color to each cube randomly so that when the cubes are re-rendered, it remembers it’s color assignment?

Thanks all,



more like => :rolleyes:

:stuck_out_tongue: That’s not much help.

How about setting a random color when creating the display list?

Other than that, just store the color somewhere and use the same in the next frame :stuck_out_tongue:

Yep, I created an array and saved the color assignment there…

					k = ( (rand()*1.0)/RAND_MAX ) * 5;
											color_state[i] = k;
					k = color_state[i];

Then set bRandom to false after the loop.
Worked like a charm!



well, doesn’t look so charming to me. the if-condition is tested in each frame- although you know it is true only once, in the very first frame you draw.

a better way would be filling the array in your main function, before the main loop is started.