Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

カメラ画像を三次元のボックスで表現する

f:id:aa_debdeb:20151118204310j:plain
/**
* Box Image
*
* @author aa_debdeb
* @date 2015/11/23
*
*/

import processing.video.*;

Capture camera;

void setup(){
  size(640, 480, P3D);
  smooth();  
  camera = new Capture(this, width, height);
  camera.start();
}

void draw(){
  background(255);
  stroke(0);
  fill(200);
  camera.loadPixels();
  for(int x = 5; x < width; x += 10){
    for(int y = 5; y < height; y += 10){
      color rgb = camera.pixels[y * width + x];
      float brightness = map(max(red(rgb), green(rgb), blue(rgb)), 0, 255, 0, 1);
      pushMatrix();
      translate(x, y, 0 + -200 * brightness);
      box(10, 10, 100);
      popMatrix();
    }
  }
}