Sunday, May 31, 2009
Recursion4
int sides = 7;
int maxDepth = 3;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(600, 600);
noStroke();
fill(0,0,0,3);
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)
{
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);
}
popMatrix();
rotate(angle);
}
}
int maxDepth = 3;
float angle = radians(360/sides);
float angle2 = angle/2;
float sz = 48;
void setup()
{
size(600, 600);
noStroke();
fill(0,0,0,3);
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)
{
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);
}
popMatrix();
rotate(angle);
}
}
info
submitted by:
PsychicTeethviews: 2007
Shapes drawn next to each other in a recursive function.

comments

Add a comment: