/** * HotDotShot (blech) by Srikanth Narayan * Date 3 Oct 2007 * * Based on Mirror 2 by Daniel Shiffman. * * Each pixel from the video source is drawn as a rectangle with size based on brightness. */ import processing.video.*; import processing.serial.*; // Size of each cell in the grid int cSize = 5; // Number of columns and rows in our system int cols, rows; // Variable for capture device Capture video; Serial port; String buf = ""; String portname = "/dev/tty.usbserial-A4001nCl"; int cr = 13; // ASCII return == 13 int lf = 10; // ASCII linefeed == 10 int colour =268; int shot=0; int shotPrevious=0; //PImage scrShot; void setup() { size(630, 480, P3D); //set up columns and rows cols = width / cSize; rows = height / cSize; colorMode(RGB, 255, 255, 255, 100); rectMode(CENTER); // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 15); port = new Serial(this, portname, 9600); //scrShot = new PImage(640, 480); background(0); } void draw() { if (video.available()) { //println("########################"); video.read(); video.loadPixels(); background(0, 0, 0); // Begin loop for columns for (int i = 0; i < cols;i++) { // Begin loop for rows for (int j = 0; j < rows;j++) { // Where are we, pixel-wise? int x = i * cSize; int y = j * cSize; int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image // Each rect is colored white with a size determined by brightness color c = video.pixels[loc]; float sz = (brightness(c) / 255.0) * cSize; fill(colour%255, colour%512, colour%768); //fill(c); noStroke(); //rect(x + cellSize/2, y + cellSize/2, sz, sz); ellipse(x + cSize/2, y + cSize/2, sz, sz); } } } } void serialEvent(Serial p) { int c = port.read(); if (c != lf && c != cr) { buf += char(c); } if (c == lf) { String[] values = buf.split(","); cSize = int(values[2])/50; if(cSize < 5) { cSize = 5; } if(cSize > 20) { cSize = 20; } cols = width / cSize; rows = height / cSize; println("csize "+ cSize); colour = int(values[1]); println("colour"+ colour); shotPrevious = shot; shot = int(values[0]); println("shot "+ shot); if(shot - shotPrevious > 250) { saveFrame(shot+".jpg"); } buf = ""; } }