Can so many circles create the Mandala image?

An pattern with so many circles.

Description of this example code.

It's a creative coding example made with the 'Processing' in Java mode. It generates various patterns with many random circles.

 







The 'Processing' code examples.

Second version.

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.

// Spiral Mandala
// @author @deconbatch
// @version 0.2
// Processing 3.2.1
// Create: 2017.07.19
// Update: 2018.11.23

/* ---------------------------------------------------------------------- */
abstract class MandalaStyle {

  float valBriMin, valBriMax;
  float valAlpMin, valAlpMax;
  float baseWeight;
  float baseDiv;
  
  MandalaStyle() {
    valBriMin  = 0.0;
    valBriMax  = 0.0;
    valAlpMin  = 0.0;
    valAlpMax  = 0.0;
    baseWeight = 0.0;
    baseDiv    = 0.0;
  }

}

/* ---------------------------------------------------------------------- */
class FilledMandala extends MandalaStyle {
  
  FilledMandala() {
    super();
    
    valBriMin  = 50.0;
    valBriMax  = 80.0;
    valAlpMin  = 0.0;
    valAlpMax  = 100.0;
    baseWeight = 50.0;
    baseDiv    = 8.0;
    
  }

}

/* ---------------------------------------------------------------------- */
class NeonMandala extends MandalaStyle {
  
  NeonMandala() {
    super();
    
    valBriMin  = 10.0;
    valBriMax  = 50.0;
    valAlpMin  = 0.0;
    valAlpMax  = 5.0;
    baseWeight = 20.0;
    baseDiv    = 4.0;
    
  }

}

/* ---------------------------------------------------------------------- */
class LinearMandala extends MandalaStyle {
  
  LinearMandala() {
    super();
    
    valBriMin  = 0.0;
    valBriMax  = 60.0;
    valAlpMin  = 0.0;
    valAlpMax  = 100.0;
    baseWeight = 1.0;
    baseDiv    = 3.0;
    
  }

}

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

void setup() {

  size(980, 980);
  colorMode(HSB, 360, 100, 100, 100);
  noFill();
  smooth();

}

void draw() {

  MandalaStyle mStyle;
  float baseColor;
  float hueMin = random(360.0);

  background(hueMin, 100.0, 5.0, 100.0);

  blendMode(BLEND);
  drawPixels(
             new FilledMandala(),
             random(hueMin, hueMin + 30.0) % 360.0,
             6
             );
  drawPixels(
             new NeonMandala(),
             random(hueMin, hueMin + 30.0) % 360.0,
             3
             );

  blendMode(SCREEN);
  drawPixels(
             new LinearMandala(),
             random(hueMin, hueMin + 60.0) % 360.0,
             1
             );

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

}

void drawPixels(MandalaStyle mStyle, float baseColor, int drawMult) {

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

    float circleBase = width / mStyle.baseDiv + map(random(1.0), 0.0, 1.0, -width / (mStyle.baseDiv * 4.0), width / (mStyle.baseDiv * 4.0));
    float circleMult = map(random(1.0), 0.0, 1.0, 2.0, 5.0);
    int   drawCntMax = drawMult * divCnt;

    for (int drawCnt = 0; drawCnt < drawCntMax; ++drawCnt) {

      float valHue  = (baseColor + random(1.0) * 30.0) % 360.0;
      float valSat  = map(random(1.0), 0.0, 1.0, 0.0, 40.0);
      float valAlp  = map(drawCnt, 0, drawCntMax, mStyle.valAlpMax, mStyle.valAlpMin);
      float rndBri  = random(1.0);
      float valBri  = map(rndBri, 0.0, 1.0, mStyle.valBriMin, mStyle.valBriMax);
      float valSize = map(rndBri, 1.0, 0.0, circleBase, circleMult * circleBase);
      float idxDiv  = width / divCnt;

      strokeWeight(map(drawCnt, 0, drawCntMax, mStyle.baseWeight, mStyle.baseWeight * 0.05));
      stroke(valHue, valSat, valBri, valAlp);

      for (float idxW = 0.0; idxW < width + idxDiv; idxW += idxDiv) {
        for (float idxH = 0.0; idxH < height + idxDiv; idxH += idxDiv) {
          ellipse(idxW, idxH, valSize, valSize);
        }
      }
      
    }
    
  }
}

/*
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 <http://www.gnu.org/licenses/>
*/







Example code : first version.


An pattern with so many circles.

// Spiral Mandala
// Processing 3.2.1
// 2017.07.19

