Archive for Aldahar

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.

Comments (1)

Procedural textures

Generating an 8192 by 4096 pixel canvas on the fly takes a while, but I’m putting up with it over and over again to see if I can come up with a good algorithm to make a forest-grass field. The old algorithm created a field that was almost perfect and meshed almost invisibly with our current tiles, but Justin said that it didn’t have enough brown flecks to represent leaves, so I’ve been trying something new. This is my first try, but I can’t remember the color values that I used for the life of me.

Comments