xxxxxxxxxx
42
/*Danny Rozin
Kinetic Sculpture Workshop 25
camera as color sensor */
let capture;
let R = 0,
G = 0,
B = 0; // will hold the rolling value of the colors
function setup() {
createCanvas(400, 300);
capture = createCapture(VIDEO); // initiate the capture object
capture.size(width, height); // define the capture size
capture.hide(); // make it not show on HTML
frameRate(30); // we want things to happen slowly like reall life motors
}
function draw() {
background(0, 0, 0);
image(capture, 0, 0, width / 4, height / 4); // show the live video in the corner
let pixi = capture.get(width / 2, height / 2); // get the pixel in the center
let currentR = red(pixi); // get the r,g,b values seperately
let currentG = green(pixi);
let currentB = blue(pixi);
print(pixi);
fill(pixi);
circle(width / 8, height / 8, 10); //show the current color in the corner
if (currentR > R) R++;else if (currentR < R) R--;// make the colors change gradually
fill(255, 0, 0);
circle(width / 2, height / 4, R ); // draw red circle, size of R
if (currentG > G) G++;else if (currentG < G) G--;
fill(0, 255, 0);
circle(width / 4, height * 0.66, G ); // draw green circle, size of G
if (currentB > B) B++;else if (currentB < B) B--;
fill(0, 0, 255);
circle(width * 0.75, height * 0.66, B); // draw green circle, size of B
}