-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (77 loc) · 2.63 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Paralax</title>
<link rel="stylesheet" href="style.css">
<script src="lib/paper/dist/paper-full.min.js" type="text/javascript"></script>
<script type="text/paperscript" canvas="myCanvas">
var count = 150;
// Create a symbol, which we will use to place instances of later:
var path = new Path.Circle({
center: [0, 0],
radius: 10,
fillColor: 'white',
strokeColor: 'black'
});
var symbol = new Symbol(path);
// Place the instances of the symbol:
for (var i = 0; i < count; i++) {
// The center position is a random point in the view:
var center = Point.random() * view.size;
var placedSymbol = symbol.place(center);
placedSymbol.scale(i / count);
}
var lSpeed = 0;
var rSpeed = 0;
var uSpeed = 0;
var dSpeed = 0;
function onKeyDown(e) {
var l = (e.key === 'a');
var r = (e.key === 'd');
var u = (e.key === 'w');
var d = (e.key === 's');
lSpeed += l;
rSpeed += r;
uSpeed += u;
dSpeed += d;
}
function onFrame(e) {
lSpeed -= .1;
rSpeed -= .1;
uSpeed -= .1;
dSpeed -= .1;
lSpeed = Math.max(lSpeed, 0);
rSpeed = Math.max(rSpeed, 0);
uSpeed = Math.max(uSpeed, 0);
dSpeed = Math.max(dSpeed, 0);
for (var i = 0; i < count; i++) {
var item = project.activeLayer.children[i];
// Move the item 1/20th of its width to the right. This way
// larger circles move faster than smaller circles:
item.position.x += lSpeed*(item.bounds.width / 20) - rSpeed*(item.bounds.width / 20);
item.position.y += uSpeed*(item.bounds.width / 20) - dSpeed*(item.bounds.width / 20);
// If the item has left the view on the right, move it back
// to the left:
if (item.bounds.left > view.size.width) {
item.position.x = 0;
}
if (item.bounds.right < 0) {
item.position.x = view.size.width - item.bounds.width;
}
if (item.bounds.top > view.size.height) {
item.position.y = 0;
}
if (item.bounds.bottom < 0) {
item.position.y = view.size.height - item.bounds.height;
}
}
}
</script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>