1 | <!DOCTYPE html>
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <meta charset="UTF-8">
|
---|
5 | <title>Space</title>
|
---|
6 | <link rel="stylesheet" href="../css/style.css">
|
---|
7 | <script type="text/javascript" src="../../dist/paper.js"></script>
|
---|
8 | <script type="text/paperscript" canvas="canvas">
|
---|
9 | // The amount of symbol we want to place;
|
---|
10 | var count = 150;
|
---|
11 |
|
---|
12 | // Create a symbol, which we will use to place instances of later:
|
---|
13 | var path = new Path.Circle(new Point(0, 0), 5);
|
---|
14 | path.style = {
|
---|
15 | fillColor: 'white',
|
---|
16 | strokeColor: 'black'
|
---|
17 | };
|
---|
18 |
|
---|
19 | var symbol = new Symbol(path);
|
---|
20 |
|
---|
21 | // Place the instances of the symbol:
|
---|
22 | for (var i = 0; i < count; i++) {
|
---|
23 | // The center position is a random point in the view:
|
---|
24 | var center = Point.random() * view.size;
|
---|
25 | var placed = symbol.place(center);
|
---|
26 | placed.scale(i / count);
|
---|
27 | placed.data = {};
|
---|
28 | placed.data.vector = new Point({
|
---|
29 | angle: Math.random() * 360,
|
---|
30 | length : (i / count) * Math.random() / 5
|
---|
31 | });
|
---|
32 | }
|
---|
33 |
|
---|
34 | var vector = new Point({
|
---|
35 | angle: 45,
|
---|
36 | length: 0
|
---|
37 | });
|
---|
38 |
|
---|
39 | var mouseVector = vector.clone();
|
---|
40 |
|
---|
41 | function onMouseMove(event) {
|
---|
42 | mouseVector = view.center - event.point;
|
---|
43 | }
|
---|
44 |
|
---|
45 | // The onFrame function is called up to 60 times a second:
|
---|
46 | function onFrame(event) {
|
---|
47 | vector = vector + (mouseVector - vector) / 30;
|
---|
48 |
|
---|
49 | // Run through the active layer's children list and change
|
---|
50 | // the position of the placed symbols:
|
---|
51 | for (var i = 0; i < count; i++) {
|
---|
52 | var item = project.activeLayer.children[i];
|
---|
53 | var size = item.bounds.size;
|
---|
54 | var length = vector.length / 10 * size.width / 10;
|
---|
55 | item.position += vector.normalize(length) + item.data.vector;
|
---|
56 | keepInView(item);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | function keepInView(item) {
|
---|
61 | var position = item.position;
|
---|
62 | var itemBounds = item.bounds;
|
---|
63 | var bounds = view.bounds;
|
---|
64 | if (itemBounds.left > bounds.width) {
|
---|
65 | position.x = -item.bounds.width;
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (position.x < -itemBounds.width) {
|
---|
69 | position.x = bounds.width + itemBounds.width;
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (itemBounds.top > view.size.height) {
|
---|
73 | position.y = -itemBounds.height;
|
---|
74 | }
|
---|
75 |
|
---|
76 | if (position.y < -itemBounds.height) {
|
---|
77 | position.y = bounds.height + itemBounds.height / 2;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | </script>
|
---|
81 | </head>
|
---|
82 | <body>
|
---|
83 | <canvas id="canvas" resize hidpi="off" style="background:black"></canvas>
|
---|
84 | </body>
|
---|
85 | </html> |
---|