Daily Creative Coding

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

カメラから取得した映像を白黒ドットに変換する

f:id:aa_debdeb:20151218231741j:plain
/**
* Binary Dot Camera
*
* @author aa_debdeb
* @date 2015/12/30
*/

import processing.video.*;

float radious = 8;

Capture camera;

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

void draw(){
  background(255);
  camera.loadPixels();
  fill(0);
  for(int x = 0; x < width; x += radious){
    for(int y = 0; y < height; y += radious){
      color c = camera.pixels[y * width + x];
      float gray = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
      if(gray <  map(mouseX, 0, height, 0, 255)){
        ellipse(radious / 2 + x, radious / 2 + y, radious * 0.8, radious * 0.8);
      }
    }
  }
}

void captureEvent(Capture camera){
  camera.read();
}