Description
Increasing access
This feature could increase beginner-friendliness by making it a bit easier to generate such values as well increase interoperability between P2D and WEBGL mode.
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)
Feature request details
I'd like to make a suggestion to add two new functions to p5: randomX
and randomY
, which would get random values relative to the dimensions of the canvas and the coordinate system origin (which differs between P2D and WEBGL mode).
A margin could be passed as an optional parameter, the distance to extend (positive) or contract (negative) the range from the edges of the canvas.
In WEBGL mode it'd reduce the amount of code needed to do so from this random(-width / 2, width / 2)
to just randomX()
which in a large file where this is done many times would make user's code smaller and easier to read imo since the function is intuitively named.