How to iterate video.pixels.length for random area of image

the sampled color still drawn beyond that x and y value

If you don’t want to sample beyond x < 100 and y > 240 then you’ve got to limit where the mouse traps clicks. I’ve shown you this code previously. The last post of this thread:https://discourse.processing.org/t/how-to-iterate-over-2d-region-with-1d-pixels-array/39336/23

One change would be to not use the counter but use the most recent code that was posted above; ie, use id = x + y*width.