* 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)
| 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 |
no outgoing calls
no test coverage detected