float sweep = 0.0; int maxDepth = 0; float speed = 0.012; void setup() { size(500,333); smooth(); strokeWeight(2.0); noFill(); } void draw() { //background(0); fill(0,0,0,100); rect(0,0,500,333); noFill(); pythagorasBaum(0,230,300,0.0,65); sweep += speed; if (sweep > 1.0) { sweep = 0.0; speed *= 0.85; maxDepth++; if (maxDepth > 6) { maxDepth = 0; speed = 0.012; } } } void pythagorasBaum(int depth, float x0, float y0, float phi, float rad) { if (depth > maxDepth) return; // // x4y4 // / \ // / \ // x3y3-------x2y2 // | | // x0y0-------x1y1 float theta = PI * (1+sweep); float x1 = x0 + rad*cos(phi); float y1 = y0 + rad*sin(phi); float xOffset = rad*sin(phi); float yOffset = -rad*cos(phi); float x3 = x0+xOffset; float y3 = y0+yOffset; float x2 = x1+xOffset; float y2 = y1+yOffset; float xMid = (x3+x2)/2.0; float yMid = (y3+y2)/2.0; float x4 = xMid + rad/2.0 * cos(theta+phi); float y4 = yMid + rad/2.0 * sin(theta+phi); if (depth == maxDepth) { stroke(127,127,255); strokeWeight(1); ellipse(xMid,yMid,rad,rad); } strokeWeight(2); stroke(255,0,0); line(x0,y0,x1,y1); stroke(255); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x0,y0); line(x3,y3,x4,y4); line(x2,y2,x4,y4); float xv = x4-x3; float yv = y4-y3; float radNew = sqrt(xv*xv+yv*yv); float newPhi = atan2(yv,xv); pythagorasBaum(depth+1,x3,y3,newPhi,radNew); float xw = x2-x4; float yw = y2-y4; radNew = sqrt(xw*xw+yw*yw); newPhi = atan2(yw,xw); pythagorasBaum(depth+1,x4,y4,newPhi,radNew); strokeWeight(1); fill(0); ellipse(x0,y0,8,8); ellipse(x1,y1,8,8); ellipse(x2,y2,8,8); ellipse(x3,y3,8,8); ellipse(x4,y4,8,8); noFill(); }