//---------------------------------------
ArrayList veinpopulation;
ArrayList leafpopulation;
void setup(){
size(1200, 700);
//background(241);
smooth();
int w = 60;
veinpopulation = new ArrayList();
for( int i=0; i<11; i++ ){
veinpopulation.add( new vein( int(random(w, width-w)), int(random(7, 51)) ));
}
}
void draw(){
background(241);
noLoop();
for( int i=0; i<veinpopulation.size(); i++ ){
vein v = (vein) veinpopulation.get(i);
v.render();
for( int j=0; j<leafpopulation.size(); j++ ){
leaf f = (leaf) leafpopulation.get(j);
f.render();
}
}
}
//---------------------------------------
//---------------------------------------
class vein{
//variables
int x, leafNum;
int strokeColor = color( int(random(150,221)), int(random(71,180)), 0, int(random(69,255)) );
//constructor
vein( int _x, int _leafNum ){
x = _x;
leafNum = _leafNum;
}
void render(){
strokeWeight(1);
stroke( strokeColor );
line( x, 0, x, height );
int gap = height /leafNum;
int r = int(random(gap));
int direction = 1;
leafpopulation = new ArrayList();
for( int i=0; i<leafNum; i++ ){
int fillColor = color( int(random(150,221)), int(random(71,180)), 0, int(random(69,255)) );
leafpopulation.add( new leaf( x, gap*i +r, int(random(7, 41)), direction, fillColor ));
direction = -direction;
}
}
}
//---------------------------------------
//---------------------------------------
class leaf{
//variables
int x, y, leafSize, leafDir, leafSpeed, leafColor;
//constructor
leaf( int _x, int _y, int _leafSize, int _leafDir, int _leafColor ){
x = _x;
y = _y;
leafSize = _leafSize;
leafDir = _leafDir;
leafColor = _leafColor;
}
void render(){
noStroke();
fill( leafColor );
pushMatrix();
translate(x, y); //move to position
scale( leafSize ); //scale to size
beginShape(); //draw the shape
vertex( leafDir, -0.6875 );
bezierVertex( leafDir, -0.6875, leafDir*0.4375, -1.03125, 0, 0 );
bezierVertex( 0, 0, leafDir, 0.375, leafDir, -0.6875 );
endShape();
popMatrix();
}
}
//---------------------------------------
Sunday, August 23, 2009
Processing with Class
Processing with Function
//---------------------------------------
void setup(){
size(1200, 700);
smooth();
background(241);
noLoop();
}
void draw(){
for( int i=0; i<9; i++){
int s = int(random(7, 51));
int w = 2*s;
int n = int(random(9, 51));
drawVine( int(random(w, width-w)), n, s );
}
}
//---------------------------------------
//---------------------------------------
void drawVine( int x, int numLeaves, int leafSize ){
strokeWeight(1);
stroke( 0, int(random(0, 71)), int(random(71, 180)));
line( x, 0, x, height );
strokeWeight( 1/leafSize );
int gap = height /numLeaves;
int direction = 1;
for( int i=0; i<numLeaves; i++ ){
int colorR = 0;
int colorG = int(random(0, 71));
int colorB = int(random(71, 180));
noStroke();
fill( colorR, colorG, colorB, random(99, 255) ); //random color for fill
int r = int(random(gap));
drawLeaf( x, gap*i +r, leafSize, direction );
direction = -direction;
}
}
//---------------------------------------
//---------------------------------------
void drawLeaf( int x, int y, int size, int dir ){
pushMatrix();
translate(x, y); //move to position
scale(size); //scale to size
beginShape(); //draw the shape
vertex( dir, -0.6875 );
bezierVertex( dir, -0.6875, dir*0.4375, -1.03125, 0, 0 );
bezierVertex( 0, 0, dir, 0.375, dir, -0.6875 );
endShape();
popMatrix();
}
//---------------------------------------
Subscribe to:
Posts (Atom)