• fullscreen
  • Damper.pde
  • Particle.pde
  • nov13a_2011_iridescence.pde
  • class Damper{
      float x, y;
      float w, h;
      Damper(float w_,float h_) {
        x = width/2;
        y = height/2;
        w = w_;
        h = h_;
      }
      void movement() {
        x = lerp(x, mouseX, 0.3);
        y = lerp(y, mouseY, 0.3);
      }
      void display() {
        fill(100, 50);
        noStroke();
        rect(x, y, w, h);
      }
    }
    
    
    class Particle {
      float x, y;
      float xSpeed, ySpeed;
      float yAccel;
      float thres, areaThres;
      float satu;
      color c;
      Particle() {
        satu = 0;
        x = random(width);
        y = random(height);
        xSpeed = random(0.5, 3);
        ySpeed = random(0.5, 2);
        yAccel = random(0.1, 0.4);
        thres = 75;
        areaThres = 2000;
        c = color(random(360), 255, 255);
      }
      void movement(Damper damper) {
        ySpeed += yAccel;
        ySpeed = constrain(ySpeed, -5, 5);
        x += xSpeed;
        y += ySpeed;
        collisionTest(damper);
      }
      void collisionTest(Damper damper){
        if (x<0 || x>width) {
          xSpeed = -xSpeed;
        }
        if (y>height) {
          reset();
        }
        if (y>=mouseY-damper.h/2 && y<=mouseY+damper.h/2 && x>=mouseX-damper.w/2 && x<=mouseX+damper.w/2) {
          y=mouseY-10;
          ySpeed =-ySpeed*0.95;
          satu = 255;
        }
      }
      void  display() {
        strokeWeight(3);
        stroke(c, 100);
        point(x, y);
      }
      void ligature(Particle particle_) {
        float distance = dist(x, y, particle_.x, particle_.y);
        if (distance < thres) {
          float averageHue = (hue(c)+hue(particle_.c))/2;
          stroke(averageHue, satu, 255, (thres-distance)*(255/thres));
          strokeWeight((thres-distance)/10);
          line(x, y, particle_.x, particle_.y);
        }
      }
      void drawTri(Particle particle1_, Particle particle2_) {
        float distance1 = dist(x, y, particle1_.x, particle1_.y);
        float distance2 = dist(x, y, particle2_.x, particle2_.y);
        float distance3 = dist(particle1_.x, particle1_.y, particle2_.x, particle2_.y);
        float l = (distance1+distance2+distance3)/2;
        float s = sqrt(l*(l-distance1)*(l-distance2)*(l-distance3));
        if (s < areaThres && distance1<thres && distance2<thres && distance3<thres) {
          noStroke();
          float averageHue = (hue(c)+hue(particle1_.c)+hue(particle2_.c))/3;
          fill(averageHue, satu, 255, 255-(s*255/areaThres));
          beginShape();
          vertex(x, y);
          vertex(particle1_.x, particle1_.y);
          vertex(particle2_.x, particle2_.y);
          endShape(CLOSE);
        }
      }
      void reset() {
        y = 0;
        satu = 0;
      }
    }
    
    //Raven Kwok | 郭锐文
    //Email: raystain@gmail.com
    //Blog: the-moor.blogbus.com
    //Vimeo: vimeo.com/ravenkwok
    //Weibo: weibo.com/ravenkwok
    
    Damper damper;
    Particle [] particles = new Particle[50];
    
    void setup() {
      size(400, 600, P3D);
      frameRate(30);
      background(255);
      colorMode(HSB);
      rectMode(CENTER);
      for (int i=0;i<particles.length;i++) {
        particles[i] = new Particle();
      }
      damper = new Damper(100,20);
      smooth();
    }
    void draw() {
      background(255);
      for (int i=0;i<particles.length;i++) {
        particles[i].movement(damper);
        for (int j=i+1;j<particles.length;j++) {
          for (int k=j+1;k<particles.length;k++) {
            particles[i].drawTri(particles[j], particles[k]);
          }
          particles[i].ligature(particles[j]);
        }
        particles[i].display();
      }
      damper.movement();
      damper.display();
    }
    
    

    code

    tweaks (1)

    about this sketch

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

    license

    advertisement


    Raven Kwok
    Kles4enko Andrey
    16 Mar 2012
    Hohow!!!
    hello

    cant download properly or in other words the three sketches are not interconnected there is something missing

    help
    please i like the irigescence very much

    thanks
    Raven Kwok
    23 Mar 2012
    You may directly copy the code and then paste in your Processing IDE, the sketch doesn't use a 3rd party library :)
    redkhat plus+
    18 Oct 2012
    magic confetti. excellent!
    You need to login/register to comment.