fractalkitty looking for math? fractalkitty.com

weekly creative coding

Ancient Is

#random#interactive#poem#sky#space#wcc

Haiku pairings are here:

nebulastarscluster

function setup() {
  cnv = createCanvas((c = 0.9 * min(windowWidth, windowHeight)), c);
  noStroke();
  noLoop();
  background(0);
}
function draw() {
  push();
  translate(c / 2, c / 2);
  sc = random(0.3, 1);
  scale(sc, sc);//variety of zoom
  rotate(random(-PI, PI));//variety in angle
  nebula(random(10, 255), random(10, 255), random(10, 255), 3, 6);//dominant color
  stars();//dots in the sky
  nebula(200, 200, 200, 7, 205);//not a nebula
  nebula(0, 200, 250, 22, 205);//not a nebula
  nebula(250, 100, 250, 25, 205);//not a nebula
  for (let i = 0; i < floor(random(0, 3.1)); i++) {
    cluster();//not a cluster, but is a cluster
  }
  g = max(10, c / 12);
  for (let i = 0; i < int(random(5, g)); i++) {
    push();
    translate((c / 3) * randomGaussian(), (c / 3) * randomGaussian());
    scale(random(0.5, 1), random(0.5, 1));
    rotate(random(-PI / 4, PI / 4));
    nebula(random(100, 255), random(100, 255), random(100, 255), 15, 100);//not a nebula
    pop();
  }
  pop();
}
function nebula(r1, b1, g1, s, a) {//s is a scaling factor for each not a nebula
  a = a + c / 2000;//because "a" is super descriptive for alpha factor
  n = 8300 + int(c / 3);//change n based on screen size
  p = c / 1500;
  cr = 20;//jiggle in color
  for (let i = 0; i < n; i++) {
    fill(
      r1 + random(cr),
      g1 + random(cr),
      b1 + random(cr),
      abs(randomGaussian()) / 4
    );
    circle(
      -c / 2 + (c / 2) * randomGaussian(),
      (c * randomGaussian()) / s,
      randomGaussian(c / 100, c / s + c / 40)
    );
    fill(255, 255, 255, (a * randomGaussian()) / 2);
    circle(
      -c / 2 + (c / 2) * randomGaussian(),
      (c * randomGaussian()) / s,
      p * randomGaussian()
    );
  }
}

function stars() {
  n = c * 4;
  for (let i = 0; i < n; i++) {
    fill(255, 255, 255, abs(255 * randomGaussian()));
    circle(
      -c / 2 + (c / 2) * randomGaussian(),
      c *
        randomGaussian() *
        randomGaussian() *
        randomGaussian() *
        randomGaussian(),
      0.5 * randomGaussian()
    );
  }
}

function mousePressed() {
  background(0, 0, 0, 200);
  draw();
}

function keyPressed() {
  if (keyCode === 83) {
    save(cnv, "Ancient is", "png");
  }
}

function cluster() {
  push();
  translate(random(-c / 2, c / 2), random(-c / 10, c / 10));
  nebula(random(100, 255), random(100, 255), random(100, 255), 29, 100);
  scale(0.05, 0.05);
  nebula(random(100, 255), random(100, 255), random(100, 255), 10, 2);
  nebula(255, 255, 255, 2, 2);
  stars();
  pop();
}

function windowResized() {
  setup();
  draw();
}