add clover shape

This commit is contained in:
yuanchuan 2017-05-28 16:40:32 +08:00
parent 439811564c
commit 343ab111e8
1 changed files with 22 additions and 0 deletions

View File

@ -72,3 +72,25 @@ export const hypocycloid = memo('hypocycloid', function(k = 3) {
export function astroid() {
return hypocycloid(4);
}
export const clover = memo('clover', function(k = 3) {
switch (k) {
case 4: k = 2; break;
case 5: k = 5; break;
case 3: k = 3;
default: {
if (k > 5) k = 5;
else if (k < 3) k = 3;
}
}
var split = 240;
var deg = Math.PI / (split / 2);
var points = [];
for (var i = 0; i < split; ++i) {
var theta = deg * i;
var x = Math.cos(k * theta) * Math.cos(theta);
var y = Math.cos(k * theta) * Math.sin(theta);
points.push((x * 50 + 50 + '% ') + (y * 50 + 50+ '%'));
}
return `polygon(${ points.join(',') })`;
});