-
Notifications
You must be signed in to change notification settings - Fork 3
/
sketch.js
executable file
·69 lines (61 loc) · 1.35 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Code written by Selcuk ARTUT 2022
Geometric Patterns with Creative Coding
All rights reserved
*/
// Motif class
class Motif {
constructor(a) {
this.a = a;
}
display() {
let x0, y0, x1, y1;
x0 = 0;
y0 = 0;
x1 = a * cos(30);
y1 = a * sin(30);
for (let i = 0; i < 12; i++) {
push();
rotate(i * 30);
translate(0, -a);
beginShape();
vertex(x1, -y1);
vertex(x0, -y0);
vertex(-x1, -y1);
endShape();
pop();
}
}
}
//scale factor
let a = 32;
let motif = new Motif(a);
let nRow;
let nCol;
let dx, dy, doff;
function setup() {
createCanvas(800, 800);
angleMode(DEGREES);
noFill();
noLoop();
dx = 2 * (a + a * sin(30));
dy = 4 * a * cos(30);
doff = 2 * a * cos(30);
//approximate the nRow and nCol values
nRow = 1 + ceil(height / dy);
nCol = 1 + ceil(width / dx);
}
function draw() {
for (let c = 0; c < nCol; c++) {
for (let r = 0; r < nRow; r++) {
push();
if (c % 2 == 1) {
//columns 1,3,5,7
translate(0, doff);
}
translate(dx * c, dy * r);
motif.display();
pop();
}
}
}