Amazon Shopping Mall

Interactive Processing Programming

All about Processing(The Interactive Multimedia Programming)


The world today has constantly become in-tune with its environment. Humans no longer want to do things by themselves. The edge of developing tools and systems to work on our behalf has become a top priority. Most people will be wondering why we want to keep improving our world but the answer is simple. And this is because we want to make it a better place. As to whether the discovery and improvement of technology is a 'blessing or a curse' is a statement to debate some other time. However, if you want to share your view on other, you can send in your comments.

So why all this introduction? 
Well, I want to introduce a very important way of programming interactively. For those of my readers who already know how to programme Processing, this is an added advantage. Otherwise for those of you hearing it the first time, please get your PC, arduino board and lets get started. 

What is Processing?
Processing is just a tool or language to help you achieve building of interactive applications. 

For more on how to download Go to Processing Programming Website.

                    THE CLUBBING PROJECT 

This project can be used in the house, clubs and public entertainment places. It has the ability to track motions and uses these motions to enlarge colored smaller(initial size) balls just like disco lights or clubbing lights. It can also track light hence this software is best displayed or shown in the dark for a more beautiful and colorful display.

The amazing thing is that it is accompanied by music. So upload any music you like and you are ready to turn your house into a club house.

              Final Project Presentation Video 
                   



                   The code

//sound
import ddf.minim.*;

Minim minim;
AudioPlayer player;
//sound

import processing.video.*;

// Variable for capture device
Capture video;


// Previous Frame
PImage prevFrame;

// How different must a pixel be to be a "motion" pixel
float threshold = 50;

//square
// Two variables for color.
float c1 = 0;     
float c2 = 255;   
// Start by incrementing c1.
float c1dir = 30; 
// Start by decrementing c2.
float c2dir = -30;
//square

void setup() {
  size(640,480);
  // we pass this to Minim so that it can load files from the data directory
  minim = new Minim(this);
 
  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("Party Rock Anthem (Audio).mp3");
 
  // play the file
  player.play();
 
  // Using the default capture device
  video = new Capture(this, width, height);
  video.start();
  // Create an empty image the same size as the video
  prevFrame = createImage(video.width,video.height,RGB);
  noStroke();
  smooth();
}

void draw() {
 
  background(0);
 
  // You don't need to display it to analyze it!
  image(video,0,0);
 
  // Capture video
  if (video.available()) {
    // Save previous frame for motion detection!!
    prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height);
    prevFrame.updatePixels();
    video.read();
    image(video, 0, 0, width, height); // Draw the webcam video onto the screen
    int brightestX = 0; // X-coordinate of the brightest video pixel
    int brightestY = 0; // Y-coordinate of the brightest video pixel
    float brightestValue = 0; // Brightness of the brightest video pixel
    // Search for the brightest pixel: For each row of pixels in the video image and
    // for each pixel in the yth row, compute each pixel's index in the video

 
  loadPixels();
  video.loadPixels();
      int index = 0;
    for (int y = 0; y < video.height; y++){
      for (int x = 0; x < video.width; x++){
        // Get the color stored in the pixel
        int pixelValue = video.pixels[index];
        // Determine the brightness of the pixel
        float pixelBrightness = brightness(pixelValue);
        // If that value is brighter than any previous, then store the
        // brightness of that pixel, as well as its (x,y) location
        if (pixelBrightness > brightestValue) {
          brightestValue = pixelBrightness;
          brightestY = y;
          brightestX = x;
        }
        index++;
     }
    }
     fill(255, 204, 0, 128);
    ellipse(brightestX, brightestY, 200, 200);
  }
  prevFrame.loadPixels();
 
  // Begin loop to walk through every pixel
  // Start with a total of 0
  float totalMotion = 0;
 
  // Sum the brightness of each pixel
  for (int i = 0; i < video.pixels.length; i ++ ) {
    // Step 2, what is the current color
    color current = video.pixels[i];
   
    // Step 3, what is the previous color
    color previous = prevFrame.pixels[i];
   
    // Step 4, compare colors (previous vs. current)
    float r1 = red(current);
    float g1 = green(current);
    float b1 = blue(current);
    float r2 = red(previous);
    float g2 = green(previous);
    float b2 = blue(previous);
   
    // Motion for an individual pixel is the difference between the previous color and current color.
    float diff = dist(r1,g1,b1,r2,g2,b2);
    // totalMotion is the sum of all color differences.
    totalMotion += diff;
  }
 
  // averageMotion is total motion divided by the number of pixels analyzed.
  float avgMotion = totalMotion / video.pixels.length;
 
  // Draw a circle based on average motion
  smooth();
  noStroke();
  fill(255);
  float r = avgMotion*2;
  ellipse(random(width),random(height),r,r);
 
    fill(c2,0,c1);
  float rrrrrr = avgMotion*2;
  ellipse(random(width),random(height),r,r);
 
 
 
  //suqare
   noStroke();
 
  // Draw rectangle of down right
  fill(c2,255,c1);
  float rr = avgMotion*5;
  rect(0,0,20,20,r,r,r,r);

 // Draw rectangle of down right
  fill(c2,240,c1);
  float rrr = avgMotion*5;
  rect(620,0,20,20,r,r,r,r);

 // Draw rectangle of down right
  fill(c2,220,c1);
  float rrrr = avgMotion*5;
  rect(620,460,20,20,r,r,r,r);

 // Draw rectangle of down right
  fill(c2,100,c1);
  float rrrrr = avgMotion*5;
  rect(0,460,20,20,r,r,r,r);
 




   //Adjust color values
  c1 = c1 + c1dir;
  c2 = c2 + c2dir;

   //Instead of reaching the edge of a window, these variables reach the "edge" of color: 
   //0 for no color and 255 for full color. 
  // When this happens, just like with the bouncing ball, the direction is reversed.

  // Reverse direction of color change
  if (c1 < 0 || c1 > 255) {
    c1dir *= -1;
  }

  if (c2 < 0 || c2 > 255) {
   c2dir *= -1;
  }
}


             

Please share this and leave a comment. Thanks. 



No comments:

Post a Comment

Please send me your comments