Iterative method for the Ammann-Beenker tiling – the code

// needs class Vector and saveImage code
// for details see Iterative method for the Ammann-Beenker tiling using “Vector”

Vector a,b,c;
float f;

void setup(){
  size(600,600);
  f=1./(1.+sqrt(2.));
  strokeWeight(2);
  smooth();
}

void draw(){
  noLoop();
a=new Vector(-10,-10);
b=new Vector(1200,-10);
c=new Vector(-10,1200);
int ite=4;
triangle(a,b,c,ite);
saveImage();
}

void quad(Vector a,Vector b,Vector c){
  Vector d=sub(c,a);
  d.add(b);
  quad(a.x,a.y,b.x,b.y,d.x,d.y,c.x,c.y);
}

void triangle(Vector a,Vector b,Vector c,int ite){
  if(ite==0){
    fill(255,128,128);
    quad(a,b,c);
    return;
  }
  Vector m=interpolate(0.5,b,c);
  Vector z=interpolate(f,m,a);
  Vector mc=interpolate(f,m,c);
  Vector mb=interpolate(f,m,b);
  Vector ac=interpolate(f,a,c);
  Vector ba=interpolate(f,b,a);
  triangle(z,mc,mb,ite-1);
  triangle(mc,c,ac,ite-1);
  triangle(z,a,ba,ite-1);
  rhomb(z,mb,ba,ite-1);
  rhomb(a,ac,z,ite-1);
}


void rhomb(Vector a,Vector b,Vector c,int ite){
  if(ite==0){
    fill(128,128,255);
    quad(a,b,c);
    return;
  }
  Vector d=sub(c,a);
  d.add(b);
  Vector z=interpolate(0.5,a,d);
  Vector za=interpolate(f/(2+f),z,a);
  Vector zd=interpolate(f/(2+f),z,d);
  Vector ac=interpolate(f,a,c);
  Vector ab=interpolate(f,a,b);
  Vector dc=interpolate(f,d,c);
  Vector db=interpolate(f,d,b);
  triangle(za,c,ac,ite-1);
  triangle(za,b,ab,ite-1);
  triangle(zd,c,dc,ite-1);
  triangle(zd,b,db,ite-1);
  rhomb(c,za,zd,ite-1);
  rhomb(a,ab,ac,ite-1);
  rhomb(d,dc,db,ite-1);
}
This entry was posted in programming, Quasiperiodic design and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s