Files

24 lines
689 B
C
Raw Permalink Normal View History

void random_player_color(Player& p)
{
float h = (float)random(0, 100000) / 100000.0;
float s = 0.95f; // high saturation
float v = 1.0f; // max brightness
float c = v * s;
float x = c * (1 - fabsf(fmodf(h * 6.0f, 2) - 1));
float m = v - c;
float r1=0, g1=0, b1=0;
if (h < 1.0/6) { r1=c; g1=x; }
else if (h < 2.0/6) { r1=x; g1=c; }
else if (h < 3.0/6) { g1=c; b1=x; }
else if (h < 4.0/6) { g1=x; b1=c; }
else if (h < 5.0/6) { r1=x; b1=c; }
else { r1=c; b1=x; }
p.setColor( (unsigned char)((r1 + m) * 255),
(unsigned char)((g1 + m) * 255),
(unsigned char)((b1 + m) * 255));
}