I am using a video input to draw onto a canvas in order to get the color of the pixel in the very middle of the canvas.
With the recent code I have the pixel color and pass it as a color value to draw a line. This line should run from left to right drawing the different colors of the video onto the canvas and add up with every line. But the line seems to be overwritten with every frame. Only one line is displayed which is moving from left to right. Can someone help me understand why and how I can change this behavior?
Thank you very much in advance.
let movie;
let playButton;
let movieInput = "/public/IMG_1569.m4v";
var playing = false;
function setup() {
let canvas = createCanvas(534, 300);
pixelDensity(1);
movie = createVideo(movieInput);
movie.size(width, height);
playButton = createButton("play").addClass("button");
playButton.mouseClicked(playVideo);
}
function draw() {
if (playing) {
movie.loadPixels();
var i = image(movie, 0, 0, width, height);
let pixelColor = get(width / 2, height / 2);
background(255);
let px = frameCount % width;
stroke(pixelColor);
var fineLine = line(px, 0, px, height);
}
}
function playVideo() {
if (playing) {
movie.pause();
playButton.html("play");
} else {
movie.play();
playButton.html("pause");
}
playing = !playing;
}