Powered By Blogger

Thursday 14 April 2011

Final Code - Transformation

// Import Sound Library
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

Minim m;
AudioPlayer mplayer;


// Import image for background.
import processing.pdf.*;
PImage img;


// Number of circles being drawn in each frame of the animation.
int N = 450;
Particle particles[] = new Particle[N];


void setup(){
  size(500,500);


  m = new Minim(this);
  
  // Image being used in background (because I did not like the previous gradient palette being used)
  img = loadImage("http://2.bp.blogspot.com/_wb8bAl1P-N0/TOFKkD6iQII/AAAAAAAARyQ/mmGzMbjvVrk/s1600/blue-sky.jpeg");
  img.resize(width, height);
  background(img);
  
  createParticles();


}

void draw(){
  
//This prevents the sketch from building up and redraws the animation each frame
  for(int i=0; i<width; i++){
     image(img,0,0,width,height);
     line(0,i,width,i);
  }
   


 //Defines class Particle and it's objects being drawn.
 for(int j=0; j<N; j++){
      particles[j].move();
      particles[j].mouse();
  }
  
}

void createParticles(){
  
   // This creates the "particles" for each frame


    for(int i=0; i<N; i++){
        particles[i] = new Particle(random(width), random(height), int(random(100)));
    }
  
}



class Particle{
// This is a class, which contains a composite of functions and data.  


    float x;
    float y;
    int s;
     
     Particle(float _x, float _y,  int _s){
        x = _x;
        y = _y;
        s = _s;
        
    }
     
    void move(){
      
        // This is where the movement of the circles across the screen is defined


        x += random(6);
        y += random(5) - 2;
         
        if(x<0) x = width;
        if(x>width) x = 0;
        if(y<0) y = height;
        if(y>height) y = 0;
        
    }
    
    void mouse(){
   
    // This is where the mouse interaction is defined.


     if(mousePressed){
      
        smooth();
        noStroke();
        float dia = dist(x, y, mouseX, mouseY);
        dia = constrain (dia,0,150);
        fill(240,random(10,15)); 
        ellipse( x, y, dia, dia);
     }
     else {
     
       // This is where the animation is told to continue if the mouse is not pressed


         smooth();
         noStroke();
         fill(240,random(10,15)); 
         ellipse( x, y, 150, 150);
     
      }
    }
}




void mousePressed(){
    //This Function starts the wind sound (at the same time of the void mouse() function and then loops it so that the sound continues infinitely.
       mplayer = m.loadFile("wind_final.wav");
       mplayer.loop();


}



Below are a couple of screen shots of the interaction...


No comments:

Post a Comment