-
Notifications
You must be signed in to change notification settings - Fork 407
/
Copy pathBathUniversityParticles.html
60 lines (42 loc) · 982 Bytes
/
BathUniversityParticles.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 lang="en">
<meta charset="utf-8">
<head>
<title> Particles!</title>
<style type="text/css">
body {
background-color:black;
margin:0px;
overflow : hidden;
}
</style>
</head>
<body>
<script>
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var particles = [];
setInterval(draw, 16);
function draw() {
ctx.clearRect(0,0,canvas.width, canvas.height);
var p = {x : canvas.width/2,
y : canvas.height/2,
xSpeed : Math.random() * 10 - 5,
ySpeed : Math.random() * 10 - 5,
colour : 'hsl('+Math.random()*360+', 100%, 50%)'
}
particles.push(p);
for(var i = 0; i<particles.length; i++) {
p = particles[i];
ctx.fillStyle = p.colour;
ctx.fillRect(p.x,p.y,10,10);
p.x = p.x+p.xSpeed;
p.y = p.y+p.ySpeed;
}
}
</script>
</body>
</html>