-
Notifications
You must be signed in to change notification settings - Fork 20
/
sketch.js
executable file
·67 lines (60 loc) · 1.59 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
var radius;
var cx, cy;
var third;
var bShowDebug;
var nArcPoints = 30;
var angularAmount;
//-----------------------------------------
function setup() {
createCanvas(400, 400);
radius = width / 2 * 0.75;
cx = width / 2;
cy = height / 2;
third = TWO_PI / 3.0;
bShowDebug = false;
}
//-----------------------------------------
function draw() {
background(255);
noFill();
stroke(0);
strokeWeight(3);
strokeJoin(ROUND);
angularAmount = pow(0.5 + 0.5 * sin(millis() / 2000.0), 2.0);
beginShape();
for (var j = 0; j < 3; j++) {
for (var i = 0; i <= nArcPoints; i++) {
var angCenter = (j + 0.5) * third;
var angA = angCenter - angularAmount * 0.5 * third;
var angB = angCenter + angularAmount * 0.5 * third;
var t = map(i, 0, nArcPoints, angA, angB) + HALF_PI;
var px = cx + radius * cos(t);
var py = cy + radius * sin(t);
vertex(px, py);
}
}
endShape(CLOSE);
drawDebug();
}
//-----------------------------------------
function keyPressed(){
bShowDebug = !bShowDebug;
}
//-----------------------------------------
function drawDebug() {
if (bShowDebug) {
stroke(255, 0, 0, 64);
strokeWeight(1);
for (var j = 0; j < 3; j++) {
for (var i = 0; i <= nArcPoints; i++) {
var angCenter = (j + 0.5) * third;
var angA = angCenter - angularAmount * 0.5 * third;
var angB = angCenter + angularAmount * 0.5 * third;
var t = map(i, 0, nArcPoints, angA, angB) + HALF_PI;
var px = cx + radius * cos(t);
var py = cy + radius * sin(t);
line(cx, cy, px, py);
}
}
}
}