MCPcopy
hub / github.com/processing/p5.js / pixelDensity

Method pixelDensity

src/image/p5.Image.js:47–74  ·  view source on GitHub ↗

* Gets or sets the pixel density for high pixel density displays. * * By default, the density will be set to 1. * * Call this method with no arguments to get the default density, or pass * in a number to set the density. If a non-positive number is provided, * it defaults to 1.

(density)

Source from the content-addressed store, hash-verified

45 * @returns {Number} The current density if called without arguments, or the instance for chaining if setting density.
46 */
47 pixelDensity(density) {
48 if (typeof density !== 'undefined') {
49 // Setter: set the density and handle resize
50 if (density <= 0) {
51 const errorObj = {
52 type: 'INVALID_VALUE',
53 format: { types: ['Number'] },
54 position: 1
55 };
56
57 // p5._friendlyParamError(errorObj, 'pixelDensity');
58
59 // Default to 1 in case of an invalid value
60 density = 1;
61 }
62
63 this._pixelDensity = density;
64
65 // Adjust canvas dimensions based on pixel density
66 this.width /= density;
67 this.height /= density;
68
69 return this; // Return the image instance for chaining if needed
70 } else {
71 // Getter: return the default density
72 return this._pixelDensity;
73 }
74 }
75
76 /**
77 * Helper function for animating GIF-based images with time

Callers 15

getMethod · 0.95
getMethod · 0.95
readFramebufferRegionMethod · 0.95
readFramebufferRegionMethod · 0.95
p5.Image.jsFile · 0.45
loading.jsFile · 0.45
filters.jsFile · 0.45
pixels.jsFile · 0.45
rendering.jsFile · 0.45
environment.jsFile · 0.45
assertValidGraphSizesFunction · 0.45
p5.Graphics.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected