-
Notifications
You must be signed in to change notification settings - Fork 1
/
animation.js
32 lines (26 loc) · 889 Bytes
/
animation.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
import { Void } from 'void'
export default function () {
// Get the canvas's dimensions and setup some variables.
let { width, height } = Void.settings()
let y = 0
// Define a `speed` trait that will control how fact our line moves.
let speed = Void.int('speed', 1, 11)
// Create a layer to draw on, and fill it with black.
let context = Void.layer()
context.fillStyle = 'black'
context.fillRect(0, 0, width, height)
// On each frame…
Void.draw(() => {
// Fade the previous frame slightly more towards black.
context.fillStyle = 'rgba(0, 0, 0, 0.25)'
context.fillRect(0, 0, width, height)
// Draw a new horizontal line.
context.strokeStyle = 'gray'
context.beginPath()
context.moveTo(0, y)
context.lineTo(width, y)
context.stroke()
// Move downward, and wrap back to the top.
y = y >= height ? 0 : y + speed
})
}