Open
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()