May 13, 2009

Processing: Spiral growth generative art

A coworker got me excited to play around with Processing again, and I wrote a couple new generative art scripts. Here's a fun one:

float x;
float y;
float curRotation;
float rotationVelocity;
float curRadius;
float radiusVelocity;
float radiusThreshold;
float curSize;
float sizeVelocity;
float curRed;
float redVelocity;
float curGreen;
float greenVelocity;
float curBlue;
float blueVelocity;

void setup(){
size(1000,1000);
smooth();
background(45,0,0);
frameRate(100);
reset();
}

void draw(){

x = (width / 2) + sin(curRotation) * curRadius;
y = (height / 2) + cos(curRotation) * curRadius;

noStroke();
//stroke(100,100,100,150);
fill(curRed,curGreen,curBlue);
ellipse(x,y,curSize,curSize);

curRadius += radiusVelocity;
curRotation += rotationVelocity;
curSize -= sizeVelocity;
if( curRed > 45 ) curRed -= redVelocity;
curGreen -= greenVelocity;
curBlue -= blueVelocity;

if( curSize <= 0 ) //curRadius > radiusThreshold ||
{
reset();
}

}

void reset(){
curRadius = 0;
curRotation = random(0,3.14*2);
curSize = 20;
sizeVelocity = random(.05, .2);
rotationVelocity = random(.001, .009);
radiusVelocity = random( .1, 2 );
radiusThreshold = random( width / 3, width / 4 );
// make a shade of red
curRed = random(100, 255);
redVelocity = random( .1, 1 );
curGreen = random(0, 50);
greenVelocity = .5 * redVelocity;
curBlue = curGreen;
blueVelocity = greenVelocity;
}

It ends up looking something like this:

No comments:

Post a Comment