-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
99 lines (79 loc) · 1.83 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
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
let canvas;
let lastXpos;
let lastYpos;
let scale;
let aTouchStarted;
function setup() {
mycanvas = createCanvas(windowWidth, windowHeight);
mycanvas.touchStarted(newTouchStarted)
background(color(255));
scale = 3;
button = createButton('Start på Vytt!');
button.position(10, 10);
button.mousePressed(reset);
touchStarted = false;
noStroke()
}
function draw() {
if (aTouchStarted) {
lastXpos = mouseX;
lastYpos = mouseY;
}
if (mouseIsPressed) {
if (!lastXpos > 0) {
lastXpos = mouseX;
lastYpos = mouseY;
}
// Middle piece: black or green
if (mouseY > lastYpos) {
fill(color('#00866e'));
} else {
// Up: green
fill(color(0));
}
beginShape();
vertex(lastXpos - scale, lastYpos);
vertex(lastXpos + scale, lastYpos);
vertex(mouseX + scale, mouseY);
vertex(mouseX - scale, mouseY);
endShape(CLOSE);
// White
fill(color(255));
drawArea(1);
// Black
fill(color(0));
drawArea(3);
// White outer
fill(color(255));
drawArea(5);
}
lastXpos = mouseX;
lastYpos = mouseY;
aTouchStarted = false;
}
function drawArea(startPoint) {
let endPoint = startPoint + 2
// left
beginShape();
vertex(lastXpos - startPoint * scale, lastYpos);
vertex(lastXpos - endPoint * scale, lastYpos);
vertex(mouseX - endPoint * scale, mouseY);
vertex(mouseX - startPoint * scale, mouseY);
endShape(CLOSE);
// right
beginShape();
vertex(lastXpos + startPoint * scale, lastYpos);
vertex(lastXpos + endPoint * scale, lastYpos);
vertex(mouseX + endPoint * scale, mouseY);
vertex(mouseX + startPoint * scale, mouseY);
endShape(CLOSE);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function reset() {
background(color(255));
}
function newTouchStarted() {
aTouchStarted = true;
}