fractalkitty looking for math? fractalkitty.com

all

inKleined to dance

#trig#3d#animation#math#topology#parametric

I got side-tracked in klien bottles while deciding what to doodle - this is the result.

inKlein

a = 130;
uLim = 8;
vLim = 7;
function setup() {
  createCanvas(windowWidth, windowHeight, WEBGL);
  angleMode(DEGREES);
  noStroke();
}
function draw() {
  t = frameCount / 2;
  specularMaterial(255);
  pointLight(
    225 * abs(cos(t / 4)),
    245 * abs(cos(t / 4)),
    255 * abs(cos(t / 4)),
    -2000,
    -2000,
    -2000
  );
  background(
    205 * abs(sin(t / 4)),
    245 * abs(sin(t / 4)),
    255 * abs(sin(t / 4))
  );
  inKlein(1);
  inKlein(0.5);
  inKlein(0.2);
}
function inKlein(s) {
  rotateY(t);
  rotateZ(90 + t);
  rotateX(t);
  for (let j = 0; j < 360; j += vLim) {
    for (let i = 0; i < 360; i += uLim) {
      push();
      scale(s, s, s);

      u = i + 360 * sin(t / 4);
      v = j;
      x = (2 + cos(v / 2) * sin(u) - sin(v / 2) * sin(2 * u)) * cos(v);
      y =
        (2 + cos(v / 2 + 60 * sin(t)) * sin(u) - sin(v / 2) * sin(2 * u)) *
        sin(v);
      z = sin(v / 2) * sin(u) + cos(v / 2) * sin(2 * u);
      translate(
        a * x + tan(90 + t / 100),
        a * y + tan(90 + t / 100),
        a * z + tan(90 + t / 100)
      );
      sphere(5 + 3 * cos(t));
      pop();
    }
  }
}