@labcat2020/p5.polygon
v0.1.0
Published
p5.js polygon helpers — regular polygon, pentagon, hexagon, octagon, equilateral
Readme
@labcat2020/p5.polygon
Standalone p5.js polygon helpers — no audio, no polar, no sacred deps.
Extracted from @labcat2020/p5.audioreactive so sketches that just need polygons don't pull Tone/MIDI/sacred.
Install
pnpm add @labcat2020/p5.polygon p5Exports
{
".": "./src/p5.polygon.js",
"./p5.polygon.js": "./src/p5.polygon.js"
}Usage
import p5 from 'p5';
import '@labcat2020/p5.polygon'; // adds to p5.prototype
const sketch = (p) => {
p.setup = () => { p.createCanvas(400, 400); };
p.draw = () => {
p.background(0);
p.polygon(200, 200, 80, 6); // x,y,radius,sides,startAngle?
p.pentagon(100, 100, 60);
p.hexagon(300, 100, 60);
p.octagon(100, 300, 60);
p.equilateral(300, 300, 60);
};
};
new p5(sketch);API (all on p5.prototype):
polygon(x, y, radius, sides, startAngle=0)pentagon(x, y, width, height=width)hexagon(x, y, radius)octagon(x, y, radius)equilateral(x, y, radius)
Motivation
@labcat2020/p5.audioreactive/p5.polygon.js still re-exports this for compat, but new code should import @labcat2020/p5.polygon directly.
License
MIT — LABCAT