import java.util.Random;

/* ---------------------------------------------------------------------- */
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 CircleBrush extends PshapeElement {
  
  CircleBrush() {
    super();
  }

  PShape pscreateElement() {

    stroke(0.0, 0.0, 0.0, 0.0);
    noFill();
    PShape psDp = createShape(ELLIPSE, 0.0, 0.0, 5.0, 5.0);
    return psDp;

  }

}

/* ---------------------------------------------------------------------- */
abstract class MandalaStyle {

  float valBriMin, valBriMax;
  float valColorMin, valColorMax;
  float valStrokeWeight;
  float valCircleBaseDiv;
  
  MandalaStyle() {
    valBriMin = 0.0;
    valBriMax = 0.0;
    valColorMin = 0.0;
    valColorMax = 0.0;
    valStrokeWeight = 0.0;
    valCircleBaseDiv = 0.0;
  }

}

/* ---------------------------------------------------------------------- */
class NeonMandala extends MandalaStyle {
  
  NeonMandala() {
    super();
    
    valBriMin = 0.4;
    valBriMax = 32.0;
    valColorMin = 200.0;
    valColorMax = 280.0;
    valStrokeWeight = 0.05;
    valCircleBaseDiv = 14.0;
    
  }

}

/* ---------------------------------------------------------------------- */
class FilledMandala extends MandalaStyle {
  
  FilledMandala() {
    super();
    
    //    valBriMin = 0.3;
    //    valBriMax = 2.4;
    valBriMin = 0.2;
    valBriMax = 3.6;
    valColorMin = 170.0;
    valColorMax = 220.0;
    valStrokeWeight = 0.2;
    valCircleBaseDiv = 18.0;
    
  }

}

/* ---------------------------------------------------------------------- */
class LinearMandala extends MandalaStyle {
  
  LinearMandala() {
    super();
    
    valBriMin = 5.0;
    valBriMax = 100.0;
    valColorMin = 150.0;
    valColorMax = 200.0;
    valStrokeWeight = 0.003;
    valCircleBaseDiv = 12.0;
    
  }

}

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

PshapeElement pCircle;
MandalaStyle mStyle;
float baseColor;

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

  // choose Mandala Style
  float selector = random(1.0);
  if (selector > 0.66) {
    mStyle = new NeonMandala();
  } else if (selector > 0.33) {
    mStyle = new FilledMandala();
  } else {
    mStyle = new LinearMandala();
  }

  strokeWeight(mStyle.valStrokeWeight);
  pCircle = new CircleBrush();

  baseColor = random(mStyle.valColorMin, mStyle.valColorMax); // blue - violet are good for me.

}

void draw() {

  background(0, 0, 0);
  drawPixels();

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

}

void canvasRotation(float degrees) {

  translate(width/2, height/2);
  rotate(radians(degrees));
  translate(-width/2, -height/2);

}

void drawPixels() {

  canvasRotation(-18.0);

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

    canvasRotation(divCnt * 3);
    float circleBase = width / mStyle.valCircleBaseDiv + map(random(1.0), 0.0, 1.0, -width / (mStyle.valCircleBaseDiv * 4.0), width / (mStyle.valCircleBaseDiv * 4.0));
    float circleMult = map(random(1.0), 0.0, 1.0, 2.0, 5.0);
    int drawCntMax = 3 * divCnt;

    for (int drawCnt = 0; drawCnt < drawCntMax; ++drawCnt) {

      float valHue = (baseColor + map(random(1.0), 0.0, 1.0, -60.0, 60.0)) % 360.0;
      float valSat = map(random(1.0), 0.0, 1.0, 60.0, 100.0);
      float valBri = map(random(1.0), 0.0, 1.0, mStyle.valBriMin, mStyle.valBriMax);
      float valAlp = map(random(1.0), 0.0, 1.0, 30.0, 100.0);
      float valSize = map(random(1.0), 0.0, 1.0, circleBase, circleMult * circleBase);
      float idxDiv = width / divCnt;

      for (float idxW = 0.0; idxW < width + idxDiv; idxW += idxDiv) {
        for (float idxH = 0.0; idxH < height + idxDiv; idxH += idxDiv) {

          pushMatrix();
          translate(idxW, idxH);
          pCircle.resetSize();
          pCircle.changeSize(valSize, valSize);
          pCircle.setElementFill(valHue, valSat, valBri, valAlp);
          pCircle.show();
          popMatrix();
        
        }
      }
    }
  }
}

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