Sunday, May 31, 2009
Recursion5
int sides = 7;
int maxDepth = 4;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
background(255);
size(600, 600);
noStroke();
fill(0,0,0,1);
int x = width/2;
int y = height/2;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0,1, 0.9, 0.9, 0.9);
endShape();
}
void drawShape(int depth, int dir, float r, float g, float b)
{
fill(r*255,g*255,b*255,3);
for(int i = 0; i < sides ; i++)
{
vertex(0,0);
vertex(sin(-angle2)*sz,cos(-angle2)*sz);
vertex(sin(angle2)*sz,cos(angle2)*sz);
pushMatrix();
if (depth < maxDepth)
{
float sc = 1.0;
float d = sz * sc * sin(angle2);
translate(0,(sz + d) * dir);
scale(sc, sc);
rotate(PI);
//drawShape(depth + 1, dir * -1, r - 0.05, g - 0.1 + 0.05*dir, b - 0.02);
drawShape(depth + 1, dir * -1, r + random(0.3)*dir, g + random(0.3)*dir, b + random(0.3)*dir);
}
popMatrix();
rotate(angle);
}
}
int maxDepth = 4;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
background(255);
size(600, 600);
noStroke();
fill(0,0,0,1);
int x = width/2;
int y = height/2;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0,1, 0.9, 0.9, 0.9);
endShape();
}
void drawShape(int depth, int dir, float r, float g, float b)
{
fill(r*255,g*255,b*255,3);
for(int i = 0; i < sides ; i++)
{
vertex(0,0);
vertex(sin(-angle2)*sz,cos(-angle2)*sz);
vertex(sin(angle2)*sz,cos(angle2)*sz);
pushMatrix();
if (depth < maxDepth)
{
float sc = 1.0;
float d = sz * sc * sin(angle2);
translate(0,(sz + d) * dir);
scale(sc, sc);
rotate(PI);
//drawShape(depth + 1, dir * -1, r - 0.05, g - 0.1 + 0.05*dir, b - 0.02);
drawShape(depth + 1, dir * -1, r + random(0.3)*dir, g + random(0.3)*dir, b + random(0.3)*dir);
}
popMatrix();
rotate(angle);
}
}
info
submitted by: PsychicTeethviews: 820
Shapes drawn next to each other in a recursive function. Takes a while to render. Should look slightly different each time.
This sketch has a parent
comments
loading...
Add a comment: