Recursive Triangle(Processing)


by Flik
2017-10-22

sourcecode


void setup() {
  size(800, 800);
}

void draw() {
  translate(width/2, height*0.12);
  scale(1.5);

  recursive(0, 0, -int(width*0.5/sqrt(3)), height/2, int(width*0.5/sqrt(3)), height/2, 0);
}



void recursive(int x1, int y1, int x2, int y2, int x3, int y3, int l) {
  if (l<20) {
    triangle(x1, y1, x2, y2, x3, y3);
 
    int a=9; 
    int b=1;
    recursive((a*x1+b*x2)/(a+b), (a*y1+b*y2)/(a+b),
      (a*x2+b*x3)/(a+b), (a*y2+b*y3)/(a+b),
      (a*x3+b*x1)/(a+b), (a*y3+b*y1)/(a+b), l+1);
  }
}

댓글