Iteration of rhombs: the programming code

//  this is the processing code for the iteration of rhombs
//  you can reproduce my results of the earlier posts
//  feel free to experiment !
//
//  to run it you have first to download “processing” from processing.org
//  it is free !!
//
// you then just paste and copy the code into the editor-window and choose run from the sketch-menu
//

color[] colors=new color[2];
int nRot;

void setup() {
size(620, 600);
smooth();
colors[0]=color(150, 255, 128);
colors[1]=color(255, 120, 100);
//  number for nRot-fold rotational symmetry
nRot=12;
//  nRot=8;
// nRot=10;
}

void draw() {
noLoop();
background(0);
stroke(255);
// noStroke();
strokeCap(ROUND);
strokeWeight(2);
float angle;
float zx=50;
float zy=90;
float theSize=1000;
int theColor=1;
int numberIterations=5;
//for (int i=0; i                                        This is a copying error

for (int i=0; i<nRot;i++){                      //  this is correct
theColor=1-theColor;
angle=2*PI*i/nRot;
iteRhomb(zx, zy, zx+theSize*cos(angle), zy+theSize*sin(angle), numberIterations, theColor);
}
}

void iteRhomb(float x1, float y1, float x2, float y2, int ite, int theColor) {
float ax=(x1+x2)/2;
float ay=(y1+y2)/2;
float dx=x2-x1;
float dy=y2-y1;
float alfa=0.5*tan(PI/nRot);
float aax=ax-alfa*dy, aay=ay+alfa*dx;
float bbx=ax+alfa*dy, bby=ay-alfa*dx;

if (ite<=0) {
fill(colors[theColor]);
//   noFill();
quad(x1, y1, bbx, bby, x2, y2, aax, aay);
}
else {
iteRhomb(x1, y1, bbx, bby, ite-1, theColor);
iteRhomb(x2, y2, bbx, bby, ite-1, 1-theColor);
iteRhomb(x1, y1, aax, aay, ite-1, 1-theColor);
iteRhomb(x2, y2, aax, aay, ite-1, theColor);
//  12 er extra
if (nRot==12) {
iteRhomb(aax, aay, bbx, bby, ite-2, theColor);
}
}
}

This entry was posted in Tilings and tagged , , , . Bookmark the permalink.

6 Responses to Iteration of rhombs: the programming code

1. Eric says:

I’ve greatly enjoyed working my way through your blog posts. Thank you very much for offering so much on this blog. The above post, however, is my favorite, because it offered code! It has been very interesting to use the code with Processing – trying out odd values of n, attempting to fill the gaps (I know you blog about this later on, but it is an interesting exercise), and beyond that, it was great to see some example code.

If you were interested, it would be great to see some code for other examples of aperiodic tiling. For example, it would be very helpful to see Processing code (or code in another language) showing how you implement the dual grid method, generating Stampfli tiling, as you did here:
https://geometricolor.wordpress.com/2012/05/29/a-tiling-of-12-fold-rotational-symmetry-from-two-hexagon-grids/

If that’s too much work, it would be completely understandable – I just thought I’d offer some feedback.

Thanks again!

• Peter Stampfli says:

It would be quite difficult to present the code for the implementation of the dual method. It is at the moment a terrible hack of thousands of lines. But you are right, it is a good idea to rewrite it in a understandable form.

• Eric says:

That would be wonderful, if it isn’t too big a project.

But in general, I just wanted to offer the opinion that adding code to this blog would really enhance it. Even hard-to-understand and/or very long code is a big enhancement, if it has variables to tweak.

I’d love to see other tilings via substitution, especially if they are easy for you (but perhaps harder for readers like me.) I’m currently trying to adapt the above code to create various aperiodic rhombic tilings, and while I don’t have an issue with the programming, I find the geometry to be tricky. On the other hand, as a recovering math-phobe, this blog is certainly inspiring me to improve my knowledge of geometry! Thanks again.

2. Steve says:

Thanks a lot! It works really well now.

I’m a grad student in the US, and in my research, I’ve started to look at a lot of quasiperiodic and tiled patterns. Your posts are very helpful.

3. Steve says:

Hi, I think you’ve discussed some really great info on this blog. I tried to run your script with Processing, but it keeps on giving me an error around ‘theColor=1-theColor;’ Can you check it see if it works for you and how I can fix the code? Thanks!

• Peter Stampfli says:

Thanks for your interest. It seems that you are the first to try the program.
The problem lies in the line before. It is
the beginning of a for-loop. I made same mistake in copying and pasting.

It should be :

for (int i=0; i<nRot;i++){

I will fix the post. Have fun with it. Try some experiments.
The reference section at processing.org is really good. An introduction to java