Procedural textures; take two
So, Rick and I came up with a new pseudo-random number distribution:
double random_pow(int power)
{
double num = 2.0 * rand() / RAND_MAX - 1;
return (copysign(pow(num, power), num) + 1) / 2;
}
I’m using the standard C library versions of rand() and RAND_MAX, so this function generates a random number in [0, 1] biased towards 0.5 using the exponent power. I thought it might be useful in making most of my field green but having a few brown or yellow flecks at the end points, but I’m not sure it worked out correctly. Grass 1 and Grass 2 are my tries using this system. The code for the first one is:
Color lawn_grass(int x, int y)
{
static color darkGreen(23, 90, 0);
static color lightGreen(51, 175, 15);
static color brown(87, 67, 6);
color green = clint(darkGreen, lightGreen, rand_double());
return clint(green, brown, rand_double()).convert();
}
For the second one, it’s:
Color lawn_grass(int x, int y)
{
static color darkGreen(27, 81, 0);
staric color lightGreen(75, 150, 25);
static color brown(90, 97, 16);
color green = clint(darkGreen, lightGreen, rand_double());
return clint(green, brown, rand_double()).convert();
}
Crap. It occurs to me that neither of my grass functions use my random_pow() function. I’ll have to look around to see if I saved the originals.