xxxxxxxxxx
void setup(){
size(500,500);
background(255);
}
void draw(){
background(255);
tri(new PVector(50, 375), new PVector(450, 375), new PVector(250,25));
}
void bla(PVector s,PVector e,int deep){
float d = dist(s.x, s.y, e.x, e.y);
if(d < 5){
line(s.x,s.y,e.x,e.y);
return;
}
PVector mid1 = PVector.lerp(s, e, 1.0/3);
PVector mid2 = PVector.lerp(s, e, 2.0/3);
PVector midonLine = PVector.lerp(s, e, 0.5);
PVector target = PVector.sub(mid2,mid1);
target.rotate(PI/3);
target.add(mid1);
if(frameCount < 60*deep) {
float dt = frameCount%(60);
PVector mid = PVector.lerp(midonLine,target,dt/60.0);
line(s.x,s.y,mid1.x,mid1.y);
line(mid.x,mid.y,mid1.x,mid1.y);
line(mid.x,mid.y,mid2.x,mid2.y);
line(e.x,e.y,mid2.x,mid2.y);
}
else{
bla(s,mid1,deep+1);
bla(mid1,target,deep+1);
bla(target,mid2,deep+1);
bla(mid2,e,deep+1);
}
}
void tri(PVector p1, PVector p2, PVector p3){
bla(p1,p2,1);
bla(p2,p3,1);
bla(p3,p1,1);
}