The creative coding example of changing shape with 'curveTightness()'

An example image of concentric shape.


About this creative coding artwork.

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

I tried to change the shape with 'curveTightness()' in this code. It's an application of the 'Broken Tea Cup'. And I focused on the movement of one shape this time.

This code do not display any images on the screen but just generates image files.
You can make 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.


/**
 * Matters Of The Heart.
 * concentric shape animate with curveTightness().
 * 
 * Processing 3.2.1
 * @author @deconbatch
 * @version 0.1
 * created 0.1 2019.04.21
 */

void setup() {

  size(720, 720);
  colorMode(HSB, 360, 100, 100, 100);
  rectMode(CENTER);
  smooth();
  noLoop();

}

void draw() {
 
  int   frameCntMax = 24 * 6;  // for 24fps x 6s animation
  int   lineCntMax  = 28;      // lines number
  float plotDiv     = 0.015;   // bigger : gap of each line wider

  int   cornerCntMax = floor(random(3.0, 6.0));
  float baseHue      = random(360.0);
  float tightStart   = random(1.0);

  NodeList[] nodeList = new NodeList[lineCntMax];
  for (int lineCnt = 0; lineCnt < lineCntMax; ++lineCnt) {
    nodeList[lineCnt] = new NodeList();
  }

  translate(width * 0.5, height * 0.5);

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

    float frRatio = map(frameCnt, 0, frameCntMax, 0.0, 1.0);
    float esRatio = easeInOutCubic(frRatio);

    pushMatrix();
    rotate(TWO_PI * esRatio);
    background(0.0, 0.0, 90.0, 100);

    for (int lineCnt = 0; lineCnt < lineCntMax; ++lineCnt) {
      nodeList[lineCnt].clear();
    }

    for (int cornerCnt = 0; cornerCnt < cornerCntMax; ++cornerCnt) {

      float cRatio = map(cornerCnt, 0, cornerCntMax, 0.0, 1.0);

      float xPoint = 0.0;
      float yPoint = 0.0;

      for (int lineCnt = 0; lineCnt < lineCntMax; ++lineCnt) {

        float lRatio = map(lineCnt, 0, lineCntMax, 0.0, 1.0);

        float xPrev = xPoint;
        float yPrev = yPoint;

        float baseDiv = plotDiv * (1.5 - lRatio);
        float tremor  = sin(TWO_PI * frRatio) * 0.05;
        xPoint += baseDiv * cos(TWO_PI * (cRatio + noise(tremor + yPrev * 0.5)));
        yPoint += baseDiv * sin(TWO_PI * (cRatio + noise(tremor + xPrev * 0.5)));
        Node node = new Node(new PVector(xPoint * width, yPoint * height));
        nodeList[lineCnt].add(node);
      }

    }

    for (int lineCnt = 0; lineCnt < lineCntMax; ++lineCnt) {

      float lRatio = map(lineCnt, 0, lineCntMax, 0.0, 1.0);

      float sHue   = baseHue + lRatio * 60.0 + sin(TWO_PI * frRatio) * 30.0;
      float sSat   = map(sin(HALF_PI * lRatio), 0.0, 1.0, 60.0, 40.0);
      float sBri   = map(lRatio, 0.0, 1.0, 60.0, 30.0);

      noFill();
      curveTightness(map(sin(TWO_PI * (tightStart + esRatio + lRatio)), -1.0, 1.0, 1.0, -2.0));
      strokeWeight(map(lRatio, 0.0, 1.0, 5.0, 1.0));
      stroke(sHue % 360.0, sSat, sBri, 100.0);
      nodeList[lineCnt].connectNodes();
    }
    popMatrix();
  
    casing();
    saveFrame("frames/" + String.format("%04d", frameCnt) + ".png");

  }
  exit();
}

/**
 * casing : draw fancy casing
 */
private void casing() {
  blendMode(BLEND);
  fill(0.0, 0.0, 0.0, 0.0);
  strokeWeight(55.0);
  stroke(0.0, 0.0, 0.0, 100.0);
  rect(0.0, 0.0, width, height);
  strokeWeight(50.0);
  stroke(0.0, 0.0, 100.0, 100.0);
  rect(0.0, 0.0, width, height);
  noStroke();
  noFill();
}

/**
 * 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;
}

/**
 * Keep node information.
 * @param  _position : node position
 */
class Node {
  PVector position;
 
  Node(PVector _position) {
    position = new PVector();
    position.set(_position);
  }
}

class NodeList extends ArrayList<Node> {

  void connectNodes() {

    beginShape();
    for (int j = 0; j < 2; ++j) { // twice for nice curve
      for (int i = 0; i < this.size(); ++i) {
        Node node = this.get(i);
        curveVertex(node.position.x, node.position.y);
      }
    }
    endShape();

  }
}


/*
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/>
*/


 

Next Post Previous Post
No Comment
Add Comment
comment url