xxxxxxxxxx
/*
* Author: Juan Carlos Ponce Campuzano
* Date: 28/May/2024
* Site: https://www.dynamicmath.xyz
* Video: https://youtu.be/vqGeaY188Ew
*/
let t = 0, speed = 0.004;
function setup() {
createCanvas(500, 500);
colorMode(HSB, 1, 1, 1);
}
function draw() {
background(0);
for (let j = 1; j <= 10; j++) {
let hue = map(j, 1, 10, 0, 1)
stroke(hue, 1, 1);
hexagonalCurve(50, 2.5, 3, j, j * t, PI + j * t);
}
t += speed;
if(t >= TWO_PI) t = 0;
}
/*
Hexagonal curve
Defined on the interval [startT, endT]
Main parameters: n, k, m
*/
function hexagonalCurve(n, k, m, size, startT, endT) {
noFill();
strokeWeight(4);
let view = 12;
let x, y;
beginShape();
for (let i = startT; i <= endT; i += 0.01) {
let v = pow(
pow(cos((m * i) / 2), n) + pow(sin((m * i) / 2), n),
1 / (k * n)
);
x = map(cos(i) * (size / v), -view, view, 0, width);
y = map(sin(i) * (size / v), -view, view, height, 0);
vertex(x, y);
}
endShape();
}