• fullscreen
  • Chain.pde
  • chains.pde
  • class Chain {
    
    
      PVector pos;
      Chain n;
      int id;
      float d, theta;
      float x1, x2, y1, y2;
      PGraphics mapa;
    
    
      Chain(int _id) {
        id = _id;
    
        if (id==0)
          n = this;
        else
          n = (Chain)chain.get(id-1);
    
        mapa = createGraphics(120, 120, JAVA2D);
        mapa.beginDraw();
        mapa.textFont(font,110);
        mapa.fill(0);
        mapa.textAlign(CENTER);
        mapa.text(reversed.charAt(reversed.length()-1-(id%reversed.length())), mapa.width/2, mapa.height-30);
        mapa.scale(-1, 1);
    
        mapa.endDraw();
    
    
        theta = 0;
        pos = new PVector(-90, height/2);
      }
    
      void update() {
        if (id==0) {
          pos.x += (mouseX-pos.x)/1.1;
          pos.y += (mouseY-pos.y)/1.1;
        }
        else {
    
          pos.x += (n.pos.x-pos.x)/(10.1);
          pos.y += (n.pos.y-pos.y)/(10.1);
         // d = noise(id/30.0)*96*2;//
          //d += (n.d-d)/10.001;
          d = dist(pos.x, pos.y, n.pos.x, n.pos.y);//(dist(pos.x, pos.y, n.pos.x, n.pos.y)-d)/20.1; 
         
    
          theta = atan2(n.pos.y-pos.y, n.pos.x-pos.x);
        }
    
    
    
        pushMatrix();
        translate((pos.x+n.pos.x)*.5, (pos.y+n.pos.y)*0.5);
    
    
    
    
        x1 = screenX(cos(theta+QUARTER_PI)*d, sin(theta+QUARTER_PI)*d);
        y1 = screenY(cos(theta+QUARTER_PI)*d, sin(theta+QUARTER_PI)*d);
    
        x2 = screenX(cos(theta-QUARTER_PI)*d, sin(theta-QUARTER_PI)*d);
        y2 = screenY(cos(theta-QUARTER_PI)*d, sin(theta-QUARTER_PI)*d);
    
        popMatrix();
      }
    
      void draw() {
    
    
    
        fill(0,0);
        noStroke();
        beginShape();
        tint(255,d*12);
        texture(mapa);
        vertex(x2, y2, 0, 0);
        vertex(n.x2, n.y2, mapa.width, 0);
        vertex(n.x1, n.y1, mapa.width, mapa.height);
        vertex(x1, y1, 0, mapa.height);
    
    
    
        endShape(CLOSE);
        
        /*
         stroke(0, 100);
         line(x1, y1, n.x1, n.y1);
         line(x2, y2, n.x2, n.y2);
        
        switch(phase) {
         case 0:    
         triangle(
         x2, y2, 
         x1, y1, 
         n.x1, n.y1
         );
         break;
         case 1:
         triangle(
         x2, y2, 
         n.x2, n.y2, 
         n.x1, n.y1
         );
         break;
         
         
         case 2:
         
         triangle(
         x1, y1, 
         n.x2, n.y2, 
         n.x1, n.y2
         );
         break;
         
         
         case 3:
         triangle(
         x1, y1, 
         n.x1, n.y1, 
         x1, y2
         );
         break;
         }
         */
        /*
        quad(
         x1, y1, 
         x2, y2, 
         n.x2, n.y2, 
         n.x1, n.y1
         );*/
      }
    }
    
    
    /*
    *  Dada data dada data code by kof 2012
     */
    
    
    ArrayList chain = new ArrayList();
    
    color c;
    PFont font;
    
    String tex[], plain, reversed;
    
    
    int num = 400;
    
    String reverseWords(String input[]) {
    
      String in = "";
      for (int i =0 ; i < input.length;i++)
        in += input[i]+" ";
    
      String tmp[] = splitTokens(in, " ");
      String out = "";
      for (int i = 0;i<tmp.length;i++) {
        out += new StringBuffer(tmp[i]).reverse().toString() +" ";
      }
      out = new StringBuffer(out).reverse().toString();
      return out;
    }
    
    void setup() {
      size(600, 350, P2D);
    
      c = color(random(255), random(255), random(255));
    
      tex = loadStrings("chains.pde");
      reversed = reverseWords(tex);
    
    
      font = loadFont("Aller-Light-120.vlw");
    
    
      for (int i  =0;i<num;i++)
        chain.add(new Chain(i));
    
      //smooth();
    
      noFill();
      background(0);
    
      colorMode(HSB, 255);
    }
    
    
    void draw() {
    
      hint(DISABLE_DEPTH_TEST);
    
      background(255);
      /*
     
       mapa.beginDraw();
       for (int i =0 ;i<mapa.width;i++) {
       mapa.stroke(0);
       mapa.line(i, 0, i, mapa.height);
       }
       mapa.endDraw();
       */
    
      noStroke();
      noFill();
    
      for (int i =0 ; i < chain.size();i++) {
        Chain c  = (Chain)chain.get(i);
        c.update();
      }
    
      for (int i =chain.size()-1 ; i > 0 ;i--) {
        Chain c  = (Chain)chain.get(i);
        c.draw();
      }
    }
    
    void shapeIt() {
    
      for (int z = 10;z<30;z+=5) {
        stroke(0, 30);
        strokeWeight(z);
    
        noFill();
        beginShape();
        Chain c  = (Chain)chain.get(0);
        vertex(c.x1, c.y1);
        for (int i =0 ; i < chain.size();i++) {
    
    
          c  = (Chain)chain.get(i);
    
          curveVertex(c.x1, c.y1);
        }
    
        endShape();
    
        beginShape();
        c  = (Chain)chain.get(chain.size()-1);
        vertex(c.x2, c.y2);
        for (int i = chain.size()-1 ; i > 0 ;i--) {
    
    
          c  = (Chain)chain.get(i);
    
          curveVertex(c.x2, c.y2);
        }
        c  = (Chain)chain.get(chain.size()-1);
        vertex(c.x2, c.y2);
        endShape();
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Report Sketch

    Report for inappropriate content

    Please provide details if possible:

    Your have successfully reported the sketch. Thank you very much for helping to keep OpenProcessing clean and tidy :)

    Make a Copyright Infringement claim

    Kryštof Pešek (Kof)

    Data Dada

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

    Any program which is reading it's source code is my favorite metaphor for helpless human efforts to understand the meaning of life.

    a good illustration of such helplessness:

    http://en.wikipedia.org/wiki/Meaning_of_life

    (notice the number of references at very bottom, it seems you can probably find the answer.. elsewhere)

    You need to login/register to comment.