Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

readme.md

about

Parametric solutions for common polar equations worth drawing with, superformula included.

setup

Find the latest version on the npm registry:

# Includes ES and CJS modules
npm install @thewhodidthis/multipolar

usage

Expect pure functions as named exports returning arrays of points represented as { x, y } object literals. For example,

import { poly } from 'multipolar'

const canvas = document.createElement('canvas')
const target = canvas.getContext('2d')
const center = { x: canvas.width * 0.5, y: canvas.height * 0.5 }

// Draw an evil pentagram
const points = poly(center.y, 5)

target.translate(center.x + 0.5, center.y + 0.5)
target.rotate(Math.PI * 0.5)
target.beginPath()

points.forEach((p, i) => {
  const s = (i + 3) % points.length
  const n = points[s]

  target.moveTo(p.x, p.y)
  target.lineTo(n.x, n.y)
})

target.stroke()

document.body.appendChild(canvas)

see also