マウスのある位置の色を表示する


import processing.video.*;
Capture camera;

void setup() {
  size(480, 320);
  camera = new Capture(this, width, height, Capture.list()[2], 12);
  smooth();
  noStroke();
}

void draw() {
  background(0);
  
  noStroke();
  camera.loadPixels(); //カメラ画像のpixel情報を読み込み
  int d = 1; //円の直径を定義
  // ライブカメラの映像から、円の直径の間隔ごとに、色情報を取得し、その色で円を描く
  for(int y = d / 2 ; y < height ; y += d) {
    for(int x = d / 2 ; x < width ; x += d) {
      fill(camera.pixels[y * width + x]);
      ellipse(x, y, d, d);
    }
  }
  
  text(
    "X="+mouseX + " " +
    "Y="+mouseY + " " + 
    "R="+red(camera.pixels[mouseY * width + mouseX])   + " " +
    "G="+green(camera.pixels[mouseY * width + mouseX]) + " " +
    "B="+blue(camera.pixels[mouseY * width + mouseX])  + " "
    ,10
    ,20
  );
  
  stroke(256,0,0);
  strokeWeight(3);
  noFill();
  ellipse(mouseX, mouseY, 20, 20);

  
} 

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