forked from DRynne/Multiscale-Truchet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwingtile.js
105 lines (97 loc) · 2.43 KB
/
wingtile.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class Wingtile {
constructor(motif, phase, boundary, color) {
//motif is the pattern, phase is white on black or black on white
this.motif = motif;
this.phase = phase;
this.boundary = boundary;
this.color = color;
if (this.phase) {
let tempcol;
tempcol = this.color[1];
this.color[1] = this.color[0];
this.color[0] = tempcol;
}
}
draw() {
if (this.motif === ' ') {
return;
}
let x = this.boundary.x;
let y = this.boundary.y;
let w = this.boundary.w;
let h = this.boundary.h;
let smallr = (2 * w) / 6;
let bigr = (2 * w) / 3;
let arcd = (2 * 2 * 2 * w) / 3;
noStroke();
rectMode(RADIUS);
fill(this.color[1]);
rect(x, y, w, h);
fill(this.color[0]);
switch (this.motif) {
case '\\':
arc(x + w, y - h, arcd, arcd, PI / 2, PI);
arc(x - w, y + h, arcd, arcd, (3 * PI) / 2, 2 * PI);
break;
case '/':
arc(x - w, y - h, arcd, arcd, 0, PI / 2);
arc(x + w, y + h, arcd, arcd, PI, (3 * PI) / 2);
break;
case '-':
rect(x, y, w, smallr);
break;
case '|':
rect(x, y, smallr, h);
break;
case '+.':
break;
case 'x.':
fill(this.color[0]);
rect(x, y, w, h);
break;
case '+':
rect(x, y, w, smallr);
rect(x, y, smallr, h);
break;
case 'fne':
arc(x + w, y - h, arcd, arcd, PI / 2, PI);
break;
case 'fsw':
arc(x - w, y + h, arcd, arcd, (3 * PI) / 2, 2 * PI);
break;
case 'fnw':
arc(x - w, y - h, arcd, arcd, 0, PI / 2);
break;
case 'fse':
arc(x + w, y + h, arcd, arcd, PI, (3 * PI) / 2);
break;
case 'tn':
fill(this.color[0]);
rect(x, y - smallr, w, bigr);
break;
case 'ts':
fill(this.color[0]);
rect(x, y + smallr, w, bigr);
break;
case 'te':
fill(this.color[0]);
rect(x + smallr, y, bigr, h);
break;
case 'tw':
fill(this.color[0]);
rect(x - smallr, y, bigr, h);
break;
default:
}
fill(this.color[1]);
circle(x - w, y - h, bigr);
circle(x + w, y - h, bigr);
circle(x - w, y + h, bigr);
circle(x + w, y + h, bigr);
fill(this.color[0]);
circle(x, y - h, smallr);
circle(x + w, y, smallr);
circle(x, y + h, smallr);
circle(x - w, y, smallr);
}
}