11/4 in class

Processing
Visualize an analog sources from sensor's input
* Using the brightness of video capture input instead of variable from sensors



import processing.video.*;
Capture myCapture;
int cellsize = 3;
int cols, rows;   
PFont font;



void setup () {
  size(400, 300);        
  cols = width/cellsize;            
  rows = height/cellsize;      
  frameRate(30);
 myCapture = new Capture(this, width, height, 30);


}


void captureEvent (Capture myCapture) {
  myCapture.read();
  }
  
void draw () {


  background(0);
  loadPixels();
  for ( int i = 0; i < cols;i++) {
    for ( int j = 0; j < rows;j++) {
      int x = i*cellsize + cellsize/2; 
      int y = j*cellsize + cellsize/2; 
      int loc = x + y*width;           // Pixel array location
      color c = myCapture.pixels[loc];       // Grab the color
      float z = (mouseX/(float)width) * brightness(myCapture.pixels[loc]) - 20 ;
      
      
     println(loc);   
     stroke(123,128,158);
     line(cellsize, height, cellsize, height - loc);
      if (cellsize >= width) {
      cellsize = 0;
   
    background(48,31,65); 
  } 
  else {
    // increment the horizontal position for the next reading:
    cellsize++;
  }
   
     }
    
  }
    
}

No comments:

Post a Comment