Polar Plots
const Pnt = (x, y, p = { x, y }) => (
p.add = o => (p.x += o.x, p.y += o.y, p), p
);
Pnt.polar = (rad, t) => Pnt(rad * Math.cos(t), rad * Math.sin(t));
const pnts = {};
let index = -1;
const polar = (inc, rad) => {
index++;
if (!pnts[index]) pnts[index] = 0;
return Pnt.polar(rad, (pnts[index] += inc));
};
let d = document;
let b = d.body;
with (b.appendChild(
Object.assign(d.createElement`canvas`, {
width: 600,
height: 500,
})
).getContext`2d`) {
canvas.style.transformOrigin = "0 0";
canvas.style.transform = "scale(.6)";
let p0 = Pnt(80, 100);
let p1 = Pnt(270, 100);
let p2 = Pnt(480, 40);
let p3 = Pnt(170, 180);
let p4 = Pnt(430, 300);
fillStyle = "black";
function loop() {
for (let i = 0; i < 20; i++) {
index = -1;
p0.add(polar(0.2, 4).add(polar(-0.4, 2).add(polar(0.05, 1))));
fillRect(p0.x, p0.y, 1, 1);
p1.add(
polar(0.1, 2).add(
polar(-0.2, 2).add(polar(0.03, 1).add(polar(-0.01, 0.5)))
)
);
fillRect(p1.x, p1.y, 1, 1);
p2.add(polar(0.08, 3).add(polar(-0.2, -12).add(polar(2, 10))));
fillRect(p2.x, p2.y, 1, 1);
p3.add(polar(0.08, 7).add(polar(-0.2, -12).add(polar(2, 11))));
fillRect(p3.x, p3.y, 1, 1);
p4 = p4.add(polar(0.025, 2).add(polar(-0.05, 1)));
fillRect(p4.x, p4.y, 1, 1);
}
requestAnimationFrame(loop);
}
loop();
}
Some polar plots…