Star Cycle.


It's not an electric shaver nor a vibrissa trimmer.

It's a creative coding animation made with Processing.

I interested in cyclic motion. Many particles move the individual path and they make interesting shapes at some point in time.

My blog article about cyclic motion in Japanese.

Example code. (Processing on Java)

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

Please feel free to use this example code, if you like it.
To see other works based on my code is my pleasure. And my honor.


// Star Cycle.
// @deconbatch
// Processing 3.2.1
// 2018.06.16

void setup() {

  size(720, 720);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(SCREEN);
  smooth();
  noLoop();
  noStroke();

}

void draw() {

  translate(width / 2, height / 2);

  int   frames         = 0;
  int   spotCntMax     = 300;
  int   tailCntMax     = 50;
  int   spotsPerRadius = floor(random(2.0, 5.9));
  int   swirlCnt       = floor(random(3.0, 6.9));
  float addRadiusX     = random(30.0, 100.0);
  float addRadiusY     = random(30.0, 100.0);
  float waveRadiusX    = random(1.0, 4.0);
  float waveRadiusY    = random(1.0, 4.0);
  float stepStart      = random(12.0);
  float stepEnd        = stepStart + 1.0;
  float stepDiv        = 0.01;
  float hueBase        = random(360.0);

  for (float step = stepStart; step < stepEnd; step += stepDiv) {

    background(0, 0, 0, 100);
    for (int spotCnt = 0; spotCnt < spotCntMax; ++spotCnt) {

      // put spotsPerRadius number spots in same radius
      float start    = (1.0 / spotsPerRadius) * (spotCnt % spotsPerRadius);
      float radius   = map(floor(spotCnt / spotsPerRadius), 0, floor(spotCntMax / spotsPerRadius), 5.0, width / 2.0);
      float speed    = map(radius, 5, width/2.0, 3.0, -1.0);
      float spotRate = map(spotCnt, 0, spotCntMax, 0.0, 1.0);

      for (int tailCnt = 0; tailCnt < tailCntMax; ++tailCnt) {

        float tailStep = step - stepDiv * tailCnt / 10.0;
        float tailRate = map(tailCnt, 0, tailCntMax, 0.0, 1.0);

        float radian  = 2.0 * PI * (tailStep * speed + start);
        float radiusX = radius * (1.0 + 0.1 * cos(spotRate * 2.0 * PI * tailStep * waveRadiusX));
        float radiusY = radius * (1.0 + 0.1 * cos(spotRate * 2.0 * PI * tailStep * waveRadiusY));
  
        float spotX   = addRadiusX + radiusX * cos(radian);
        float spotY   = addRadiusY + radiusY * sin(radian);

        float spotHue = (hueBase + tailRate * 60.0) % 360;
        float spotBri = tailRate * 10.0 * map(sqrt(spotX*spotX + spotY*spotY), 0.0, width / 2.0, 5.0, 0.0);
        
        fill(spotHue, 40, spotBri, 100);
        drawSwirl(swirlCnt, spotX, spotY , (1.0 - tailRate) * 10.0);

      }

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

  exit();

}

void drawSwirl(int swirlCnt, float x, float y, float size) {

  // draw same shape swirlCnt times while rotating
  for (int i = 0; i < swirlCnt; ++i) {
    pushMatrix();
    rotate(2.0 * PI * i / swirlCnt);
    ellipse(x, y , size, size);
    popMatrix();
  }

}

/*
Copyright (C) 2018- 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 
*/







No comments :

Post a Comment