Gate to The Magical Festa


About this Video.

This creative coding animation was made with Processing computer programming language and Kdenlive video editor.

At first, I planned to make something like 'Many red eyes watching you', and I failed as always. XP
Thanks to nice music
The Whisper by P C III
2015/07/16
http://freemusicarchive.org/music/P_C_III/Ad_Astra_Vol_II/The_Whisper
The Whisper by P C III is licensed under a Attribution License.
For more permissions:
contact artist

クリエイティブ・コモンズ・ライセンス


Processing example code.


// Gate to The Magical Festa
// Processing 3.2.1
// 2017.05.05

import java.util.Random;

Utils ut;
WallOfEyes ey;

/* ---------------------------------------------------------------------- */
class WallOfEyes {

  EyeElement[] ee;
  PVector[] locateEyes;
  float radianIdo[], radianKdo[];
  float blinkRadian[], divBlink[];
  int numEyes;

  WallOfEyes() {

    int numIdo = 16;
    int numKdo = 30;
    int startIdo = 110;
    int stopIdo = 190;
    int startKdo = 180;
    int stopKdo = 370;
    int radiusWall = 600;
    
    numEyes = numIdo * numKdo;
    float divIdo = (stopIdo - startIdo) / numIdo;
    float divKdo = (stopKdo - startKdo) / numKdo;

    radianIdo = new float[numEyes];
    radianKdo = new float[numEyes];
    blinkRadian = new float[numEyes];
    divBlink = new float[numEyes];
    ee = new EyeElement[numEyes];
    locateEyes = new PVector[numEyes];

    float ido, kdo;
    int cntEyes = 0;
    for (ido = startIdo; ido < stopIdo; ido += divIdo) { // Y
      for (kdo = startKdo; kdo < stopKdo; kdo += divKdo) { // Z

        if (cntEyes < numEyes) {
          radianIdo[cntEyes] = radians(ido);
          radianKdo[cntEyes] = radians(kdo);
          blinkRadian[cntEyes] = ut.gaussdist(90, 10, 5);
          divBlink[cntEyes] = 0.5 + ut.gaussdist(0.5, 0.5, 0.3);

          ee[cntEyes] = new EyeElement();
          locateEyes[cntEyes] = new PVector(
                                            radiusWall * cos(radianKdo[cntEyes]) * sin(radianIdo[cntEyes]),
                                            radiusWall * sin(radianKdo[cntEyes]) * sin(radianIdo[cntEyes]),
                                            radiusWall * cos(radianIdo[cntEyes])
                                            );
        }
        ++cntEyes;
        
      }
    }
  }

  void drawEyes() {
    for (int i = 0; i < numEyes; ++i) {
      blinkRadian[i] += divBlink[i];
      pushMatrix();
      translate(locateEyes[i].x, locateEyes[i].y, locateEyes[i].z);
      rotateZ(radianKdo[i]); // must be this order Z -> Y
      rotateY(radianIdo[i]);
      rotateX(radians(blinkRadian[i]));
      ee[i].show();
      popMatrix();
    }

  }

}

/* ---------------------------------------------------------------------- */
abstract class FountainElement {

  PShape anElement;
  float elementColor, elementSaturation, elementBright, elementAlpha;
  
  FountainElement() {
    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.setFill(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, float scaleZ) {
    anElement.scale(scaleX, scaleY, scaleZ);
  }

  void rotate(float radX, float radY, float radZ) {
    anElement.rotateX(radX);
    anElement.rotateY(radY);
    anElement.rotateZ(radZ);
  }

  void show() {
    shape(anElement);
  }

}

/* ---------------------------------------------------------------------- */
class EyeElement extends FountainElement {

  EyeElement() {
    super();
  }

  PShape pscreateElement() {

    noStroke();
    PShape psDp = createShape(GROUP);

    PShape psCh;
    for (int i = 0; i < 6; ++i) {
      float rad = 5 + pow(i, 3)/2;
      psCh = createShape(ELLIPSE, 0, 0, rad, rad);
      psCh.setFill(color(random(0, 360), 50, 20, 100));
      psCh.rotateX(radians(i * 30));
      psDp.addChild(psCh);
    }

    psCh = createShape(ELLIPSE, 0, 0, 10, 65);
    psCh.setFill(color(random(0, 360), 100, 80, 100));
    psCh.rotateX(radians(150));
    psDp.addChild(psCh);

    return psDp;

  }

}

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

/* ---------------------------------------------------------------------- */
void setup() {
  size(1280, 720, P3D);
  colorMode(HSB, 360, 100, 100, 100);
  smooth();
  background(0, 0, 0);
  frameRate(30);
  
  blendMode(LIGHTEST);
  hint(DISABLE_DEPTH_TEST);

  ut = new Utils();  
  ey = new WallOfEyes();  
}

void draw() {

  background(0, 0, 0);
  translate(0, 0, 0);
  camera(0, 0, 10,
         0, -60, -100,
         0, 1, 0);

  pointLight(0, 0, 100, 0, 0, 0);
      
  ey.drawEyes();


    saveFrame("frames/####.png");
    if (frameCount >= 3000) {
    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 
*/


Next Post Previous Post
No Comment
Add Comment
comment url