-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (47 loc) · 1.12 KB
/
script.js
File metadata and controls
61 lines (47 loc) · 1.12 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
const canvas = document.querySelector("canvas");
const context = canvas.getContext("2d");
canvas.width = 500;
canvas.height = 500;
let angle = 0
animation({
clear() {
context.clearRect(0, 0, canvas.width, canvas.height);
},
update() {
angle += Math.PI * 0.01;
},
render() {
context.beginPath();
context.arc(
canvas.width / 2 ,
250 - (150 * Math.sin(angle)),
25,
0,
Math.PI * 2,
);
context.fillStyle = "white";
context.fill()
}
})
function animation(obj) {
const {clear, update, render} = obj;
let pTimestamp = 0;
requestAnimationFrame(tick);
function tick(timestamp) {
requestAnimationFrame(tick);
const diff = timestamp - pTimestamp;
pTimestamp = timestamp;
const fps = 1000 / diff;
const secondPart = diff / 1000;
const params = {
timestamp,
pTimestamp,
diff,
fps,
secondPart,
};
update(params);
clear();
render(params);
}
}