Sunday, May 31, 2009
Recursion
int sides = 5;
int maxDepth = 5;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(800, 800);
smooth();
noStroke();
fill(0,0,0,10);
int x = 400;
int y = 400;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0);
endShape();
}
void drawShape(int depth)
{
for(int i = 0; i < sides ; i++)
{
vertex(0,0);
vertex(sin(-angle2)*sz,cos(-angle2)*sz);
vertex(sin(angle2)*sz,cos(angle2)*sz);
//push();
if (depth < maxDepth)
{
translate(0,sz + sz);
drawShape(depth+1);
}
//pop();
rotate(angle);
}
}
int maxDepth = 5;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(800, 800);
smooth();
noStroke();
fill(0,0,0,10);
int x = 400;
int y = 400;
translate(x,y);
beginShape(TRIANGLES);
drawShape(0);
endShape();
}
void drawShape(int depth)
{
for(int i = 0; i < sides ; i++)
{
vertex(0,0);
vertex(sin(-angle2)*sz,cos(-angle2)*sz);
vertex(sin(angle2)*sz,cos(angle2)*sz);
//push();
if (depth < maxDepth)
{
translate(0,sz + sz);
drawShape(depth+1);
}
//pop();
rotate(angle);
}
}
comments
loading...
Add a comment: