This repository was archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwistArm.js
More file actions
227 lines (203 loc) · 5.61 KB
/
twistArm.js
File metadata and controls
227 lines (203 loc) · 5.61 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
var radius = 0;
var speed = 0;
var rCircle = 0;
var center = 0;
var angle = 0;
var animate = 0;
var initialClickAngle = 0;
var hasBeenRecorded = false;
var ifLoopSection = 0;
var exit;
var quitActivity = false;
var rotationsCompleted = 0;
var hasBeenCounted = false;
var isAnimationGoing = true;
var animationAngle = 25;
var animationSpeed = -1;
function setup() {
createCanvas(700, 700);
angleMode(DEGREES);
exit = new Clickable();
exit.locate(44*width/50, height/50);
exit.resize(width/10, height/15);
exit.textSize = 20;
exit.text = "exit";
exit.onOutside = function () {
this.color = "#FFFFFF";
};
exit.onHover = function () {
this.color = "#AA33AA";
};
exit.onPress = function () {
quitActivity = true;
};
endAnimation = new Clickable();
endAnimation.locate(width/2 - width/14, 3*height/4);
endAnimation.resize(width/7, height/15);
endAnimation.textScaled = false;
endAnimation.textSize = 20;
endAnimation.text = "START";
endAnimation.onOutside = function () {
this.color = "#FFFFFF";
};
endAnimation.onHover = function () {
this.color = "#AA33AA";
};
endAnimation.onPress = function () {
isAnimationGoing = false;
};
}
function draw() {
if(isAnimationGoing == true){
background("lightblue");
arrows();
animation();
endAnimation.draw();
//debug();
}
else{
if(quitActivity == false) {
if(rotationsCompleted < 5) {
background("lightblue");
arrows();
exit.draw();
recordInitialClick();
//debug();
var angle = mouseAngle();
if(mouseIsPressed && (angle < -70 || angle > 230) && (initialClickAngle > 10 && initialClickAngle < 50)){
trackingCircles(angle, "green");
if(hasBeenCounted == false) {
rotationsCompleted++;
hasBeenCounted = true;
}
}
else if(mouseIsPressed) {
trackingCircles(angle, "red");
}
else {
startingCircles();
hasBeenCounted = false;
}
}
else {
background("lightgray");
textSize(48);
fill("green");
text('Congratulations', width/2, height/2 - (height/10));
exit.textSize = 17;
exit.text = "return to menu";
exit.resize(width/5, height/10);
exit.locate(width/2 - width/10, height/2);
exit.draw();
}
}
else {
noCanvas();
window.location.href = "index.html";
}
}
}
function arrows() {
/* for triangle construction */
var center = [width/2, height/2];
var radius1 = width/12.5;
var radius2 = radius1 + width/50;
var radius3 = radius1 + width/25;
/* traingle 1 */
var point1 = [center[0] + (radius1 * cos(0)),
center[1] + (radius1 * sin(0))];
var point2 = [center[0] + (radius2 * cos(0)),
center[1] + (radius2 * sin(-18))];
var point3 = [center[0] + (radius3 * cos(0)),
center[1] + (radius3 * sin(0))];
/* triangle 2 */
var point4 = [center[0] + (radius1 * cos(-120)),
center[1] + (radius1 * sin(-120))];
var point5 = [center[0] + (radius2 * cos(-138)),
center[1] + (radius2 * sin(-135))];
var point6 = [center[0] + (radius3 * cos(-120)),
center[1] + (radius3 * sin(-120))];
/* triangle 3 */
var point7 = [center[0] + (radius1 * cos(-240)),
center[1] + (radius1 * sin(-240))];
var point8 = [center[0] + (radius2 * cos(-255)),
center[1] + (radius2 * sin(-267))];
var point9 = [center[0] + (radius3 * cos(-240)),
center[1] + (radius3 * sin(-240))];
strokeWeight(4);
fill("lightblue");
stroke("black");
arc(width/2, height/2, width/5, height/5, 0, 60);
arc(width/2, height/2, width/5, height/5, 120, 180);
arc(width/2, height/2, width/5, height/5, 240, 300);
strokeWeight(1);
fill("black");
triangle(point1[0], point1[1], point2[0], point2[1], point3[0], point3[1]);
triangle(point4[0], point4[1], point5[0], point5[1], point6[0], point6[1]);
triangle(point7[0], point7[1], point8[0], point8[1], point9[0], point9[1]);
}
function trackingCircles(startingAngle, fillColor) {
var center = width/2;
var placementRadius = 150;
var circleRadius = 60;
var angle = startingAngle;
stroke("black");
fill(fillColor);
/* creates fingers */
for(var i = 0; i < 5; i++) {
var x = center + (placementRadius * cos(angle));
var y = center + (placementRadius * sin(angle));
circle(x,y, circleRadius);
if(i == 3) {
angle = angle - 75;
}
else {
angle = angle - 40;
}
}
}
function startingCircles() {
trackingCircles(25, "gray");
}
function mouseAngle() {
var center = [width/2, height/2];
var angle = atan( (center[1] - mouseY) / (mouseX - center[0]) );
if(mouseX < center[0]) {
angle = angle - 180;
}
return -angle;
}
function animation() {
if (animationAngle < -100 && animationAngle > -140) {
trackingCircles(animationAngle, "green");
}
else if(animationAngle < -140) {
animationAngle = 25;
}
else {
trackingCircles(animationAngle, "red");
}
animationAngle += animationSpeed;
}
function recordInitialClick() {
if(mouseIsPressed && (hasBeenRecorded == false) ) {
initialClickAngle = mouseAngle();
hasBeenRecorded = true;
ifLoopSection = 1;
}
else if(!mouseIsPressed) {
hasBeenRecorded = false;
initialClickAngle = 0;
ifLoopSection = 2;
}
else {
initialClickAngle = initialClickAngle;
ifLoopSection = 3;
}
}
function debug() {
//text(initialClickAngle, 100, 30);
//text(hasBeenRecorded, 100, 50);
//text(ifLoopSection, 100, 70);
text(animationAngle, 100, 30);
}