Daily Creative Coding

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

映像のRGBの各層をずらす

f:id:aa_debdeb:20151106215744j:plain
/**
*  Video with Shifted RGB Layers
*
* @author aa_debdeb
* @date 2015/11/09
*/

import processing.video.*;

Capture camera;
PVector rDiff = new PVector(-50, -50);
PVector gDiff = new PVector(50, -50);
PVector bDiff = new PVector(0, 100);


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

void draw(){
  camera.loadPixels();
  loadPixels();
  for(int x = 0; x < width; x++){
    for(int y = 0; y < height; y++){
      int rX = x + int(rDiff.x);
      int rY = y + int(rDiff.y);
      int gX = x + int(gDiff.x);
      int gY = y + int(gDiff.y);
      int bX = x + int(bDiff.x);
      int bY = y + int(bDiff.y);
      float r = (0 <= rX && rX < width && 0 <= rY && rY < height) ? red(camera.pixels[rY * width + rX]): 0;
      float g = (0 <= gX && gX < width && 0 <= gY && gY < height) ? green(camera.pixels[gY * width + gX]): 0;
      float b = (0 <= bX && bX < width && 0 <= bY && bY < height) ? blue(camera.pixels[bY * width + bX]): 0;
      pixels[y * width + x] = color(r, g, b);
    }
  }
  updatePixels();
}

void mousePressed(){
  saveFrame("images/image.jpg");
}

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