Beauty of the noise.

A generative art of cherry blossom made with code.

Description of this generative art.

It's a generative artwork made with 'Processing' Java programming language.

I've not known the 'noiseSeed()' function till now! I had the problem that I can't create the same shapes even if I use the same noise start value. The holy function 'noiseSeed()' has solved this problem.

But now I know if I want to make a symmetrical image like this cherry blossom, I just use 'PGraphics' and 'image()' five times with 'rotate(TWO_PI / 5.0)'. 🤷‍♀️







 

The 'Processing' example code.

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.


// My Cherry Amour
// Processing 3.2.1
// 2017.09.10

/* ---------------------------------------------------------------------- */
class Petals {

  int cntWidthMax;
  int divRotate;
  int cntRotateMax;
  int cntLinesMax;
  int cntPetalsMax;
  float baseStrokeWeight;
  float basePetalSize;
  float baseColor;
  float petalBaseFrom, petalBaseTo, petalDivFrom, petalDivTo;

  Petals() {
    divRotate = 8;   // divide 360 degree
    cntRotateMax = 2 * 360 * divRotate;  // draw while rotating
    cntLinesMax = 3;   // draw lines with individual shape
    cntWidthMax = 12;  // repeat same shape with different stroke width
    cntPetalsMax = 5;  // repeat same shape with different angle
    baseStrokeWeight = 0.001;
    basePetalSize = 480.0;
    baseColor = map(random(1.0), 0.0, 1.0, 240.0, 340.0);
    petalBaseFrom = 0.0;
    petalBaseTo = 0.0;
    petalDivFrom = 0.0;
    petalDivTo = 0.0;
  }

  void setOneFlower() {
    petalBaseFrom = 0.5;
    petalBaseTo = 3.0;
    petalDivFrom = 6.0;
    petalDivTo = 10.0;
    basePetalSize = 460.0;
  }

  void setManyLines() {
    petalBaseFrom = 0.5;
    petalBaseTo = 1.3;
    petalDivFrom = 01;
    petalDivTo = 0.8;
    basePetalSize = 540.0;
  }

  void setVarietyShape() {
    petalBaseFrom = 6.0;
    petalBaseTo = 7.4;
    petalDivFrom = 0.2;
    petalDivTo = 1.3;
    basePetalSize = 360.0;
  }

  void setCenterOfFlower() {
    petalBaseFrom = 15.0;
    petalBaseTo = 20.0;
    petalDivFrom = 0.2;
    petalDivTo = 5.0;
    basePetalSize = 860.0;
  }

  void drawPetals() {
  
    float noiseShpStart = random(petalBaseFrom, petalBaseTo);
    for (int cntLines = 0; cntLines < cntLinesMax; ++cntLines) {
    
      noiseShpStart += random(petalDivFrom, petalDivTo);
      float noiseHueStart = random(100.0);
      float noiseBriStart = random(100.0);
      float noiseAlpStart = random(100.0);

      for (int cntPetals = 0; cntPetals < cntPetalsMax; ++cntPetals) {

        // rotate whole canvas
        canvasRotation(360/cntPetalsMax);

        float noiseSatStart = random(100.0);
        float noiseHue = noiseHueStart;
        noiseHueStart += 0.01;

        for (int cntWidth = 1; cntWidth <= cntWidthMax; ++cntWidth) {

          float noiseSat = noiseSatStart;
          float noiseBri = noiseBriStart;
          float noiseAlp = noiseAlpStart;
          float noiseShp = noiseShpStart;
          float sumRotation = 0;

          // grow the line
          strokeWeight(baseStrokeWeight * cntWidth * cntWidth);
        
          for (int cntRotate = 0; cntRotate < cntRotateMax; ++cntRotate) {

            // rotate fixed degree and calculate the plot point
            float rotation = 1.0 / divRotate;
            canvasRotation(rotation);
            sumRotation += rotation * map(noise(noiseShp), 0.0, 1.0, -1.0, 1.0);
            float idxW = 0.0;
            float idxH = basePetalSize * abs(sin(radians(sumRotation)) + cos(radians(sumRotation)));

            // smooth shape
            float brushHue = (baseColor + 360 + map(noise(noiseHue), 0.0, 1.0, -90.0, 90)) % 360;
            float brushSat = map(noise(noiseSat), 0.0, 1.0, 30.0, 100.0);
            float brushSiz = map(noise(noiseBri), 0.0, 1.0, 0.0, 2.0);
            float brushBri = map(noise(noiseBri), 0.0, 1.0, 0.0, 100.0) / cntWidth;
            float brushAlp = map(noise(noiseAlp), 0.0, 1.0, 0.0, 100.0);
            drawLine(idxW, idxH, brushHue, brushSat, brushBri, brushAlp, brushSiz);

            // weird shape
            idxH *= noise(noiseAlp) * 1.5; // I don't mind using any noise
            if (abs(idxH) > 1.0) {
              brushBri *= (idxH / abs(idxH));
            }
            drawLine(idxW, idxH, brushHue, brushSat, brushBri, brushAlp, brushSiz);

            noiseHue += 0.003;
            noiseSat += 0.003;
            noiseBri += 0.002;
            noiseAlp += 0.005;
            noiseShp += 0.002;
        
          }

          canvasRotation(-cntRotateMax);

        }
      }
    }
  }

  void drawLine(float idxW, float idxH, float brushHue, float brushSat, float brushBri, float brushAlp, float brushSiz) {
    pushMatrix();
    translate(idxW, idxH);
    stroke(brushHue, brushSat, brushBri, brushAlp);
    line(0.0, 0.0, -brushSiz, brushSiz);
    popMatrix();
  }
  
  void canvasRotation(float degrees) {
    rotate(radians(degrees));
  }

}

/* ---------------------------------------------------------------------- */
Petals pt;

void setup() {

  size(1080, 1080);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(SCREEN);
  noiseSeed(0);
  smooth();
  //  noLoop();
  frameRate(1);

  pt = new Petals();  

}

void draw() {

  background(0, 0, 0);
  translate(width / 2, height / 2);

  float flowerSelector = random(0.0, 4.0);
  if (flowerSelector < 1.0) {
    pt.setOneFlower();
  } else if (flowerSelector < 2.0) {
    pt.setManyLines();
  } else if (flowerSelector < 3.0) {
    pt.setVarietyShape();
  } else {
    pt.setCenterOfFlower();
  }
  
  pt.drawPetals();
  
  saveFrame("frames/####.png");
  //  exit();
  
}

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