• fullscreen
  • Automata.pde
  • Chain.pde
  • ChainManager.pde
  • Chords.pde
  • Controls.pde
  • Methods.pde
  • class Automaton {
      float x;
      float y;
      float py;
      float px;
      float radioX;
      float radioY;
      float tStep;
    
      int posInitX;
      int posInitY;
    
      int type;
      float inc;
    
      Automaton(float radioX, float radioY, int type) {
        this.x = random(width);
        this.y = random(height);
        this.radioX = radioX;
        this.radioY = radioY;
        tStep = random(TWO_PI);
        this.type = type;
        inc = random(0.03, 0.045);
      }
    
      Automaton(int posInitX, int posInitY, float radioX, float radioY, int type) {
        this.posInitX = posInitX;
        this.posInitY = posInitY;
        this.x = random(width);
        this.y = random(height);
        this.radioX = radioX;
        this.radioY = radioY;
        tStep = random(TWO_PI);
        this.type = type;
        inc = random(0.02, 0.029);
      }
    
      void generate() {
        px = x;
        py = y;
    
        switch(type) {
        case 1:
          x =  cos(tStep)*radioX + width/2.0;
          y =  sin(tStep)*cos(tStep)*radioY + height/2.0;
          break;
        case 2:
          x =  cos(tStep + tStep/2.0)*radioX + width/2.0;
          y =  sin(tStep)*sin(tStep)*radioY + height/2.0;
          break;
        case 3:
          x =  sin(tStep + sin(tStep/2.0))*radioX + width/2.0;
          y =  sin(tStep + cos(tStep/2.0))*radioY + height/2.0;
          break;
        case 4:
          x = cos(tStep)*sin(tStep/6)*radioX + width/2.0 + noise(tStep)*60;
          y = sin(tStep/2 + cos(tStep/3))*cos(tStep/5)*radioY + height/2.0 + noise(tStep)*60;
          break;
        case 5:
          x = posInitX + 115*noise(tStep) + 50*cos(tStep);
          y = sin(tStep + cos(tStep/2))*radioY +  posInitY;
          break;
        }
    
        tStep += inc;
      }
      
    }
    
    
    class Chain {
      ParticleSystem physics;
      Particle end;
      Particle start;
      Vector p;
      Vector s;
      
      java.util.List vertices;
    
      PVector initP;
      PVector endP;
    
      float angle;
      float inc;
      float nVal;
      float rest;
      int   n = 15;
      float t = 0.0;
      float amp = 100.0;
    
      color chordColor;
    
      Chain(ParticleSystem physics, PVector initP, PVector endP) {
        amp = 50 + random(-30, 30);
        inc = random(0.022, 0.029);
        nVal = random(0.2, 0.3);
        // t = random(-PI, PI);
        this.physics = physics;
    
        this.initP = initP;//new PVector(initP.x, initP.y);
        this.endP  = endP;//new PVector(endP.x, endP.y);
        inc = random(0.2, 0.3);
    
        end = physics.makeParticle(1.0, initP.x, initP.y, 0);
        end.makeFixed();
        start = physics.makeParticle(1.0, endP.x, endP.y, 0);
        start.makeFixed();
    
        p = new Vector();
        s = new Vector();
    
        p.add(start);
        for (int i=1; i < (n-1); i++) {
          p.add( physics.makeParticle(1.0, lerp(initP.x, endP.x, i/(float)(n-1) ), lerp(initP.y, endP.y, i/(float)(n-1) ), 0.0 ));
        }
        p.add(end);
    
        float d = dist(initP.x, initP.y, endP.x, endP.x)/(float)(n-1);
    
        for (int i=0; i < (n-1); i++) {
          Particle p1 = (Particle)p.get(i);
          Particle p2 = (Particle)p.get(i+1);
          s.add( physics.makeSpring(p1, p2, 1.0, 0.05, d));
        }
      }
    
      void draw() {
    
        angle = atan2(endP.y - initP.y, endP.x - initP.y );
    
        Vec2D[] handles=new Vec2D[n];
        for (int i=0; i<n; i++) {
          Particle p1=(Particle)p.get(i);
          handles[i]=new Vec2D(p1.position().x(), p1.position().y());
        }
    
        Spline2D spline = new Spline2D(handles);
        vertices = spline.computeVertices(8);
    
        setDraw();
      }
    
      void setDraw() {
        angle = PI + atan2(endP.y - initP.y, endP.x - initP.y );
    
        if (!drawColorChords) {
          offScreen.stroke( chordColor, 25 + noise(nVal)*50);
        }
        else {
          float mA = map(angle, 0, TWO_PI, 25, 75);
          float mG = mag(endP.x - initP.y, endP.y - initP.y)*0.2;
          offScreen.stroke(0, mA + mG + noise(nVal)*50, mG + mA + noise(nVal)*30, mA);
        }
    
        drawWave();
      }
    
      void drawWave() {
        offScreen.strokeWeight(1); 
        offScreen.noFill();
        offScreen.beginShape();
        for (int i=0; i < vertices.size();i++ ) {
          Vec2D v=(Vec2D)vertices.get(i);
          offScreen.vertex(v.x, v.y);
        }
        offScreen.endShape();
      }
    
      void update() {
        t += 1/24.0 +noise(nVal)/8;
    
        angle = PI + atan2(endP.y - initP.y, endP.x - initP.y );
    
        switch(waveType) {
        case 1:
          for (int i = 1; i < (n-1); i++) {
            Particle p1 = (Particle)p.get(i);
            p1.position().add(amp*chordAmp*cos(i * step + t)*sin(angle), amp*chordAmp*sin(i *step + t)*cos(angle), 0.0);
          }
          break;
        case 2:
          for (int i=1; i < (n-1); i++) {
            Particle p1 = (Particle)p.get(i);
            p1.position().add(chordAmp*log(i*step +1.0)*sin(angle), chordAmp*log(i*step +1.0)*cos(angle), 0.0);
          }
          break;
        case 3:
          for (int i=1; i < (n-1); i++) {
            Particle p1 = (Particle)p.get(i);
            p1.position().add(chordAmp*log(i*step +1.0)*sin(i*step +t), chordAmp*log(i*step +1.0)*cos(i*step +t), 0.0);
          }
          break;
        }
    
        nVal += inc;
      }
    
      void moveStart(float x, float y) {
        end.position().set(x, y, 0.0);
      }
    
      void moveEnd(float x, float y) {
        start.position().set(x, y, 0.0);
      }
    
      void setColor(color c) {
        chordColor = c;
      }
    
      void setColorR(float a) {
        color c = color(a, chordColor >> 8 & 0xFF, chordColor & 0xFF);
        chordColor = c;
      }
    
      void setColorG(float a) {
        color c = color( chordColor >> 16 & 0xFF, a, chordColor & 0xFF);
        chordColor = c;
      }
    
      void setColorB(float a) {
        color c = color(chordColor >> 16 & 0xFF, chordColor >> 8 & 0xFF, a);
        chordColor = c;
      }
    }
    
    
    class ChainManager {
      ArrayList<Chain> chain;
    
      ChainManager() {
        chain = new ArrayList<Chain>();
      }
    
      void draw() {
        Iterator<Chain> it = chain.iterator();
        while (it.hasNext ()) {
          Chain p = it.next();
          p.draw();
          p.update();
          if (auto)
            p.moveEnd(auto1.x, auto1.y);
          else
            p.moveEnd(mouseX, mouseY);
        }
      }
    
      void setColors(color c) {
        Iterator<Chain> it = chain.iterator();
        while (it.hasNext ()) {
          Chain p = it.next();
          p.setColor( setGoodColor() );
        }
      }
    
      void pushPos(ParticleSystem physics, int n) { 
        for (int  i =0; i < n; i++)
          push(physics, new PVector(50, height/2), new PVector(width - 100, height/2));
      }
    
      void push(ParticleSystem physics, PVector init, PVector end) {
        chain.add(new Chain(physics, init, end));
      }
    
      void pushCircle(ParticleSystem physics, int n) {
        for (int i =0; i < n; i++) {
          addCircle(physics, n);
        }
      }
    
      void addCircle(ParticleSystem physics, int n) {
        float step = (TWO_PI/n)* (chain.size() - 1);
        chain.add(new Chain(physics, new PVector(width/2 + cos(step)*(radioChords + random(-5, 5) ), height/2 + sin(step)*(radioChords + random(-5, 5)) ), new PVector(width/2, height/2)));
      }
    
      void pop() {
        chain.remove( chain.size() -1 );
      }
    }
    
    
    import controlP5.*;
    import traer.physics.*;
    import toxi.geom.*;
    import java.util.Vector;
    
    ParticleSystem physics;
    
    Automaton auto1;
    ChainManager mChain;
    
    int waveType = 3;
    boolean auto = false;
    boolean drawColorChords = false;
    
    float chordAmp = 0.62;
    float step     = 0.57;
    
    int radioChords = 260;
    
    float alphaBack = 10;
    float cBackground = 0;
    
    PGraphics offScreen;
    void setup() {
      size(1024, 768);
    
      menuSetup(); 
    
      offScreen = createGraphics(width, height, P2D);
    
      physics = new ParticleSystem( 0.0f, 0.05f );
    
      mChain = new ChainManager();
      auto1  = new Automaton(width/2, height/2, 255, 255, 4);
      mChain.pushCircle(physics, 200);
      mChain.setColors(color(0, 0, 0));
    
      offScreen.beginDraw();
      offScreen.smooth();
      offScreen.endDraw();
    
      waveType = 3;
      auto = true;
      drawColorChords = true;
    
      chordAmp = 0.62;
      step     = 0.57;
      alphaBack = 60;
    }
    
    void draw() {
      offScreen.beginDraw();
      offScreen.noStroke();
      offScreen.fill(cBackground, alphaBack);
      offScreen.rect(0, 0, width, height);
      offScreen.endDraw();
    
      physics.tick();
    
      offScreen.beginDraw();
      mChain.draw();
      offScreen.endDraw();
      image(offScreen, 0, 0);
    
      auto1.generate();
    }
    
    
    ControlP5 controlP5;
    ControlWindow controlWindow;
    
    void menuSetup() {
      controlP5 = new ControlP5(this);
      controlP5.setAutoDraw(true);
      //Korg nano-kontrol automatic gui creation
      int x1 = 10;
      int y1 = 10;
    
      controlP5.addSlider("alphaBack", 0, 255, 80, x1, y1, 15, 100);
      controlP5.addSlider("cBackground", 0, 255, 0, x1 + 55, y1, 15, 100);
      controlP5.addSlider("stepV", 0, 1, 0.57, x1, y1 + 120, 15, 100);
      controlP5.addSlider("chordAmpV", 0, 2, 0.62, x1 + 55, y1 + 120, 15, 100);
    
      controlP5.addSlider("waveType", 1, 4, 50, x1 + 15, y1 + 240, 15, 100).setNumberOfTickMarks(4);
    
      controlP5.addToggle("autoV", true, x1+ 130, y1, 30, 30);
      controlP5.addToggle("drawColorChords", true, x1+ 130, y1 + 50, 30, 30); 
    }
    
    void autoV(){
     auto = !auto; 
    }
    void drawColorChords(){
      drawColorChords = !drawColorChords;
    }
    
    void waveType(int a){
      waveType = a;
    }
    
    void alphaBack(float a) {
      alphaBack = a;
    }
    
    void cBackground(float a) {
      cBackground = a;
    }
    
    void stepV(float a) {
      step = a;
    }
    
    void chordAmpV(float a) {
      chordAmp = a;
    }
    
    
    color[] colors ={
                #126886, #107CA2, #1F88AD, #047C5F, #36B99A, #199D7D, #088969,
                #16896D, #125D98, #2779B9, #1EBCB8, #0FAAA6, #18B9B5, #0E3995,
                #11BCB2, #0F7E78, #55C9C2, #247672, #0D6593, #024A6F, #085176,
                #0AAA9B, #19B4A6, #09746A, #1D7E95, #05645F, #2CA099, #2E8972,
                #108E5A, #126B93, #116379, #095367, #096766, #1D9D6D, #097C22,
                #118986, #048683, #1D8986, #088380, #1B817E, #0CA7A4, #25A086,
                #1CBCB8, #0AC4BF, #0C7EAA, #177AA0, #02AF5A, #179EBF, #00D8B2,
                #17A593, #0FB3B7, #07A1A5, #13CCD1, #30BBBF, #05A7E5, #139ACE,
                #1182AD, #1180B9, #038D93, #014043, #066367, #1E7D81, #05575A,
                #118398, #0BB27E, #15BC88, #007F9D, #197389, #034555, #086176,
                #0B5998, #114B79, #078180, #0B4FA0, #107383, #DEFAFF, #DAE8EA,
                #F7F7F7, #FFFFFF, #48CBE0, #478A95, #479579, #A2FFDE, #4B9D7F,
                #C1C1C1, #41BAC9, #2D75AA, #327C77, #097E77, #035550, #077C75
              };
              
              
              
    color setGoodColor(){
       return colors[(int)random(0, colors.length - 1)];
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Thomas Sanchez Lengling

    Chords

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

    Made with toxilibs.
    Each chord is independent.
    With the Auto toggle mouse Control

    AMAZING! Is it possible to export is as a 3d model? (when done with Vec3D)
    Hey!, Of course it can be exported as a 3d model, just by adding the z coordinate but it doesn't look as good as the the 2D version. I'm currently working on a new 3D version, but it needs a lot more modifications of it to look good, when it's ready I'll upload it.
    You need to login/register to comment.