title

deconbatch's Land of 1000 Creative Codings. example codes of Processing / p5.js, how-to articles, generative art images, and much more!

Love Light.

Generative art made with Processing.

Generative art made with Processing.


The morphing shadow picture.

Creative coding made with Processing on Java programming language.

I used the morphing method in 'Morph the Cat'.
And I made the animation of shadow pictures feeling.

You can make yet another morphing works with changing morphCalc() parameters.

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


Processing code example.

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





// Love Light.
// @author @deconbatch
// @version 0.1
// Processing 3.2.1
// 2018.12.08

void setup() {

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

void draw() {

  int   frameCntMax = 24 * 3;
  float radius      = width * 0.35;
  float baseHue     = random(360.0);

  translate(width / 2.0, height / 2.0);
  rotate(random(TWO_PI));

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

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

    for (float lineNo = 0.25; lineNo <= 2; lineNo += 0.25) {

      float radianLine = TWO_PI * noise(lineNo);
      float multFrom   = 2;
      float multTo     = floor(noise(lineNo * 10.0) * 3.0 + 1.0) * 2.0;

      for (float dotCnt = 0.0; dotCnt < 1.0; dotCnt += 0.001) {

        float radianDotCnt = TWO_PI * dotCnt;
        float radianShape  = radianDotCnt * lineNo + radianLine;

        float applySiz = morphCalc(
                                  abs(sin((radianShape) * multFrom) * 2.0) * 25,
                                  abs(sin((radianShape) * multTo) * 2.0) * 25,
                                  frameRatio
                                  );

        float applyHue = morphCalc(
                                   baseHue + dotCnt * 60.0 + lineNo * 360.0,
                                   baseHue + dotCnt * 30.0 + lineNo * 180.0,
                                  frameRatio
                                  );

        float applySat = morphCalc(
                                   map(sin(radianDotCnt + HALF_PI * 0.5), -1.0, 1.0, 60.0, 20.0),
                                   map(sin(radianDotCnt + HALF_PI * 0.5), -1.0, 1.0, 10.0, 50.0),
                                  frameRatio
                                  );

        float applyBri = morphCalc(
                                   4,
                                   6,
                                  frameRatio
                                  );
      
        float applyX   = cos(radianDotCnt) * radius * lineNo;
        float applyY   = sin(radianDotCnt) * radius * lineNo;
        
        fill(applyHue % 360.0, applySat, applyBri, 100.0);
        ellipse(applyX, applyY, applySiz, applySiz);
        
      }
    }      

    // for round trip animation
    saveFrame("frames/" + String.format("%04d", frameCnt) + ".png");
    saveFrame("frames/" + String.format("%04d", frameCntMax * 2 - frameCnt) + ".png");
    
  }
  
  exit();
  
}

/**
 * morphCalc morphing calculate function.
 * @param  from  any value : from shape value.
 * @param  to    any value : to   shape value.
 * @param  morphRatio  0.0 - 1.0 : morphing ratio from 1.0 to 0.0.
 * @return float any value : morphing shape value.
 */
private float morphCalc(float from, float to, float morphRatio) {
  return from * morphRatio + to * (1.0 - morphRatio);
}

/**
 * easeInOutCubic easing function.
 * @param  t     0.0 - 1.0 : linear value.
 * @return float 0.0 - 1.0 : eased value.
 */
private 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) 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 
*/











Post a Comment

0 Comments