Blood of the Sun.

Some creative coding works with Vector Field.
Some creative coding works with Vector Field.

Description of this creative coding.

This creative coding code creates  Vector Field images that use Perlin noise in angle calculation.

Reference
Drawing vector field | GenerateMe

I devised initial points makes a circle shape.
And I used Perlin noise in angle to calculate draw points.
Finally, this code becomes creating an artistic burning melon. XD

This code does not display any images on the screen but just generates image files.

Processing code example.

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.



/**
 * Blood of the Sun.
 * 
 * @author @deconbatch
 * @version 0.1
 * Processing 3.2.1
 * created 2019.07.14
 * draw Vector Field with perlin noise in angle.
 */

void setup() {

  size(1080, 1080);
  colorMode(HSB, 360, 100, 100, 100);
  smooth();
  noLoop();

}

void draw() {

  float baseHue = random(360.0);

  blendMode(SCREEN);
  background(baseHue, 90.0, 5.0, 100.0);
  noStroke();
    
  drawVectorField(baseHue, 30.0);
  noiseSeed(floor(random(100)));
  drawVectorField(baseHue + 30.0, 20.0);
  noiseSeed(floor(random(100)));
  drawVectorField(baseHue + 60.0, 10.0);
  noiseSeed(floor(random(100)));
  drawVectorField(baseHue + 90.0, 8.0);
  
  casing();
  saveFrame("frames/####.png");
  exit();

}

/**
 * drawVectorField
 * @param  _baseHue   : vector field color.
 * @param  _noiseStep : noise parameter multiple value.
 */
private void drawVectorField(float _baseHue, float _noiseStep) {

  // shape
  float plotDiv   = 0.001;
  float initDiv   = 0.01;
  float radiusMax = 0.3;

  // color
  float baseSat = 90.0;
  float baseBri = 2.0;
  float baseAlp = 100.0;

  for (float radius = initDiv; radius <= radiusMax; radius += initDiv) {

    float radianDiv = map(radius, initDiv, radiusMax, 20.0, 2.0) * initDiv;
    float baseSiz   = map(radius, initDiv, radiusMax, 1.5, 1.0);
    int   plotMax   = floor(map(radius, initDiv, radiusMax, 4000.0, 10000.0));

    for (float radian = 0.0; radian < TWO_PI; radian += radianDiv) {

      // initial points makes circle shape
      float xInit  = radius * cos(radian + radius) + 1.0;
      float yInit  = radius * sin(radian + radius) + 1.0;
      int   sparse = floor((xInit + yInit) * 100.0) % 4;  // make 0, 1, 2, 3 with initial point

      // draw vector field
      float xPoint = xInit;
      float yPoint = yInit;
      float rPoint = 0.0;
      for (int plotCnt = 0; plotCnt < plotMax; plotCnt++) {

        float pRatio = map(plotCnt, 0, plotMax, 0.0, 1.0);

        // vector field calculation
        float xPrev = xPoint;
        float yPrev = yPoint;
        float rPrev = rPoint;
        rPoint += map(noise(xPrev * _noiseStep, yPrev * _noiseStep), 0.0, 1.0, -1.0, 1.0);
        xPoint += plotDiv * cos(TWO_PI * rPoint) * pRatio;
        yPoint += plotDiv * sin(TWO_PI * rPoint) * pRatio;

        float pHue = _baseHue + pRatio * 30.0;
        float pSat = baseSat * map(sin(PI * pRatio), 0.0, 1.0, 1.0, 0.5);
        float pBri = baseBri * sin(PI * pRatio) * (sparse + 6.0) / 9.0;
        float pSiz = baseSiz * sin(PI * pRatio);
        fill(pHue % 360.0, pSat, pBri, baseAlp);
        ellipse((xPoint - 0.5) * width, (yPoint - 0.5) * height, pSiz, pSiz);

      }
    }
  }
}

/**
 * casing : draw fancy casing
 */
private void casing() {
  blendMode(BLEND);
  fill(0.0, 0.0, 0.0, 0.0);
  strokeWeight(60.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);
}


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




No comments :

Post a Comment