Putting the dots and lines together – the code

// create an Ammann-Beenker tiling
// needs the code of class Vector, class TPoint, class Tiling and saveImage

float unitLength;
float xRange,yRange;     // visible coordinates from -(xy)Range to +(xy)Range
float sqrt2=sqrt(2.),sqrt05=sqrt(0.5);
float xShift,yShift;     //  shifting one grid to get different parts of the tiling
float small,lineLenghtSquare;
Tiling tiling;

void setup(){
  size(700,600);
  smooth();
  background(255);
  unitLength=20;
  xShift=0.2;
  yShift=0.01;
  ellipseMode(CENTER);
  small=0.01;
  tiling=new Tiling();
}

void draw(){
  noLoop();
  setupCoordinates();
  background(255);
  fill(0,255,0);
  stroke(0);
  ammannBeenkerProjection();
  lineLenghtSquare=tiling.minDistanceSquare()/(2-sqrt2);
  tiling.generateLines(lineLenghtSquare);
  tiling.sortConnections();
  tiling.showConnections();
  tiling.showTiles();

  saveImage();
}

void setupCoordinates(){  
  translate(width/2,height/2);
  scale(unitLength,-unitLength);
  trueStrokeWeight(2.);
                                  //  attention vectorDiameter has to be float
  vectorDiameter=6/unitLength;    // that's not good programming style
  xRange=0.5*width/unitLength;
  yRange=0.5*height/unitLength;
}

void trueStrokeWeight(float weight){
 strokeWeight(weight/unitLength);
} 

//  ammann-beenker projection

  // projektion method

  void ammannBeenkerProjection() {
    int i1, j1, i2, j2, limit;
    float x1, y1;
    int x2, y2; 
    float xm, ym, dx, dy, h;
    Vector v;
    limit=int(xRange*2);
    for (i1=-limit;i1 < limit;i1++) {
      for (j1=-limit;j1 < limit;j1++) {
        //center points of diagonal lattice
        x1=(i1+j1)*sqrt05+xShift;
        y1=(i1-j1)*sqrt05+yShift;
        if((abs(x1) < xRange)&&(abs(y1) < yRange)){ //continue only if on screen
          x2=round(x1);   //next center points of straight square lattice
          y2=round(y1);
          dx=abs(x1-x2);    //  difference between points inside octagon ???
          dy=abs(y1-y2);
          if (dy>dx) {
            h=dx;
            dx=dy;
            dy=h;
          }
          if ((dx < (sqrt05-0.5))&&((dx+dy) < (1-sqrt05))) {  
            xm=(x1+x2)/2;                         // yes: got new corner point 
            ym=(y1+y2)/2;
            v=new Vector(xm,ym);
            v.show();
            tiling.add(new TPoint(v));
           // ellipse(xm, ym,0.25,0.25);              // show the point
          }
        }
      }
    }
  }
This entry was posted in programming, Quasiperiodic design, Tilings 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