Skip to content

Instantly share code, notes, and snippets.

@fewlinesofcode
Created June 19, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fewlinesofcode/c6a8650c09a68509a642c99dd74abb83 to your computer and use it in GitHub Desktop.
Save fewlinesofcode/c6a8650c09a68509a642c99dd74abb83 to your computer and use it in GitHub Desktop.
p5 Pillow drawing
const s = (p) => {
const w = 400;
const h = 400;
// Center coordinates
const x0 = 200;
const y0 = 200;
// Radius
const r = 150;
var angle = 0;
p.setup = () => {
p.createCanvas(w, h);
p.stroke(0, 0, 0, 10);
p.background(225);
};
p.draw = () => {
var a, b = 0;
var numPoints = 10;
for(var i = 0; i <= numPoints; i++) {
// Pillow
var x = x0 + r * Math.cos(2 * Math.PI * i / numPoints - angle);
var y = y0 + r * Math.sin(2 * Math.PI * i / numPoints + angle);
if (i != 0) p.line(a, b, x, y);
a = x;
b = y;
}
angle += 1;
};
};
let myp5 = new p5(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment