xxxxxxxxxx
80
//I know som of this stuff is standard
//but I like to implement it for practice
class Vec2 {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
function posVec(v) {
return new Vec2(v.x + width / 2, -v.y + height / 2);
}
function polarToCart(v) {
return new Vec2(v.x * cos(v.y), v.x * sin(v.y));
}
function smoothstep(edge0, edge1, x) {
// Scale, bias and saturate x to 0..1 range
x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
// Evaluate polynomial
return x * x * (3 - 2 * x);
}
function clamp(x, lowerlimit, upperlimit) {
if (x < lowerlimit)
x = lowerlimit;
if (x > upperlimit)
x = upperlimit;
return x;
}
function pcircle(v, diameter) {
let w = posVec(v);
circle(w.x, w.y, diameter);
}
function setup() {
//noLoop();
createCanvas(400, 400);
}
let theta = 0;
function draw() {
background(25);
maxHeight = (sin(theta) * 40) + 60;
colorMode(HSB, 2 * PI, 100, 100);
fill(abs(cos(theta)) * (2*PI), 80, 80);
stroke(abs(cos(theta)) * PI, 80, 80);
let hCol = [];
for (let i = 0; i < 50; i++) {
hCol.push((smoothstep(0, 50, i) * maxHeight) + 50);
}
let n = 0;
let outerStep = ((2 * PI) / 10);
for (let i = theta; i < theta + (2 * PI); i += outerStep) {
let innerStep = outerStep / 50.0;
let even = (n % 2 == 0);
let h = even ? (maxHeight + 50) : 50;
let inneri = i;
if (even) {
for (let j = 49; j >= 0; j--) {
pcircle(polarToCart(new Vec2(hCol[j], inneri += innerStep)), 3);
}
} else {
for (let j = 0; j < 50; j++) {
pcircle(polarToCart(new Vec2(hCol[j], inneri += innerStep)), 3);
}
}
pcircle(polarToCart(new Vec2(h, i)), 10);
n++;
}
theta -= 0.01;
}