
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
poly-generator
Advanced tools
A versatile library for generating equilateral polygons and stars.
A versatile library for generating equilateral polygons and stars.
Visit Polygen Playground to try it online.
npm install poly-generator
Polygen provides two ways to use: utility functions and the Polygon class.
Suitable for simple drawing scenarios, directly generate paths and draw:
import polygen from 'poly-generator';
// Generate paths
const paths = polygen.generate({
npoints: 5, // Number of points
radius: 100, // Radius
cornerRadius: 0, // Corner radius
rotation: 0 // Rotation angle
});
// Draw on Canvas
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
polygen.draw(paths, ctx, {
strokeWidth: 2,
fill: '#FFFFFF',
stroke: '#000000'
});
You can also use it step by step:
// 1. Generate vertices
const vertices = polygen.generateVertices({
npoints: 6,
radius: 100,
rotation: 30
});
// 2. Generate paths from vertices
const paths = polygen.generatePathsFromVertices(vertices, 10); // With corner radius 10
// 3. Draw
polygen.draw(paths, ctx, {
fill: '#FFD056',
stroke: '#6E66FF'
});
Suitable for scenarios where you need to maintain polygon state:
import { Polygon } from 'poly-generator';
const polygon = new Polygon({
npoints: 6,
radius: 100,
cornerRadius: 10,
rotation: 30
});
// Access polygon properties
console.log(polygon.points); // Get vertices
console.log(polygon.paths); // Get path segments
// Draw with custom styles
polygon.draw(ctx, {
fill: '#FFD056',
stroke: '#6E66FF',
strokeWidth: 2
});
Both methods support generating stars by adding the innerRadius
parameter:
// Using utility function
const starPaths = polygen.generate({
npoints: 5, // Number of points
radius: 100, // Outer radius
innerRadius: 50, // Inner radius
cornerRadius: 0, // Corner radius
rotation: 0 // Rotation angle
});
// Or using Polygon class
const star = new Polygon({
npoints: 5,
radius: 100,
innerRadius: 50,
cornerRadius: 10
});
Parameter | Type | Default | Description |
---|---|---|---|
npoints | number | - | Number of vertices |
radius | number | - | Outer radius |
innerRadius | number | - | Inner radius (for stars only) |
cornerRadius | number | 0 | Corner radius |
rotation | number | 0 | Rotation angle (0-360) |
x | number | 0 | Center x coordinate |
y | number | 0 | Center y coordinate |
Parameter | Type | Default | Description |
---|---|---|---|
fill | string | 'white' | Fill color |
stroke | string | 'black' | Stroke color |
strokeWidth | number | 2 | Stroke width |
lineDash | number[] | [] | Line dash pattern |
shadowColor | string | 'transparent' | Shadow color |
shadowBlur | number | 0 | Shadow blur |
shadowOffsetX | number | 0 | Shadow X offset |
shadowOffsetY | number | 0 | Shadow Y offset |
FAQs
A versatile library for generating equilateral polygons and stars.
The npm package poly-generator receives a total of 0 weekly downloads. As such, poly-generator popularity was classified as not popular.
We found that poly-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.