Sand Ripples



About this creative coding work.

This creative coding art work was written in Processing Java programming language.
Many lines draw something like ripples on the sand. It derived from Big Bang.


Processing example code.

// Sand Ripples
// Processing 3.2.1
// 2017.07.29

import java.util.Random;

/* ---------------------------------------------------------------------- */
class Utils {

  Random obj_random;

  Utils() {
    obj_random = new Random();
  }

  float gaussdist(float pmean, float plimit, float pdevi) {
    /**
       Gaussian distribution
       1.parameters.
       pmean  : mean value
       plimit : max value of abs(deviation)
       ex. plimit >= 0
       pmean = 0.5, plimit = 0.5 -> return value = from 0.0 to 1.0
       pdevi  : standard deviation value
       ex. good value? -> pdevi = plimit / 2
       2.return.
       gaussian distribution
    **/

    if (plimit == 0) {
      return pmean;
    }

    float gauss = (float) obj_random.nextGaussian() * pdevi;
    // not good idea
    if (abs(gauss) > plimit) {
      gauss = pow(plimit, 2) / gauss;
    }

    return pmean + gauss;
    
  }
}

/* ---------------------------------------------------------------------- */
abstract class PshapeElement {

  PShape anElement;
  float elementColor, elementSaturation, elementBright, elementAlpha;
  
  PshapeElement() {
    anElement = pscreateElement();
    elementColor = 0;
    elementSaturation = 0;
    elementBright = 0;
    elementAlpha = 0;
  }

  abstract PShape pscreateElement();

  void setElementFill(float pcolor, float psaturation, float pbright, float palpha) {
    elementColor = pcolor;
    elementSaturation = psaturation;
    elementBright = pbright;
    elementAlpha = palpha;
    resetColor();
  }

  void resetColor() {
    anElement.setStroke(color(elementColor, elementSaturation, elementBright, elementAlpha));
  }

  void changeColor(float scolor) {
    elementColor = scolor;
    resetColor();
  }

  void changeBright(float sbright) {
    elementBright = sbright;
    resetColor();
  }

  void resetSize() {
    anElement.resetMatrix();
  }

  void changeSize(float scaleX, float scaleY) {
    anElement.scale(scaleX, scaleY);
  }

  void rotate(float radX) {
    anElement.rotate(radX);
  }

  void show() {
    shape(anElement);
  }

}

/* ---------------------------------------------------------------------- */
class LineBrush extends PshapeElement {
  
  LineBrush() {
    super();
  }

  PShape pscreateElement() {

    stroke(0.0, 0.0, 0.0, 0.0);
    noFill();
    PShape psDp = createShape(LINE, -0.3, -0.3, 0.3, 0.3);
    return psDp;

  }

}

/* ---------------------------------------------------------------------- */

Utils ut;
PshapeElement pLine;

void setup() {
  size(900, 900);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(SCREEN);
  strokeWeight(0.001);
  smooth(8);
  noLoop();
  //  frameRate(1);

  ut = new Utils();  
  pLine = new LineBrush();

}

void draw() {

  background(0, 0, 0);

  float baseColor = random(0.0, 360.0);
  for (int cntCircle = 0; cntCircle < 3; ++cntCircle) {
    baseColor = (baseColor + 30) % 360.0;
    drawPixels(baseColor);
  }

  saveFrame("frames/####.png");
  exit();
  
}

void canvasRotation(float degrees, float centerX, float centerY) {

  translate(centerX, centerY);
  rotate(radians(degrees));
  translate(-centerX + random(0.6), -centerY + random(0.6));

}

void drawPixels(float rippleColor) {

  float sumRotation = 0;
  float centerX = width / 8 + random(3 * width / 4);
  float centerY = height / 8 + random(3 * height / 4);
  int divCntMax = 10 + round(ut.gaussdist(10.0, 5.0, 2.5));

  for (int divCnt = 1; divCnt <= divCntMax; ++divCnt) { 

    float lineBri = map(random(1.0), 0.0, 1.0, 1.0, 100.0);
    float idxDiv = width / divCnt;
    int drawCntMax = round(ut.gaussdist(250.0, 100.0, 50.0));
    
    for (int drawCnt = 0; drawCnt < drawCntMax; ++drawCnt) {

      float lineHue = (rippleColor + ut.gaussdist(0.0, 60.0, 30.0)) % 360.0;
      float rotation = divCnt * ut.gaussdist(10.0, 3.0, 2.0);
      canvasRotation(rotation, centerX, centerY);
      sumRotation += rotation;

      for (float idxW = 0.0; idxW < width + idxDiv; idxW += idxDiv) {
        for (float idxH = 0.0; idxH < height + idxDiv; idxH += idxDiv) {
          
          float lineSat = map(random(1.0), 0.0, 1.0, 10.0, 30.0);
          float lineAlp = map(random(1.0), 0.0, 1.0, 20.0, 100.0);
          float lineSize = map(random(1.0), 0.0, 1.0, 1.0, 4.0);

          pushMatrix();
          translate(idxW, idxH);
          pLine.resetSize();
          pLine.changeSize(lineSize, lineSize);
          pLine.setElementFill(lineHue, lineSat, lineBri, lineAlp);
          pLine.show();
          popMatrix();
        
        }
      }
    }
  }

  canvasRotation(-sumRotation, centerX, centerY);

}

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



Next Post Previous Post
No Comment
Add Comment
comment url