This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snow.html
60 lines (57 loc) · 1.8 KB
/
snow.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Snow</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<style>
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: #000;
}
</style>
<canvas id="view" height="600" width="800"></canvas>
<script>
let newSnow = () => {
let _ = {}
_.x = Math.random() * mx;
_.y = 0;
_.v = Math.random() * mv + 5;
return _
}
let view = document.getElementById('view')
let ctx = view.getContext('2d')
let mx = 800
let my = 600
let mv = 50
let ms = 256
let t = new Date().getTime() / 60
let ot = t
let dt = 0
let snow = []
let draw = () => {
ctx.clearRect(0, 0, view.width, view.height);
ctx.fillStyle = 'white'
if(snow.length < ms) {
snow.push(newSnow())
}
for(i = 0; i < snow.length; i++) {
ctx.fillRect(snow[i].x, snow[i].y, 1, +2)
snow[i].y = snow[i].y + snow[i].v * dt
}
ot = t
t = new Date().getTime() / 60
dt = t - ot
snow = snow.filter((x) => x.y < my)
requestAnimationFrame(draw)
}
requestAnimationFrame(draw)
</script>
</body>
</html>