Coder Social home page Coder Social logo

geometrics's Introduction

about

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

setup

Load via script tag:

<!-- Just an IIFE namespaced `geometrics` -->
<script src="https://thewhodidthis.github.io/geometrics/geometrics.js"></script>

Source from an import map:

{
  "imports": {
    "@thewhodidthis/geometrics": "https://thewhodidthis.github.io/geometrics/main.js"
  }
}

Download from GitHub directly if using a package manager:

# Add to package.json
npm install thewhodidthis/geometrics

usage

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

import { poly } from "@thewhodidthis/geometrics"

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)

Degree to radian and polar to cartesian converters are also available:

import * as math from "@thewhodidthis/geometrics/helper"

console.assert(math.deg(math.TAU) === 360)
console.assert(math.rad(180) === Math.PI)

see also

geometrics's People

Contributors

thewhodidthis avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.