Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pixels array not working as expected #7433

Open
2 of 17 tasks
prishasbangera opened this issue Dec 18, 2024 · 2 comments
Open
2 of 17 tasks

pixels array not working as expected #7433

prishasbangera opened this issue Dec 18, 2024 · 2 comments

Comments

@prishasbangera
Copy link

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.11.2

Web browser and version

131.0.6778.140 (Official Build) (64-bit) (cohort: Stable)

Operating system

Windows

Steps to reproduce this

https://editor.p5js.org/emeraldblackbird/sketches/irR-EG-mG

I copied an old project that used to work. It is a 600 by 600 canvas. However, I saw that the pixel colors were only being set for only some of the canvas.

I logged the length of the pixels array to the console, but it is four times as long as expected. Since I haven't touched the code in a while, I am not sure if its a bug or if the pixels array works differently now.

Copy link

welcome bot commented Dec 18, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@limzykenneth
Copy link
Member

The size of the pixel array depends on the size of your canvas and the pixel density of your screen/sketch. It is likely that when you created the sketch you were working on a screen with pixel density of 1 and when you view it now it is on a screen with pixel density 2. With an increase in pixel density of 2 (ie. doubling of pixels in x and y dimensions) the pixel number will increase by 4 (2 x 2).

If you want it to be fixed to a 600 by 600 canvas, you can manually set pixelDensity(1) in function setup() and it will create a sketch of pixel density 1 regardless of what screen it is viewed on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants