Pixel array length unexpected

Hello everybody! :slight_smile:
Iโ€™m currently having some unexpected problems with the pixels array.
I have a canvas of 600x300, so I expect the array length to be 600x300x4=720 000.
Instead if I log it I get 4 times that, so 2 880 000.
What am I missing?


Hello @Yra,


A search for pixels at the p5.js site revealed this:

The description has the answer.

Exploring the references is a part of my coding journey.


Thank you both very much.
If course I read the P5 documentation, but evidently did not understand the pixelDensity.
When I console log it, it say 2, so my extra factor of 4 is 2x2.
What itโ€™s not clear to me is:
what use has this? I mean, if an image is 2x5 pixels, I have 10 pixels and RGBA for each tallies up to 40 elements of an array. If this is suddendly 4 times as long, what other information do i have in this 160 long array?!


From the reference for pixelDensity() :

Calling pixelDensity() with no arguments returns the current pixel density of the sketch.

Can you try this and what does it return?


Thanks for the answer @glv
When I log it, the value is 2.

1 Like

Hi @GoToLoop @glv o you have any other suggestion?


This image here may help you understand:

Set it to pixelDensity(1) to see the difference.