Skip to content

thewhodidthis/swing

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

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

about

Helps create harmonograph style patterns.

setup

Load via script tag:

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

Source from an import map:

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

Download from GitHub directly, using npm for example:

# Add to package.json
npm install thewhodidthis/swing

usage

Pass in minimum amplitude and frequency arguments and call the resulting function over time. For example,

import swing from "@thewhodidthis/swing"

// Lissajous curve wrapper (no damping).
const driver = (A = 1, B = A, a = 1, b = a * 2, phase = Math.PI * 0.5) => {
  const x = swing(A, a, phase)
  const y = swing(B, b, phase)

  return t => ({ x: x(t), y: y(t) })
}

// Points for the Lemniscate of Gerono.
const lookup = driver(175, 100)

setInterval(() => {
  const t = Date.now()
  const { x, y } = lookup(t)

  console.log(x, y)
}, 1000)

see also

Releases

No releases published

Packages

No packages published