Skip to content

Add drawStar() function to draw customizable star shapes #7816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

XTC917
Copy link

@XTC917 XTC917 commented May 15, 2025

Changes:

  • Added a new drawing function star(x, y, radius1, radius2, npoints) to p5.prototype in src/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.html and test-star-interactive.html to 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:
    1. Start with beginShape().
    2. Calculate angle and halfAngle for spacing star points evenly.
    3. In a loop, alternate between outer and inner points using radius1 and radius2.
    4. End with endShape(CLOSE) to complete the star.

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

Copy link

welcome bot commented May 15, 2025

🎉 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant