-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.js
More file actions
25 lines (23 loc) · 839 Bytes
/
template.js
File metadata and controls
25 lines (23 loc) · 839 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
window.onload = function () {
const PI = Math.PI;
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
width = (canvas.width = window.innerWidth),
height = (canvas.height = window.innerHeight),
p= particle.create(width/2, height/2, 10 , PI/3);
render();
function render() {
context.clearRect(0, 0, width, height);
if (p.position.getX()-p.radius > width) {
p.position.setX(0-p.radius);
} else if (p.position.getX()+p.radius < 0) {
p.position.setX(width-p.radius);
} else if (p.position.getY()-p.radius > height) {
p.position.setY(0-p.radius);
} else if (p.position.getY()+p.radium < 0) {
p.position.setY(height-p.radius);
}
//call render method everytime frame gets updated
requestAnimationFrame(render);
}
};