• fullscreen
  • main.pde
  • rec.pde
  • float xmag, ymag = 0;
    float newXmag, newYmag = 0; 
    
    List listRec = new ArrayList();
    
    
    void setup() 
    { 
      size(500, 300, P3D); 
      noStroke(); 
      colorMode(RGB, 255);
      //smooth(); 
    
      for (int i=0; i<200; i++) {
        listRec.add(new Rec(random(2, 3), random(0.05, 0.1), 40, random(0, 2*PI), random(0, 2*PI) ));
      }
    } 
    
    int count = 0;
    void draw() 
    { 
    
      background(0.5);
    
      translate(width/2, height/2, -30); 
    
      newXmag = mouseX/float(width) * TWO_PI;
      newYmag = mouseY/float(height) * TWO_PI;
    
      float diff = xmag-newXmag;
      if (abs(diff) >  0.01) { 
        xmag -= diff/4.0;
      }
    
      diff = ymag-newYmag;
      if (abs(diff) >  0.01) { 
        ymag -= diff/4.0;
      }
    
      rotateX(-ymag); 
      rotateY(-xmag); 
      Rec rec;
      count++;
    
      for (int i=0; i<listRec.size(); i++) {
        rec = (Rec)listRec.get(i);
    
        if (count > 2) {
          rec.update();
        }
        rec.draw();
      }
      if (count > 2) {
    
        count = 0  ;
      }
    }
    
    void mouseClicked() {
      listRec.clear();
      for (int i=0; i<100; i++) {
        listRec.add(new Rec(random(2, 3), random(0.05, 0.1), 40, random(0, 2*PI), random(0, 2*PI) ));
      }
    }
    
    
    /**
     * RGB Cube.
     * 
     * The three primary colors of the additive color model are red, green, and blue.
     * This RGB color cube displays smooth transitions between these colors. 
     */
    private static float scale = 30;
    private static final int stateInc = 0;
    private static final int stateDec = 1;
    
    
    public class Rec {
    
      float longueur;
      float epaisseur;
      float rotateY;
      float rotateZ;
      float distanceFromCenter;
      float r;
      float g;
      float b;
      private int maxIterInState = (int)random(5,10);
    
      private int currentState = stateInc;
      private int nbIterInState = 0;
    
      public Rec(float _longueur, float _epaisseur, float _distanceFromCenter, float _rotateY, float _rotateZ) {
        longueur = _longueur;
        epaisseur = _epaisseur;
        distanceFromCenter = _distanceFromCenter;
        rotateY = _rotateY;
        rotateZ = _rotateZ;
    
        r = _rotateY * 255 / PI;
        g = _rotateZ * 255 / PI;
      }
    
      public void update() {
         b = (b<255?b++:0);
        if (currentState == stateInc) {
          if (nbIterInState == maxIterInState) {
            currentState = stateDec;
            nbIterInState = 0;
            return;
          }
          else {
            nbIterInState++;
            longueur+=0.05;
            
            return;
          }
        }
    
        else if (currentState == stateDec) {
          if (nbIterInState == maxIterInState) {
            currentState = stateInc;
            nbIterInState = 0;
            return;
          }
          else {
            nbIterInState++;
            
            longueur-=0.05;
            return;
          }
        }
      }
    
      public void draw() 
      { 
    
        pushMatrix(); 
    
        rotateY(rotateY);
        rotateZ(rotateZ);
    
        translate(distanceFromCenter, - scale / 2.0 *  epaisseur, scale / 2.0 *  epaisseur); 
    
    
        scale(scale);
        beginShape(QUADS);
        fill(r, g, b);
        vertex(0, 0, 0);
        vertex(longueur, 0, 0);
        vertex(longueur, epaisseur, 0);
        vertex(0, epaisseur, 0);
    
        vertex(0, 0, 0);
        vertex(longueur, 0, 0);
        vertex(longueur, 0, -epaisseur);
        vertex(0, 0, -epaisseur);
    
        vertex(0, epaisseur, 0);
        vertex(longueur, epaisseur, 0);
        vertex(longueur, epaisseur, -epaisseur);    
        vertex(0, epaisseur, -epaisseur);
    
        vertex(0, 0, -epaisseur);
        vertex(longueur, 0, -epaisseur);
        vertex(longueur, epaisseur, -epaisseur);
        vertex(0, epaisseur, -epaisseur);    
    
        endShape();
    
        popMatrix();
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    urzq

    pulsing ball

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    Controls :
    move the mouse.
    click to reset.

    It's a first try to recreate this "poster" :
    http://news.idealo.fr/wp-content/uploads/2011/03/affiche_gaite_lyrique2.jpg


    Things to do:
    > controls on settings (number of shapes, size)
    > some kind of interaction
    > rewrite the source code (it's ugly / in french)
    > find a way to have nice colors ... :D I'd like some advices on it.

    You need to login/register to comment.