Skip to content

Instantly share code, notes, and snippets.

@Morpholux
Created September 19, 2023 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Morpholux/75d958e1ab9ce2236f25d3dec664a784 to your computer and use it in GitHub Desktop.
Save Morpholux/75d958e1ab9ce2236f25d3dec664a784 to your computer and use it in GitHub Desktop.
Complex pattern
// renaud.jean-francois(arobas)uqam(point)ca
// Syntaxe Processing version 4.3
// lundi, 18 septembre 2023
color w, k, y;
void setup() {
size(840, 840);
background(0);
noStroke();
w = color(#E1DCD2); // off white
k = color(#41413C); // dark gray
y = color(#C8963C); // dull yellow
noLoop();
}
void draw() {
background(w);
translate(20, 20); // margin of 20 pixels, so inside pattern will be 800x800 px
// first quadrant (upper left corner), which is a 4 x 4 tiles
pushMatrix();
translate(200, 200);
rotate(PI);
tile(); // one tile is 8 x 8 modules
popMatrix();
pushMatrix();
translate(200, 200);
rotate(-HALF_PI);
tile();
popMatrix();
pushMatrix();
translate(200, 200);
rotate(HALF_PI);
tile();
popMatrix();
k = y; // we change black to yellow
pushMatrix();
translate(200, 200);
tile();
popMatrix();
// reset black variable to black color
k = color(#41413C);
// second quadrant (upper right corner)
pushMatrix();
translate(400, 0);
pushMatrix();
translate(200, 200);
rotate(PI);
tile();
popMatrix();
pushMatrix();
translate(200, 200);
rotate(-HALF_PI);
tile();
popMatrix();
k = y;
pushMatrix();
translate(200, 200);
rotate(HALF_PI);
tile();
popMatrix();
k = color(#41413C);
pushMatrix();
translate(200, 200);
tile();
popMatrix();
popMatrix();
// third quadrant (down left corner)
pushMatrix();
translate(0, 400);
pushMatrix();
translate(200, 200);
rotate(PI);
tile();
popMatrix();
k = y;
pushMatrix();
translate(200, 200);
rotate(-HALF_PI);
tile();
popMatrix();
k = color(#41413C);
pushMatrix();
translate(200, 200);
rotate(HALF_PI);
tile();
popMatrix();
pushMatrix();
translate(200, 200);
tile();
popMatrix();
popMatrix();
// fourth quadrant (down right corner)
pushMatrix();
translate(400, 400);
k = y;
pushMatrix();
translate(200, 200);
rotate(PI);
tile();
popMatrix();
k = color(#41413C);
pushMatrix();
translate(200, 200);
rotate(-HALF_PI);
tile();
popMatrix();
pushMatrix();
translate(200, 200);
rotate(HALF_PI);
tile();
popMatrix();
pushMatrix();
translate(200, 200);
tile();
popMatrix();
popMatrix();
//save render
save("pattern.jpg");
}
// tile function
void tile() {
pushMatrix();
scale(25);
for (int j = 0; j < 8; j++) {
for (int i = 0; i < 8; i++) {
pushMatrix();
translate(i, j);
if (j%4 == 0) {
if (i%4 == 0) {
module(w, k); // white triangle above black
} else if ((i%4 > 0) && (i%4 < 3)) {
module(k, w); // black triangle above white
} else {
module(w, k);
}
} else if (j%4 == 1) {
if (i%4 < 2) {
module(k, w);
} else {
module(w, k);
}
} else if (j%4 == 2) {
if (i%4 == 0) {
module(k, w);
} else if ((i%4 > 0) && (i%4 < 3)) {
module(w, k);
} else {
module(k, w);
}
} else {
if (i%4 < 2) {
module(w, k);
} else {
module(k, w);
}
}
popMatrix();
}
}
popMatrix();
}
// module function, which is the smallest unit
// square made of two triangles
void module(color c1, color c2) {
fill(c1);
triangle(0, 0, 1, 0, 1, 1);
fill(c2);
triangle(0, 0, 1, 1, 0, 1);
}
@Morpholux
Copy link
Author

Morpholux commented Sep 19, 2023

Result look like this :

pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment