Allow object literals for 2D-Shape functions in additional to positional parameters
Open
Nobody has claimed this yet.
Discussion
Feature Request
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
- functions with more than a few parameters are hard to remember how to use
- object literals to the rescue!
- allow object literal parameter in p5.js Shape functions for readability
- leveraging api patterns from SmallTalk, Objective-C, Swift, and modern JavaScript frameworks (eg. react)
- arc function example
// arc(x, y, w, h, start, stop, [mode], [detail])
arc(50, 50, 80, 80, 0, PI + HALF_PI);
-- ++ allow object literal option
arc( {x: 50, y:50, w:80, h:80, start:0, stop:PI + HALF_PI } );
- change is totally opt-in, existing syntax is still allowed
- document change could be limited to one extra line in syntax summary for each Shape function
function arc() Syntax
arc(x, y, w, h, start, stop, [mode], [detail])
arc({ x, y, w, h, start, stop, mode, detail })
- Other Shapes updates for object literal parameter:
ellipse({ x, y, w, h})
circle({ x, y, d })
rect({ x, y, w, h, tl, tr, br, bl })
triangle({ x1, y1, x2, y2, x3, y3 })
triangle([{ x, y }, { x, y }, { x, y }])
line({ x1, y1, x2, y2 })
line([{ x, y }, { x, y }])
line({ x1, y1, z1, x2, y2, z2 })
line([{ x, y, z }, { x, y, z }])
- Details:
This proposal would affect the following Shape functions:
arc()
circle()
ellipse()
line()
point()
quad()
rect()
square()
triangle()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the p5.js Shape functions listed in the issue, beginning with arc() and its positional and object-literal syntax examples. Check how ellipse(), circle(), rect(), triangle(), line(), point(), quad(), and square() are documented and handled. Done means the proposed object-literal forms work while existing positional syntax remains supported, with the syntax summaries updated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100