Neckerchief knitted with fine soft downy hair, not.

An image of five waving cloth.

An animation of waving cloth knitted by node-garden.

It is a creative coding animation work that is written in the 'Processing'. The 'node-garden' is one of the techniques of creative coding. I made an animation of something that looks like a waving cloth with this technique.

Please read the article 'The node-garden technique : basics section.'.

It creates interesting shapes with this formula.

 float amplitude = ampBase * map(customNoise(nParam), -1.0, 1.0, 0.0, 1.0);
 float vibration = sin((customNoise(noise(lineCnt) * TWO_PI + theta * thetaMult) + thetaRatio) * TWO_PI);

 

Learning the behavior of formula.

The 'thetaMult' value detemines the density of knitting(?).

float thetaMult = 200.0;

Thick knitting.

float thetaMult = 50.0;

Rough knitting.



It's a by-product of my creative coding work that creates still image artwork 'Raining in My Heart'.

 






An example code of Processing.

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 under the terms of the GPL. To see other works based on my code is my pleasure. And my honor.



/**
 * Kind of Girl.
 * Neckerchief knitted with fine soft downy hair not.
 *
 * @author @deconbatch
 * @version 0.1
 * @license GPL Version 3 http://www.gnu.org/licenses/
 * Processing 3.5.3
 * 2021.04.14
 */

void setup() {
  size(720, 720);
  colorMode(HSB, 360.0, 100.0, 100.0, 100.0);
  smooth();
  noLoop();
}

void draw() {

  int   frmMax    = 24 * 8;
  int   lineMax   = 5;
  float thetaMax  = PI;
  float thetaMult = 100.0;
  float thetaDiv  = PI * 0.5 / thetaMult;
  float ampBase   = height / lineMax * 0.5;
  float hueBase   = random(360.0);

  // get background
  PImage bg = getBackground(width, height);

  for (int frmCnt = 0; frmCnt < frmMax; frmCnt++) {

    float frmRatio   = map(frmCnt, 0, frmMax, 0.0, 1.0);

    // draw background
    blendMode(BLEND);
    background(0.0, 0.0, 90.0, 100.0);
    image(bg, 0, 0);

    // draw foreground
    blendMode(SUBTRACT);
    noFill();
    for (int lineCnt = 0; lineCnt < lineMax; lineCnt++) {
      float lineRatio = map(lineCnt, 0, lineMax, 0.0, 1.0);
      float direction = (lineCnt % 2 == 0) ? 1.0 : -1.0;

      ArrayList<PVector> pvs = new ArrayList<PVector>();
      for (float theta = 0.0; theta < thetaMax; theta += thetaDiv) {

        float thetaRatio = map(theta, 0.0, thetaMax, 0.0, 1.0);
        float nParam = direction * (lineRatio + frmRatio) * TWO_PI + theta;

        float lineBase  = ampBase + lineRatio * height;
        float amplitude = ampBase * map(customNoise(nParam), -1.0, 1.0, 0.0, 1.0);
        float vibration = sin((customNoise(noise(lineCnt) * TWO_PI + theta * thetaMult) + thetaRatio) * TWO_PI);
        float x = thetaRatio * width;
        float y = lineBase + amplitude * vibration;

        pvs.add(new PVector(x, y));

      }

      float dMin = ampBase * 0.2;
      float dMax = ampBase * 0.6;
      stroke((hueBase + (lineRatio + frmRatio) * 360) % 360.0, 60.0, 30.0, 100.0);
      for (PVector f : pvs) {
        for (PVector t : pvs) {
          float d = dist(f.x, f.y, t.x, t.y);
          if (d < dMax && d > dMin) {
            float w = map(d, dMin, dMax, 2.0, 0.0);
            strokeWeight(w);
            line(f.x, f.y, t.x, t.y);
          }
        }
      }

    }

    blendMode(BLEND);
    casing();
    saveFrame("frames/" + String.format("%04d", frmCnt) + ".png");

  }
  exit();
}

/**
 * getBackground : returns matrix background image
 */
private PImage getBackground(int _w, int _h) {

  float div = min(width, height) * 0.02;
  
  PGraphics p = createGraphics(_w, _h);
  p.beginDraw();
  p.colorMode(HSB, 360, 100, 100, 100);
  p.background(0.0, 0.0, 100.0, 100.0);
  p.noFill();
  p.stroke(0.0, 0.0, 80.0, 100.0);
  p.strokeWeight(1.0);
  for (float x = 0; x < width; x += div) {
    p.line(x, 0, x, height);
  }
  for (float y = 0; y < height; y += div) {
    p.line(0, y, width, y);
  }
  p.endDraw();

  return p;
}

/**
 * casing : draw fancy casing
 */
private void casing() {
  fill(0.0, 0.0, 0.0, 0.0);
  strokeWeight(34.0);
  stroke(0.0, 0.0, 0.0, 100.0);
  rect(0.0, 0.0, width, height);
  strokeWeight(30.0);
  stroke(0.0, 0.0, 100.0, 100.0);
  rect(0.0, 0.0, width, height);
}

/**
 * customNoise : returns custom noise value
 */
private float customNoise(float value) {
  return sin(cos(value) * TWO_PI);
}


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