Skip to content

Instantly share code, notes, and snippets.

@fewlinesofcode
Created June 19, 2020 14:51
Show Gist options
  • Save fewlinesofcode/c6a8650c09a68509a642c99dd74abb83 to your computer and use it in GitHub Desktop.
Save fewlinesofcode/c6a8650c09a68509a642c99dd74abb83 to your computer and use it in GitHub Desktop.

Revisions

  1. fewlinesofcode created this gist Jun 19, 2020.
    38 changes: 38 additions & 0 deletions pillow_p5.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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);