Moiré Processing

Using Processing to produce Moiré patterns.

Processing code:

//moiré maker by kjanzen, 2012
//Drawing two sets of lines at varying angles and spacings. (see settings)
//Press 'p' to save as PDF. (saves to sketch directory)
import processing.pdf.*;
void setup() {
size(1280, 720); //size (pixels x pixels)
background(255); //backgtound colour (0 = black, 255 = white)
}
void keyPressed(){
 if (key=='p'){ //press 'p' to save PDF (saves to sketch dir)
 beginRecord(PDF, "moire.pdf"); //save PDF as ('name'.pdf)
}
}
void draw() {
//settings
int angle1 = 0; //adjust angle for set1 (<20)
int angle2 = 0; //adjust angle for set2 (<20)
int spacing1 = 10; //adjust spacing for set2
int spacing2 = 7; //adjust spacing for set2
int shift1 = 1; //adjust shift for set1 (!=0)
int shift2 = 1; //adjust shift for set2 (!=0)
//set1
for (int i=0; i<width+1500; i+=spacing1) {
 stroke(0);
 pushMatrix();
 // move the origin to the pivot point
 translate(0, -500);
 // then pivot the grid
 rotate(radians(angle1));
 // and draw the square at the origin
 line(i, 0, i/shift1, width+1500);
 popMatrix();
//set2
 for (int j=0; j<width+1500; j+=spacing2) {
 stroke(0);
 pushMatrix();
 // move the origin to the pivot point
 translate(0, -500);
 // then pivot the grid
 rotate(radians(angle2));
 // and draw the square at the origin
 line(j, 0, j/shift2, width+1500);
 popMatrix();
}
}
 endRecord();
}
Advertisements

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

%d bloggers like this: