xxxxxxxxxx
71
let x = [];
let y = [];
let fourierX;
let fourierY;
let time = 0;
let path = [];
function setup() {
createCanvas(600, 400);
let angle;
for (let i = 0; i < 500; i++) {
x[i] = 200 * noise(i / 50);
y[i] = 200 * noise(i / 50 + 1000);
}
fourierX = dft(x);
fourierY = dft(y);
fourierX.sort((a, b) => b.amp - a.amp);
fourierY.sort((a, b) => b.amp - a.amp);
}
function epiCycles(x, y, rotation, fourier) {
for (let i = 0; i < fourier.length; i++) {
let prevx = x;
let prevy = y;
let freq = fourier[i].freq;
let radius = fourier[i].amp;
let phase = fourier[i].phase;
x += radius * cos(freq * time + phase + rotation);
y += radius * sin(freq * time + phase + rotation);
stroke(255, 100);
noFill();
ellipse(prevx, prevy, radius * 2);
stroke(255);
line(prevx, prevy, x, y);
}
return createVector(x, y);
}
function draw() {
background(0);
let vx = epiCycles(300, 50, 0, fourierX);
let vy = epiCycles(50, 200, HALF_PI, fourierY);
let v = createVector(vx.x, vy.y);
path.unshift(v);
line(vx.x, vx.y, v.x, v.y);
line(vy.x, vy.y, v.x, v.y);
beginShape();
noFill();
for (let i = 0; i < path.length; i++) {
vertex(path[i].x, path[i].y);
}
endShape();
const dt = TWO_PI / fourierY.length;
time += dt;
if (time > TWO_PI) {
time = 0;
path = [];
}
// if (wave.length > 250) {
// wave.pop();
// }
}