-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.js
42 lines (34 loc) · 919 Bytes
/
stars.js
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
const starsArray = [];
const bang = new Image();
bang.src = '/src/images/star.png';
class Star {
constructor(){
this.x = canvas.width;
this.y = Math.random() * canvas.height;
this.radius = 25;
this.speed = Math.random() * 5 + 1;
this.distance;
this.color = 'hsla(' + hue + ', 100%, 50%, 0.8)';
}
update(){
this.x -= this.speed;
}
draw(){
// const bang = new Image();
// bang.src = '/src/images/star.png';
ctx.drawImage(bang, this.x, this.y, 30, 30);
}
}
function handleStars(){
if (frame % 50 === 0){
starsArray.push(new Star());
}
for (let i = 0; i < starsArray.length; i++) {
starsArray[i].update();
starsArray[i].draw();
}
//to not have too many stars for performance
if (starsArray.length > 300) {
starsArray.pop(starsArray[0])
}
}