Sunday, May 31, 2009
Recursion3
int sides = 5;
int maxDepth = 3;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(600, 600);
smooth();
noStroke();
fill(0,0,0,10);
int x = width/2;
int y = height/2;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0,1);
endShape();
}
void drawShape(int depth, int dir)
{
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)
{
translate(0,(sz + sz)*dir);
//scale(0.93);
rotate(PI);
drawShape(depth+1, dir*-1);
}
popMatrix();
rotate(angle);
}
}
int maxDepth = 3;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(600, 600);
smooth();
noStroke();
fill(0,0,0,10);
int x = width/2;
int y = height/2;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0,1);
endShape();
}
void drawShape(int depth, int dir)
{
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)
{
translate(0,(sz + sz)*dir);
//scale(0.93);
rotate(PI);
drawShape(depth+1, dir*-1);
}
popMatrix();
rotate(angle);
}
}
comments
loading...
Add a comment: