What is the difference between pixelDensity() and displayDensity()?

Hey!

I’ve started to use p5.Graphics in my sketches and ran into a problem with pixel densities. I’m familiar with p5 and Processing but can’t quite grasp the meaning of these two functions and how they differ. Also, what’s the best way to solve a problem involving different pixel densities and p5.Graphics objects?

Thanks!

1 Like

Hi,

One is used to set the pixel density and the other one to get it:
https://p5js.org/reference/#/p5/pixelDensity
https://p5js.org/reference/#/p5/displayDensity

  • pixelDensity() is both a setter & a getter for the sketch’s current pixel scaling!
  • displayDensity() is a getter only. It grabs the monitor’s pixel scaling AFAIK.
3 Likes