Skip to content

Commit 98f76e5

Browse files
James WitteJames Witte
authored andcommitted
separated shapes from canvas
1 parent e8b6c12 commit 98f76e5

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

js/secrets.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
// We're making 20 flowers
1+
// We're making 40 flowers
22
// each is made of 240 pretty points
3+
var colors = [
4+
'tomato',
5+
'lightsalmon',
6+
'plum',
7+
'mediumslateblue'
8+
];
9+
310
var resolution = 240;
411
var radius = 200;
5-
var two;
6-
7-
for (var k = 2, i = 0; k < 41; k++) {
8-
$('body').append('<div class="canvas" id="twocanvas' + i + '"></div>');
9-
// Setup the canvas
10-
var two = new Two({
11-
autostart: true
12-
}).appendTo(document.getElementById('twocanvas' + i));
13-
i++;
14-
12+
var shapes = [];
13+
// Make the flowers
14+
for (var k = 2; k < 44; k++) {
1515
var points = [];
1616
for (var j = 0; j < resolution; j++) {
1717
points[j] = new Two.Anchor();
1818
roseMath(points[j], k, Math.PI * 2 * j / resolution);
1919
}
2020
// Create shape
21-
var shape = two.makeCurve(points);
22-
// Center Shape to div
23-
two.scene.translation.set(two.width / 2, two.height / 2);
21+
var shape = new Two.Path(points, true, true);
22+
2423
// Style the shape
25-
shape.fill = 'rgb(0, 0, 0)';
26-
shape.stroke = 'rgb(255, 255, 255)';
27-
shape.linewidth = 6;
28-
two.update();
24+
var color = colors[Math.floor(Math.random() * colors.length)];
25+
shape.stroke = color;
26+
shape.noFill();
27+
shape.rotation = Math.floor(Math.random() * 4) * Math.PI / 2 + Math.PI / 4;
28+
shapes.push(shape);
2929
}
30+
// two.add(group)
3031

3132
function roseMath(v, k, t) {
3233
v.x = radius * Math.cos(k * t) * Math.cos(t);

0 commit comments

Comments
 (0)