Skip to content

Instantly share code, notes, and snippets.

@anselanza
Created December 20, 2017 15:16
Show Gist options
  • Save anselanza/663d55090a37bfe147552acf4bae963b to your computer and use it in GitHub Desktop.
Save anselanza/663d55090a37bfe147552acf4bae963b to your computer and use it in GitHub Desktop.
Basic example using p5js as npm module, without using global context
// As shown in https://github.com/processing/p5.js/wiki/Global-and-instance-mode
import p5 from 'p5';
let myP5 = new p5( function (sketch) {
// for red, green, and blue color values
let r, g, b;
sketch.setup = function() {
console.log('setup');
sketch.createCanvas(720, 400);
// Pick colors randomly
r = sketch.random(255);
g = sketch.random(255);
b = sketch.random(255);
}
sketch.draw = function() {
sketch.background(127);
// Draw a circle
sketch.strokeWeight(2);
sketch.stroke(r, g, b);
sketch.fill(r, g, b, 127);
sketch.ellipse(360, 200, 200, 200);
}
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment