Skip to content

[p5.js 2.0 Bug Report]: Switching from 1.x to 2.x, pixelDensity() only applies to canvas, not p5.Graphics #8289

@imrinahru

Description

@imrinahru

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

2.x.x

Web browser and version

chrome://142.0.7444.135

Operating system

Windows 11 Version 25H2 (Build 26200.7171)

Steps to reproduce this

Actual Behavior

In p5 2.x, if you set pixelDensity(n), although the canvas pixelDensity is changed to n, any p5.Graphics that you create will NOT have density n. you have to call Graphics.pixelDensity(n) to have the same pixelDensity.

https://editor.p5js.org/imrinahru/sketches/ufS-89YGX

ver 2.1.1
After calling pixelDensity(1) , the log shows g.pixelDensity remains 2.

Image

ver.1.11.11
After calling pixelDensity(1) , the log shows g.pixelDensity is set 1.

Image

Expected Behavior

pixelDensity(n) is applied to both the Canvas, and the p5.Graphics that will be created on that Canvas.

Steps to reproduce

Steps:

  1. Go to any p5 2.x
  2. createCanvas and call pixelDensity(n), set n as a different value from what is by default set by your PC resolution to see the difference.
  3. createGraphics on the canvas
  4. Check the pixelDensity of the Graphics by console.log(Graphics.pixelDensity()).

Snippet:

function setup() {
  createCanvas(400, 400);
  pixelDensity(1);
  let g =createGraphics(400, 400);
  console.log(g.pixelDensity());
}

The issue is related to an issue previously filed in p5.riso library: antiboredom/p5.riso#23

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions