Add drawStar() function to draw customizable star shapes
Changes:
- Added a new drawing function
star(x, y, radius1, radius2, npoints)top5.prototypeinsrc/core/shape/2d_primitives.js. - This function allows users to draw star-shaped figures by specifying outer radius, inner radius, and the number of points.
- Also added demo files:
test-star.htmlandtest-star-interactive.htmlto illustrate basic and interactive usage.
Description:
I found that the project didn’t have a clearly documented or easily accessible star-drawing function, so I contributed p5.prototype.star, located around line 1490-1517 in src/core/shape/2d_primitives.js.
Implementation details:
-
Parameters:
x,y— center position of the star
radius1— outer radius
radius2— inner radius
npoints— number of star points (default 5) -
Steps:
- Start with
beginShape(). - Calculate angle and halfAngle for spacing star points evenly.
- In a loop, alternate between outer and inner points using
radius1andradius2. - End with
endShape(CLOSE)to complete the star.
- Start with
This function enhances the creative capabilities of p5.js, especially for users working in visual arts and design.
Screenshots of the change:
(Add screenshots here if available, e.g. result of test-star.html)
PR Checklist
- [x]
npm run lintpasses - [ ] Inline reference is included / updated
- [ ] Unit tests are included / updated
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!
Hi, really sorry for the delay in review and really thanks for your work. Is your feature related to any issue? If not, it would be great to open up an issue and let the community discuss if we really want this feature or we have any alternatives? Does that sounds okay?