A question about looping through the pixels of an image

Hey guys,

I've been trying to solve this for days now, and it's not working. So I'm trying to translate a sketch from Processing to p5.js, and in the sketch, I need to loop through the pixels of an image. Here's the code:

<

script> var img;

function preload() { img = loadImage("img/wa.jpg"); } function setup() { createCanvas(1900, 700); imageMode(); background(255); image(img,0,0); img.loadPixels(); }

function draw() {

stroke(255,0,0); /* for (var j=0; j<img.height; j++){ for (var i=0; i<img.width; i++){ var pixcol = img.get(i,j); } }*/ }

The part that's commented out, the loop, is not working. The image size is 1600x800, so it is inside the canvas entirely. When I try to run the loop, the browser crashes. If I just ask img.get(x,y) for a particular pixel, let's say img.get(500,500), it works just fine. I can't possibly guess what's wrong, I'm new to p5, please help?

Thank you!

Answers

Sign In or Register to comment.