# Pixel array length unexpected

**URL:** <https://discourse.processing.org/t/pixel-array-length-unexpected/38963>\
**Category:** Beginners\
**Created:** [September 24, 2022, 10:08pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963 "2022-09-24T22:08:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yra](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@Yra](https://discourse.processing.org/u/Yra)\
**Post date:** [September 24, 2022, 10:08pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/1 "2022-09-24T22:08:52Z")

</div>

Hello everybody! 🙂  
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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 24, 2022, 10:18pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/2 "2022-09-24T22:18:15Z")

</div>

[**pixelDensity()**](https://p5js.org/reference/#/p5/pixelDensity)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 24, 2022, 10:26pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/3 "2022-09-24T22:26:57Z")

</div>

Hello @Yra,

> [@Yra](#):
>
> What am I missing?

Research.

A search for _pixels_ at the p5.js site revealed this:  
[https://p5js.org/reference/#/p5/pixels](https://p5js.org/reference/#/p5/pixels)

The description has the answer.

Exploring the references is a part of my coding journey.

`:)`

---

<div class="post-metadata">

**Author:** ![Yra](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@Yra](https://discourse.processing.org/u/Yra)\
**Post date:** [September 24, 2022, 11:49pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/4 "2022-09-24T23:49:38Z")

</div>

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?!

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 25, 2022, 12:37am UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/5 "2022-09-25T00:37:27Z")

</div>

Hello,

From the reference for` pixelDensity`() :

> Calling [pixelDensity()](https://p5js.org/reference/#/p5/pixelDensity) with no arguments returns the current pixel density of the sketch.

Can you try this and what does it return?

`:)`

---

<div class="post-metadata">

**Author:** ![Yra](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@Yra](https://discourse.processing.org/u/Yra)\
**Post date:** [September 25, 2022, 9:32am UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/6 "2022-09-25T09:32:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yra](https://avatars.discourse-cdn.com/v4/letter/y/a698b9/32.png) [@Yra](https://discourse.processing.org/u/Yra)\
**Post date:** [September 27, 2022, 6:51pm UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/7 "2022-09-27T18:51:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 28, 2022, 12:26am UTC](https://discourse.processing.org/t/pixel-array-length-unexpected/38963/8 "2022-09-28T00:26:00Z")

</div>

Hello,

This image here may help you understand:

> **[Pixel Density, Demystified](https://medium.com/@peternowell/pixel-density-demystified-a4db63ba2922)**
>
> How pixel density works and how it affects your designs.

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

Regards,  
glv
