Heard It Through The Grapevine.

Creative coding works made with Processing in this article.

A clothoid curve animation code that I wrote by chance.

It is the creative coding animation work made with Processing.
It draws the grapevine curve.

I got some curve shape by chance. Is this a clothoid curve?
I grew this chance to a grapevine.

Related article in Japanese.
Garland for R.:Processing 2D アニメーション作例

Processing code example.

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

// Heard It Through The Grapevine.
// Processing 3.2.1
// 2018.05.06
// 20fps x 6s

PImage imgBackdrop;
float baseHue;
float baseDensity;

void setup() {

  size(720, 720);
  colorMode(HSB, 360, 100, 100, 100);
  noFill();
  smooth();
  noStroke();

  imgBackdrop = null;
  baseHue     = random(360);
  baseDensity = random(0.3, 3.0) * 0.001; // bigger == high density
  
}

void draw() {

  background(0.0, 0.0, 90.0, 100.0);
  translate(width / 2.0, height / 2.0);

  // backdrop image, 5 plants
  if (frameCount == 1) {
    for (int plant = 0; plant < 5; ++plant) {
      rotate(2.0 * PI / 5.0);
      drawVine(
               true,
               10000,
               2.0 + 1.5 * plant,
               10.0,
               1000.0,             // no rotation
               baseDensity * 0.5,
               0.0
               );
    }
    imgBackdrop = get();
  } else {
    // energy saving
    image(imgBackdrop, -width / 2.0, -height / 2.0);
  }
  
  // vine, 3 plants
  for (int plant = 0; plant < 3; ++plant) {
    rotate(2.0 * PI / 3.0);
    drawVine(
             false,
             50000 + floor(100 + 0.5 / baseDensity) * frameCount,
             0.6 + 0.4 * plant,
             2.0,
             8.0,
             baseDensity,
             baseHue + 30.0 * plant
             );

  }

  saveFrame("frames/####.png");
  if (frameCount >= 20 * 6.0) {
    exit();
  }

}

void drawVine(
              boolean backdrop,     // is this a backdrop image?
              int     lenVineMax,   // length of vine
              float   breakVine,    // length of vine branch
              float   widVine,      // width of vine
              float   rotateVine,   // rotation of vine, small == fast
              float   applyDensity, // vine branch density, bigger == high density
              float   hueVine       // hue value of vine
              ) {
      
  float angle  = 0;

  pushMatrix();
  for (int lenVine = 0; lenVine < lenVineMax; lenVine += 1) {

    float applyHue = backdrop ? 0.0   : (map(lenVine, 0, lenVineMax, hueVine, hueVine + 30.0)) % 360;
    float applySat = backdrop ? 0.0   : map(lenVine, 0, lenVineMax,  0.0, 40.0);
    float applyBri = backdrop ? 93.0  : map(lenVine, 0, lenVineMax, 90.0, 40.0);
    float applyAlp = backdrop ? 100.0 : map(lenVine, 0, lenVineMax, 100.0, 80.0);
    float applySiz = widVine - abs(map(lenVine, 0, lenVineMax, -widVine * 0.8, widVine * 0.8));

    translate(
              breakVine * cos(PI * lenVine / lenVineMax / rotateVine),
              breakVine * sin(PI * lenVine / lenVineMax / rotateVine)
              );
    rotate(PI * angle);
    angle += applyDensity;

    fill(applyHue, applySat, applyBri, applyAlp);
    ellipse(0, 0, applySiz, applySiz);

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



Yet another example images.

Creative coding works made with Processing in this article.

A clothoid curve animation code that I wrote by chance.

No comments :

Post a Comment