-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
76 lines (67 loc) · 2.34 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Paper.js - Playground</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="examples/css/style.css">
<script type="text/javascript" src="dist/paper-full.js"></script>
<script type="text/paperscript" canvas="canvas">
var layer = project.activeLayer;
var values = {
count: 90,
points: 45
};
var colorArray = [];
// Generates a random hex color
function getRandomColor() {
return '#'+(Math.random()*0xFFFFFF<<0).toString(16);
}
var colorTable = [];
for (var i = 0; i < values.count; i++) {
colorTable.push("rgb(0, " + (255 - i * 6) + ", " + (255 - i * 2) + ")");
}
// Fills the colorArray with random hex colors
for (var i = 0; i < values.count; i++) {
colorArray.push(getRandomColor());
}
// Creation of the Shapes
for (var i = 0; i < values.count; i++) {
var path = new Path({
fillColor: colorTable[i],
strokeColor: 'black',
closed: true
});
var offset = new Point(10 * i, 0);
var l = offset.length;
for (var j = 0; j < values.points * 2; j++) {
offset.angle += 360 / values.points;
var vector = offset.normalize(l * (j % 2 ? 0.1 : -0.1));
path.add(offset + vector);
}
path.smooth({ type: 'continuous' });
layer.insertChild(0, new Group({
children: [path],
applyMatrix: false
}));
}
function onFrame(event) {
for (var i = 0; i < values.count; i++) {
var item = layer.children[i];
var angle = (values.count - i) * Math.sin(event.count / 128) / 10;
item.rotate(angle);
}
}
// Reposition the paths whenever the window is resized:
function onResize(event) {
layer.position = view.center;
}
</script>
</head>
<body>
<canvas id="canvas" resize stats hidpi="off"></canvas>
</body>
</html>