The Mona Lisa Explosion

25Jun10

Processing sketch that destroys and repairs a mona_lisa.jpg

http://www.openprocessing.org/visuals/?visualID=10634

PImage monaLisa;
int num = 330; //number of particles
int mouseState = 0; //int for toggling gravity
int keyState = 0; //int for toggling image reform
 
Pix[][] pix = new Pix[num][num];
 
void setup(){
  monaLisa = loadImage("mona_lisa.jpg");
  size(350, 350, P2D);
  //smooth();
  for (int i=0; i<num; i+=5){
    for (int j=0; j<num; j+=5){
      pix[i][j] = new Pix(i, j, random(-1, 1), random(1, 2), i, j, random(0.1, 0.5), 5);
    }
  }
}
 
void draw(){
  background(25);
 
  for(int i=0; i<num; i+=5){
    for(int j=0; j<num; j+=5){
      color pixel = monaLisa.get(i, j);
      fill(pixel, 200);
      pix[i][j].display();
 
      if(keyState==1){
        mouseState=0;
        pix[i][j].reform();
      }
      else if(mouseState==1){
        keyState=0;
        pix[i][j].move();
      }
    }
  }
}
//toggle gravity
void mousePressed(){
  keyState=0;
  mouseState+=1;
  if (mouseState>1){
    mouseState=0;
  }
}
//toggle reform
void keyPressed(){
  if (key==32){
    keyState+=1;
    mouseState=0;
    if(keyState>1){
      keyState=0;
    }
  }
}
 
class Pix{
  float x, y;
  float nx, ny;
  float ox, oy;
  float gravity;
  int w;
  int del=16;
 
  Pix(float _x, float _y, float _nx, float _ny, float _ox, float _oy, float _gravity, int _w){
    x = _x;
    y = _y;
    nx = _nx; //xspeed
    ny = _ny; //yspeed
    ox = _ox; //original x val 
    oy = _oy; //original y val
    gravity = _gravity;
    w = _w;
  }
 
  void display(){
    noStroke();
    rectMode(CENTER);
    ellipse(x, y, w, w);
  }
 
  void move(){
    x = x+nx+gravity;
    y = y+ny+gravity;
 
    if(y>height || y<0){
      ny = ny * -0.4;
    }
    if(x>width || x<0){
      nx = nx * -0.4;
    }
  }
 
  void reform(){
    x+=(ox-x)/del;
    y+=(oy-y)/del;
  }
}
Advertisements


No Responses Yet to “The Mona Lisa Explosion”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: