let video, offset, offset1, graph;
createCanvas(windowWidth, windowHeight);
video = createCapture(VIDEO);
graph = createGraphics(video.width,video.height);
translate(width/2 - video.width/2,height/2 - video.height/2);
chunk = createImage(video.width, video.height);
for (let x = 0; x < video.width; x+=1) {
for (let y = 0; y < video.height; y+=1) {
var index = (video.width * y + x) * 4;
if(y > video.height*0.15 & y < video.height*0.25)
let n = floor(noise(y*y*0.01 + offset) * 50);
let chunk_index = (index - (n*4)) % (video.width*video.height*4);
let r = lightenPixelWithNoise(x, y, graph.pixels[chunk_index]);
let g = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 1]);
let b = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 2]);
let a = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 3]);
chunk.pixels[index + 0] = r
chunk.pixels[index + 1] = g
chunk.pixels[index + 2] = b
chunk.pixels[index + 3] = a
else if(y > video.height*0.25 & y < video.height*0.5)
let n = floor(noise(y*0.01 + offset) * 100);
let chunk_index = (index - (n*4)) % (video.width*video.height*4);
let r = lightenPixelWithNoise(x, y, graph.pixels[chunk_index]);
let g = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 1]);
let b = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 2]);
let a = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 3]);
chunk.pixels[index + 0] = r
chunk.pixels[index + 1] = g
chunk.pixels[index + 2] = b
chunk.pixels[index + 3] = a
else if(y > video.height*0.5 & y < video.height*0.6)
let n = floor(noise(y*y*0.01 + offset) * 50);
let chunk_index = (index - (n*4)) % (video.width*video.height*4);
let r = lightenPixelWithNoise(x, y, graph.pixels[chunk_index]);
let g = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 1]);
let b = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 2]);
let a = lightenPixelWithNoise(x, y, graph.pixels[chunk_index + 3]);
chunk.pixels[index + 0] = r
chunk.pixels[index + 1] = g
chunk.pixels[index + 2] = b
chunk.pixels[index + 3] = a
toggleVideo = !toggleVideo;
graph.line(40,40,graph.width - 40,40);
graph.line(40,graph.height - 40,graph.width - 40,graph.height - 40);
graph.line(graph.width - 40,40,graph.width - 40,graph.height - 40);
graph.line(40,40,40,graph.height - 40);
let sec = int(0.001 * millis())
graph.text("TC: "+ (int(sec / 3600) % 3600).toFixed(0).padStart(2,0) + "." + (int(sec / 60) % 60).toFixed(0).padStart(2,0) + "." + sec.toFixed(0).padStart(2,0), 40, graph.height - 20);
function lightenPixelWithNoise(x, y, pixelValue)
let n = noise(frameCount + (noise(x)*2) + offset1,frameCount + y + offset1);
let val = (255 - pixelValue) * easeInSine(n) + pixelValue;
return 1 - cos((x * PI) / 2);