shapeData = {
refreshButton;
let { n, octave, shape } = optionForm;
let noiseGen = new simplexNoise(performance.now());
let scaleTheta = d3
.scaleLinear()
.domain([0, n])
.range([0, 2 * Math.PI]),
data = [];
let theta,
dtheta = scaleTheta(1),
r;
if (shape === "ellipse") {
let p = 1,
e = 0.5;
let dist = (x, y) => {
return Math.sqrt(x * x + y * y);
};
for (let i = 0; i < n; ++i) {
theta = scaleTheta(i);
r = p / (1 + e * Math.cos(theta));
data.push({ r, theta, dtheta });
}
}
if (shape == "glass") {
let a = 3,
b = 1;
let dist = (x, y) => {
return x * x + y * y;
};
for (let i = 0; i < n; ++i) {
theta = scaleTheta(i);
r = dist(a * Math.cos(theta), b * Math.sin(theta));
data.push({ r, theta, dtheta });
}
}
if (shape === "heart") {
let a = 3,
b = 1,
c = Math.sqrt(a * a - b * b);
let dist = (x, y) => {
return Math.sqrt(x * x + y * y);
};
for (let i = 0; i < n; ++i) {
theta = scaleTheta(i);
r = dist(a * Math.cos(theta) + c, b * Math.sin(theta));
r = 1 - Math.cos(theta);
data.push({ r, theta, dtheta });
}
}
if (shape === "random") {
for (let i = 0; i < n; ++i) {
theta = scaleTheta(i);
r = noiseGen.noise2D(0.5, (i / n) * octave);
data.push({ r, theta, dtheta });
}
let scale = d3
.scaleLinear()
.domain([0, n])
.range([data[0].r, data[n - 1].r]);
data.map((d, i) => {
r = d.r - scale(i) + 2;
Object.assign(d, { r });
});
}
let v,
distance = 0;
data.map((d, i) => {
v = d.r * d.dtheta;
Object.assign(d, { v, distance });
distance += v;
});
return data;
}