-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathliveSketch.js
More file actions
39 lines (33 loc) · 814 Bytes
/
liveSketch.js
File metadata and controls
39 lines (33 loc) · 814 Bytes
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
/**
* Easing.
*
* Move the mouse across the screen and the symbol will follow.
* Between drawing each frame of the animation, the program
* calculates the difference between the position of the
* symbol and the cursor. If the distance is larger than
* 1 pixel, the symbol moves part of the distance (0.05) from its
* current position toward the cursor.
*/
function runLiveSketch(s) {
var x = 0;
var y = 0;
var easing = 0.05;
s.setup = () => {
s.createCanvas(640, 360);
s.noStroke();
};
s.draw = () => {
s.background(51);
var targetX = s.mouseX;
var dx = targetX - x;
if (s.abs(dx) > 1) {
x += dx * easing;
}
var targetY = s.mouseY;
var dy = targetY - y;
if (s.abs(dy) > 1) {
y += dy * easing;
}
s.ellipse(x, y, 66, 66);
};
}