Repository navigation
Expand file tree
/
Copy pathsketch.js
More file actions
290 lines (180 loc) · 4.92 KB
/
Copy pathsketch.js
File metadata and controls
290 lines (180 loc) · 4.92 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
function inputSelectChanged() {
var option = $('#inputSelect').val();
_input = option;
}
function playButtonClicked() {
if (_paused) {
$('#playButton').html('Pause');
_paused = false;
} else {
$('#playButton').html('Play');
_paused = true;
}
}
function resetButtonClicked() {
document.location.reload();
}
function textReferenceChanged() {
_globalReferences[0] = parseFloat($('#textReference').val());
}
function activateControl() {
_globalReferences[0] = parseFloat($('#textReference').val());
_communicator = new Communication(()=>{
resetComtrol();
alert('Control Server is out...');
});
$('#buttonControl').html('stop...');
_isControlling = true;
_input = 'none';
$('#inputSelect').prop('disabled', true);
$('#inputSelect option[value=none]').prop('selected', true);
}
function resetComtrol() {
$('#buttonControl').html('Control');
_isControlling = false;
_communicator.socket.close();
$('#inputSelect').prop('disabled', false);
}
function controlButtonClicked() {
if (!_isControlling) {
activateControl();
} else {
resetComtrol();
}
}
function displayRadioChanged() {
switch ($("input[name='displayRadio']:checked").val()) {
case "images":
system.drawingImages = true;
system.drawingBlocks = false;
system.drawingAxis = false;
break
case "blocks":
system.drawingImages = false;
system.drawingBlocks = true;
system.drawingAxis = false;
break
case "axis":
system.drawingImages = false;
system.drawingBlocks = false;
system.drawingAxis = true;
break
}
}
function processInput() {
$('#spanTime').html(_t.toFixed(3));
$('#spanAmplitude').html((_inputAmplitude*_inputScale).toFixed(3));
$('#spanFrequency').html(_inputFrequency.toFixed(3));
if (_isDragging && (_input != "none")) {
_inputAmplitude -= (mouseY-pmouseY)/height;
_inputFrequency += (mouseX-pmouseX)/width;
}
let amp = _inputAmplitude*_inputScale;
switch (_input) {
case "step":
if (_t>T0) {
_globalInput = amp;
}
break
case "pulse":
if (_t>T0) {
_globalInput = amp;
}
if (_t>T0+_inputFrequency) {
_globalInput = amp;
}
break
case "square":
if (Math.sin(_t*_inputFrequency)>0)
_globalInput = amp;
else
_globalInput = -amp;
break
case "sine":
_globalInput = amp*Math.sin(_t*_inputFrequency);
break
case "noise":
_globalInput = amp*noise(_t*_inputFrequency);
break;
}
}
function init() {
// implement
}
function updateValues() {
// implement
}
function updateSystem() {
// implement
}
function setup() {
CANVAS = createCanvas(SCREEN_SIZE_W, SCREEN_SIZE_H/3, WEBGL);
CANVAS.parent("systemCanvas");
$('#osciloscopeDiv').height(SCREEN_SIZE_H/4);
frameRate(60);
init();
}
function mousePressed() {
_hasMousePressed = CLICK_SHOW_TIME;
if ( Math.abs(mouseY>0)) {
_isDragging = true;
}
}
function mouseReleased() {
_hasMousePressed = CLICK_SHOW_TIME;
_isDragging = false;
}
function mouseWheel(event) {
if (keyIsDown(SHIFT)) {
_cameraDist += event.delta;
} else {
_cameraTeta -= event.deltaX/100;
_cameraPhi += event.deltaY/100;
}
return false;
}
var dragAmount = 0
var sawPrize = false
function mouseDragged() {
if (_isDragging && (_input == "none")) {
_globalInput += _inputScale*(mouseX - pmouseX)/width;
// dragAmount += 1
// if (dragAmount > 100 && !sawPrize) {
// alert("Congratulations for using iDynamic! You might earn 1.0 point in the discipline! Send an email to me (allan@dee.ufrn.br) referring to this code: CTRL_I_EA_2020.2. If you happen to be the first three to see this message, congratulations, you earned 1.0 point. If more than 3 people already won, don't give up! There might be mode points hidden in the apps (not only this one)");
// sawPrize = true;
// }
}
return false;
}
function drawCursor() {
var canvas = document.getElementById("2DCanvas");
var ctx = canvas.getContext("2d");
ctx.resetTransform();
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (_hasMousePressed>0) {
ctx.globalAlpha = 0.9;
ctx.beginPath();
for (var ang = 0.0; ang<2*Math.PI; ang += Math.PI/3) {
ctx.moveTo( mouseX+1.5*CURSOR_SIZE*Math.cos(ang), mouseY+1.5*CURSOR_SIZE*Math.sin(ang) );
ctx.lineTo( mouseX+2.5*CURSOR_SIZE*Math.cos(ang), mouseY+2.5*CURSOR_SIZE*Math.sin(ang) );
}
ctx.lineWidth = 6;
ctx.strokeStyle = '#505050';
ctx.stroke();
_hasMousePressed--;
console.log('click');
}
if (_isDragging) {
ctx.globalAlpha = 0.5;
ctx.beginPath();
ctx.arc(mouseX, mouseY, CURSOR_SIZE, 0, 2 * Math.PI, false);
ctx.fillStyle = 'yellow';
ctx.fill();
ctx.lineWidth = 3;
ctx.strokeStyle = '#505050';
ctx.stroke();
}
}
function draw() {
// implement
}