/* Physical Image: Portrait in Triangles Joshua Clayton Adapted from Mirror 2 by Daniel Shiffman */ import processing.video.*; import processing.dxf.*; boolean record; // Size of each cell in the grid int cellSize = 12; // Number of columns and rows in our system int cols, rows; // Variable for capture device Capture video; void setup() { size(640, 480, P3D); //set up columns and rows cols = width / cellSize; rows = height / cellSize; colorMode(RGB, 255, 255, 255, 100); // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 15); background(0); } void keyPressed() { // use a key press so that it doesn't make a million files if (key == 'r') record = true; } void draw() { if (video.available()) { if (record) { beginRaw(DXF, "output.dxf"); } video.read(); video.loadPixels(); background(255); // 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 * cellSize; int y = j * cellSize; 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) * cellSize; noStroke(); fill(0); triangle(x, y, x + (sz*0.5), y - (sz*0.75), x - (sz*0.5), y - (sz*0.75)); } } } if (record) { endRaw(); record = false; } }