Creative coding starry heavens that make you feel dizzy

An animation of glistening Archimedes' spiral.


 

Description of an animation of glistening Archimedes' spiral.

It a creative coding animation made with the 'Processing'.

I was interested in the Archimedes' spiral recently. I made this spiral glistening. And I think the key to this code is here.


float brushAlp = pow(log(brushBri + 1.0) / logBriMax, 2.0) * 100.0;  // to shine glaringly

I inspired by the great article written by GenerateMe.

(WIP) Smooth rendering - log density mapping
https://generateme.wordpress.com/2018/10/24/smooth-rendering-log-density-mapping/

This code does not display any images on screen but generates image files for animation. You can make an animation with these files.







 

The 'Processing' code example.

Please feel free to use this example code under the terms of the GPL.
To see other works based on my code is my pleasure. And my honor.

// Stargazer.
// @author @deconbatch
// @version 0.1
// Processing 3.2.1
// 2019.01.25


void setup() {

  size(720, 720);
  colorMode(HSB, 360.0, 100.0, 100.0, 100.0);
  blendMode(ADD);
  smooth();
  noStroke();
  noLoop();

}

void draw() {

  int   frameCntMax = 24 * 6;
  int   pointCntMax = 85000;
  int   sizeCntMax  = 3;
  float spiralGap   = 4.0;
  float baseHue     = random(360.0);
  float briMax      = 80.0;
  float logBriMax   = log(briMax + 1.0);

  float npHueIni = random(100.0);
  float npSatIni = random(100.0);
  float npBriIni = random(100.0);
  float npSizIni = random(100.0);
  
  translate(width / 2, height / 2);

  for (int frameCnt = 0; frameCnt < frameCntMax; ++frameCnt) {

    float frameRatio = map(frameCnt, 0, frameCntMax, 0.0, 1.0);
    float easeRatio  = easeInOutCubic(frameRatio);

    float npHue = npHueIni;
    float npSat = npSatIni;
    float npBri = npBriIni;
    float npSiz = npSizIni;

    background(baseHue, 100.0, 10.0, 100.0);

    for (int pointCnt = 0; pointCnt < pointCntMax; ++pointCnt) {

      float divRotate = sqrt(pointCnt) * 15.0;
      float radian = TWO_PI / divRotate  * pointCnt;
      float pX = spiralGap * radian * cos(radian);
      float pY = spiralGap * radian * sin(radian);

      float brushHue = (baseHue + map(sin(TWO_PI * (frameRatio + noise(npHue) * 2.0)), -1.0, 1.0, 0.0, 60)) % 360;
      float brushSat = map(sin(TWO_PI * (frameRatio + noise(npSat) * 2.0)), -1.0, 1.0, 20.0, 60.0);

      for (int sizeCnt = 1; sizeCnt <= sizeCntMax; ++sizeCnt) {

        float brushBri = map(sin(TWO_PI * (easeRatio + noise(npBri) * 2.0)), -1.0, 1.0, 0.0, briMax) / sizeCnt / sizeCnt;
        float brushAlp = pow(log(brushBri + 1.0) / logBriMax, 2.0) * 100.0;  // to shine glaringly
        float brushSiz = map(sin(TWO_PI * (frameRatio + noise(npSiz) * 1.0)), -1.0, 1.0, 0.0, 1.0 * sizeCnt * sizeCnt);

        fill(brushHue, brushSat, brushBri, brushAlp);
        ellipse(pX, pY, brushSiz, brushSiz);

      }

      npHue += 0.03;
      npSat += 0.01;
      npBri += 0.03;
      npSiz += 0.05;

    }

    saveFrame("frames/" + String.format("%04d", frameCnt) + ".png");

  }

  exit();

}

/**
 * easeInOutCubic easing function.
 * @param  t     0.0 - 1.0 : linear value.
 * @return float 0.0 - 1.0 : eased value.
 */
float easeInOutCubic(float t) {
  t *= 2.0;
  if (t < 1.0) {
    return pow(t, 3) / 2.0;
  }
  t -= 2.0;
  return (pow(t, 3) + 2.0) / 2.0;
}

/*
Copyright (C) 2019- deconbatch

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/


 

Yet another example image.


An animation of glistening Archimedes' spiral.

 

Next Post Previous Post
No Comment
Add Comment
comment url