float heightoftriangle = cos(radians(30)); // universal constant BFont GillSans; int max_depth = 7; String message = "multiple recursion"; float Gilldivide = message.length()/3.2; int Width = 1024; void setup(){ size(1200,1200); GillSans = loadFont("GillSans.vlw.gz"); textFont(GillSans, 20); fill(0); } void draw(){ translate(50,50); background(255); serpinski(1); save("serpinski.tif"); } void eqtri(float b){ textLine(0,0,b,0); textLine(b,0,b/2,b*heightoftriangle); textLine(b/2,b*heightoftriangle,0,0); } void serpinski(int depth){ if (depth <= max_depth) { float newb = Width/pow(2,depth); eqtri(newb); serpinski(depth+1); push(); translate(newb,0); eqtri(newb); serpinski(depth+1); pop(); push(); translate(newb/2,newb*heightoftriangle); eqtri(newb); serpinski(depth+1); pop(); } } void textLine(float x1, float y1, float x2, float y2){ push(); float dx = x2 - x1; float dy = y2 - y1; float d = sqrt(sq(dx)+sq(dy)); textSize(d/Gilldivide); translate(x1,y1); float theta = atan2(dy,dx); rotate(theta); text(message,0,0); pop(); }