10/11/07

Organic Art










Back at college I had a few heroes of computer graphics. One of them, Professor William Latham was creating fascinating organic art. The three images above are his work and are reproduced with permission. I strongly encourage you to see these images in higher resolution at Williams web site: www.williamlatham1.com

It recently occurred to me that such organic art may be possible in real time and in very few bytes using OpenGL. Whilst I can't hope to match the beauty of the images in very few bytes, I can get close in form.

Here are some images I'm working on. Each image is taken from a real-time program which animates the structure in a more or less organic way.












The structures above are mine. Aside fom the colours and lighting which needs work, I think the code is beginning to show promise. The "latham" routine to generate the shapes is less than 300 bytes after compression.

The code is a recursive, iterative and randomised. I think there is loads of potential here.


void latham (uint32 depth, uint32 n, uint32 seed) {
uint32 i;
float s;

#define OPENNESS 40.0f // lower is more open
#define SPACING 2.0f // distance between generated points...higher, more
#define TWISTINESS 10.0f // how weird the structure gets...lower, less

if (depth==0) return;
for (i=0; i < n; i++) {
mirand = seed;
s= my_sin(sfrand()*(seed+i)*0.04f);
glRotatef ( s*OPENNESS, s*sfrand(),s*sfrand(),s*sfrand() );
s= my_sin(s*TWISTINESS)*SPACING;
glTranslatef ( s*sfrand(), s*sfrand(), s*sfrand() );
if (i%(n/4)==0) {
glPushMatrix();
glScalef(0.5f,0.5f,0.5f);
latham (depth-1, n/2, seed+1);
glPopMatrix();
}
drawSphere(SPACING); // SPACING=radius of sphere
}
}



sfrand() is a function that returns a psuedo-random number between -1 and 1. Mirand is used to set the seed for random number generation. Dirty: but this is size coding. The code iterates applying a random (but repeatable by seed) rotation and translation and drawing a sphere. At a certain iteration, a new random seed is passed recursively into the function in order to draw "branches" off the main creature.

I have removed the animation code here (which is tiny) but you can figure that out yourself.

Overall, through fortuitous randomness we can come close to resembling Lathams structures and animate them in real time. Now if only I had some artistic ability I could light them and colour them better!

2 comments:

  1. Awesome article, mate.

    Williams art is fantastic indeed!

    ReplyDelete
  2. I agree Benny, the images are iconic in my opinion.

    ReplyDelete