Skip to content

Instantly share code, notes, and snippets.

@spite
Created June 1, 2021 22:40
Show Gist options
  • Save spite/77d2c59d73d3e022574fe7291f45dd54 to your computer and use it in GitHub Desktop.
Save spite/77d2c59d73d3e022574fe7291f45dd54 to your computer and use it in GitHub Desktop.
superellipse / squircle
// superellipse / Lamé curve
// https://en.wikipedia.org/wiki/Superellipse
const a = 0.4; // semi-diameter
const b = 0.4; // semi-diameter
const n = 1.5; // curve (<1, 1-2, >2)
const c = Math.cos(gamma); // gamma 0-2π
const s = Math.sin(gamma); // gamma 0-2π
const x = Math.pow(Math.abs(c), 2 / n) * a * Math.sign(c);
const y = Math.pow(Math.abs(s), 2 / n) * b * Math.sign(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment