xxxxxxxxxx
97
let capture;
let video;
let side=8;
let vScale=200;
let osc=[];
function setup() {
createCanvas(640, 480);
pixelDensity(1);
video = createCapture(VIDEO);
video.size(width/vScale, height/vScale);
osc0 = new p5.Oscillator();
osc1 = new p5.Oscillator();
osc2 = new p5.Oscillator();
osc3 = new p5.Oscillator();
osc0Params()
osc1Params()
osc2Params()
osc3Params()
}
function draw() {
background(20,20);
video.loadPixels();
for (let y = 0; y < video.height; y++) {
for (let x = 0; x < video.width; x++) {
let index = (video.width - x + 1 + (y * video.width))*4;
let r = video.pixels[index+0];
let g = video.pixels[index+1];
let b = video.pixels[index+2];
let bright = (r+g+b)/3;
let w = map(bright, 0, 255, 0, vScale);
let vol = map(bright, 0, 255, 0, 1);
strokeWeight(0);
fill(200,100,0);
rectMode(CENTER);
ellipse((x*vScale)+90,(y*vScale)+90, w, w);
osc0.freq((y/2)*(w/2)*2);
osc1.freq((x/2)*(w/2)*3);
osc2.freq(y*(w/2)*5);
osc3.freq(x*(w/2)*8);
}
}
// tint(100,200,0);
// // image(capture, 0, 0);
// // filter(INVERT);
// let w =capture.width;
// let h =capture.height;
// copy(capture, w/2, 0, 1, h, x, 0, 1, h);
// x++
// // filter(THRESHOLD, 0.3);
// if (x>width){
// x=0
// }
}
function osc0Params() {
osc0.setType('sine');
osc0.freq(120+(random(2)));
osc0.amp(0.3, 5);
osc0.start();
}
function osc1Params(){
osc1.setType('sine');
osc1.freq(30+(random(1)));
osc1.amp(0.3, 5);
osc1.start();
}
function osc2Params(){
osc2.setType('sine');
osc2.freq(30);
osc2.amp(0.3, 8);
osc2.start();
}
function osc3Params(){
osc3.setType('sine');
osc3.freq(30+(random(4)));
osc3.amp(0.3, 13);
osc3.start();
}