Showing posts with label randomness. Show all posts
Showing posts with label randomness. Show all posts
Tuesday, May 18, 2010
Cloudy blue Perlin sky
Click on the image to load the canvas demo (requires FireFox or non-IE browser) Perlin Noise is a technique for generating procedural textures, commonly used for smoke, clouds or to add a random looking realistic roughness to surfaces. The algorithm is basically to generate noise, then scale that noise randomly across an image at different sizes and levels of transparency. This creates a self similarity which mimics the appearance of some natural processes. I found a canvas implementation by iron_wallaby and made the noise be the transparency of pure white, giving a cloud like effect. This was originally going to be just the background for another canvas demo I was working on, but that is delayed as I'm currently doing bioinformatics study/working on a project in my spare time. Things to improve on this are restricting how cloudy it is to a range, and removing some visual artifacts (lines/blockiness)
Tuesday, April 13, 2010
Russian Dolls - Random combinations
Click on the image on the left to load the canvas demo (requires FireFox or non-IE browser)
This demo shows how a huge amount of content can be generated by randomly combining variations. This technique is useful as for example a crowd of identical people looks unnatural, but you don't necessarily care what the individuals look like, so long as they match a general theme.
The numbers get large very quickly - for instance 3 variations of hair color, and 2 of eye color gives 3 * 2 = 6 possible combinations (assuming independent assortment). Adding another trait multiplies this again, and soon the number of possible variations becomes enormous.
The code internals do not resemble genetics, but there is a similar idea in nature, with alleles. In the future I may use the dolls and their many variations as phenotypes for some experiments in this area.
The reason I chose to use Russian dolls (aside from just liking their recursive nature) is because my daughter Caitlin has lots of them on various clothes, bags, sheets etc, so this is for her.
It works fine in FireFox but there is something strange going on with parts of the faces not being drawn in some versions of Chrome.
Thursday, January 14, 2010
City Skyline and random seeds
Click the image on the left to view the canvas demo. (you need a browser other than Internet Explorer)
This generates a random city skyline, which fades from sunset to night time.
A way to achieve the effect would have been to generate the buildings, store them and alter their state as we go, but I did it a different way to demonstrate a property of generating scenes with pseudo random numbers.
Computers are deterministic so the random numbers are not really random. There are algorithms which can produce a random looking number from another number, and so by using one number to create the next, you can create a random looking sequence. The first number you start with is called a (random) seed.
A generator will usually set a seed if you don't specify it, using something kind of random it can get, eg the current time, the id of the process or the temperature of the CPU. Not setting the seed is thus the normal thing to do, as each run of the program will probably be different and things will appear more random.
However, by setting the seed you can generate a repeated sequence of numbers. This means that if you have some data that is created by a sequence of random numbers, by setting the seed to the same value, you can re-create it again. This is an incredible CPU/memory trade off, where you can generate infinite complexity with CPU time for a single integer value in the seed! A game in the 1980s called Elite used this technique to generate a huge game world on the tiny computers of the time.
The way the demo works is to reset the random seed each frame and then generate everything again using repeated calls to random. The windows have a random value of what time they'll turn on, and if it's past that time, they will be on.
This demonstrates how you can change some things in the the repeated calls, but critically the calls to random must be the same sequence, ie don't put calls to random in branches that depend on something that varies each call.
Sunday, December 13, 2009
Diffusion limited aggregation
Subscribe to:
Comments (Atom)