Skip to content

Commit 59179f3

Browse files
committed
cleaned up secrets.js
1 parent 5523677 commit 59179f3

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

js/secrets.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,11 @@ var two = new Two({
44
autostart: true
55
}).appendTo(document.body);;
66

7-
var background = two.makeRectangle(two.width / 2, two.height / 2,
8-
two.width, two.height);
9-
background.noStroke();
10-
background.fill = 'black';
11-
background.name = 'background';
12-
13-
var container = two.makeGroup(background);
147
var rows = Math.floor(two.height / 100);
158
var cols = Math.floor(two.width / 100);
169
var radius = Math.floor(Math.max(two.width, two.height) / Math.max(rows, cols)) / 2;
17-
18-
var resolution = 240;
19-
var shapes = [];
20-
// We're making 40 flowers
21-
// each is made of 240 pretty points
22-
var colors = ['tomato', 'lightsalmon', 'floralwhite', 'orangered',
23-
'gold', 'red', 'darkorange'];
24-
// Make the flowers
25-
for (var k = 4; k < 20; k++) {
26-
var points = [];
27-
for (var j = 0; j < resolution; j++) {
28-
points[j] = new Two.Anchor();
29-
roseMath(points[j], k, Math.PI * 2 * j / resolution);
30-
}
31-
// Create shape
32-
var shape = new Two.Path(points, true, true);
33-
// shape.step = (Math.floor(Math.random() * 8) / 8) * Math.PI / 60;
34-
// shape.step *= Math.random() > 0.5 ? - 1 : 1;
35-
36-
shapes.push(shape);
37-
}
38-
10+
var shapes = makeFlowers();
11+
var container = two.makeGroup(getBackground());
3912
for (var r = 0; r < rows; r++) {
4013
// even rows have an offset of 0.5
4114
var even = !!(r % 2);
@@ -50,24 +23,59 @@ for (var r = 0; r < rows; r++) {
5023
}
5124
}
5225
var hi = k /(cols - 1);
53-
var s = Math.floor(Math.random() * shapes.length);
54-
var shape = shapes[s].clone();
55-
// Style the shape
56-
var color = colors[Math.floor(Math.random() * colors.length)];
57-
shape.stroke = color;
58-
shape.fill = color;
59-
shape.linewidth = 4;
60-
shape.cap = 'round';
61-
shape.rotation = Math.floor(Math.random() * 4) * Math.PI / 2 + Math.PI / 4;
26+
var shape = pickFlower();
6227
shape.translation.set(hi * two.width, vi * two.height);
6328
container.add(shape);
6429
}
6530
}
6631

6732
two.update();
6833

34+
function getBackground() {
35+
var background = two.makeRectangle(two.width / 2, two.height / 2,
36+
two.width, two.height);
37+
background.noStroke();
38+
background.fill = 'black';
39+
background.name = 'background';
40+
return background
41+
}
42+
6943
function roseMath(v, k, t) {
7044
v.x = radius * Math.cos(k * t) * Math.cos(t);
7145
v.y = radius * Math.cos(k * t) * Math.sin(t);
7246
return v;
7347
}
48+
49+
function makeFlowers() {
50+
var shapes = [];
51+
var resolution = 240; // every flower has 240 points
52+
for (var k = 4; k < 20; k++) {
53+
var points = [];
54+
for (var j = 0; j < resolution; j++) {
55+
points[j] = new Two.Anchor();
56+
roseMath(points[j], k, Math.PI * 2 * j / resolution);
57+
}
58+
// Create shape
59+
var shape = new Two.Path(points, true, true);
60+
shapes.push(shape);
61+
}
62+
return shapes;
63+
}
64+
65+
function pickFlower() {
66+
var s = Math.floor(Math.random() * shapes.length);
67+
var shape = shapes[s].clone();
68+
// Style the shape
69+
var colors = ['tomato', 'lightsalmon', 'floralwhite', 'orangered',
70+
'gold', 'red', 'darkorange'];
71+
var color = colors[Math.floor(Math.random() * colors.length)];
72+
shape.stroke = color;
73+
shape.fill = color;
74+
shape.linewidth = 4;
75+
shape.cap = 'round';
76+
shape.rotation = Math.floor(Math.random() * 4) * Math.PI / 2 + Math.PI / 4;
77+
// For animation later on
78+
shape.step = (Math.floor(Math.random() * 8) / 8) * Math.PI / 60;
79+
shape.step *= Math.random() > 0.5 ? - 1 : 1;
80+
return shape;
81+
}

0 commit comments

Comments
 (0)