Skip to content

Commit bf16633

Browse files
committed
basic polar coordinate two js shapes made very rough
1 parent 6e047d3 commit bf16633

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

js/secrets.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// We're making 20 flowers
2+
// each is made of 240 pretty points
3+
var resolution = 240;
4+
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+
15+
var points = [];
16+
for (var j = 0; j < resolution; j++) {
17+
points[j] = new Two.Anchor();
18+
roseMath(points[j], k, Math.PI * 2 * j / resolution);
19+
}
20+
// Create shape
21+
var shape = two.makeCurve(points);
22+
// Center Shape to div
23+
two.scene.translation.set(two.width / 2, two.height / 2);
24+
// Style the shape
25+
shape.fill = 'rgb(0, 0, 0)';
26+
shape.stroke = 'rgb(255, 255, 255)';
27+
shape.linewidth = 6;
28+
two.update();
29+
}
30+
31+
function roseMath(v, k, t) {
32+
v.x = radius * Math.cos(k * t) * Math.cos(t);
33+
v.y = radius * Math.cos(k * t) * Math.sin(t);
34+
return v;
35+
}

0 commit comments

Comments
 (0)