-
Notifications
You must be signed in to change notification settings - Fork 0
/
Background.js
41 lines (35 loc) · 948 Bytes
/
Background.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
import {c, canvas} from "./index.js"
export class Background {
constructor() {
this.positions = []
this.density = 1
this.velocity = 2
this.radius = 0.8
}
animate() {
this.positions.forEach((position, index, array) => {
position.y += this.velocity
if (position.y >= canvas.height){
this.positions.splice(index, 1)
}
})
for (let i = 0; i <= this.density; i++) {
const position = {
x: Math.randomInterval(0, canvas.width),
y: 0
}
this.positions.push(position)
}
this.draw()
}
draw () {
this.positions.forEach(position => {
c.beginPath()
c.arc(position.x, position.y, this.radius, 0, Math.PI * 2)
c.fillStyle = 'white'
c.fill()
})
}
static createStar() {
}
}