therewasaguy / p5js-webIDE

demo ~
http://p5ide.herokuapp.com/
47 stars 11 forks source link

Constructor p5 nowhere to be found! #120

Open GoToLoop opened 8 years ago

GoToLoop commented 8 years ago
function setup() {
  createCanvas(400, 400);
  console.log(p5);
  var vec = p5.Vector.Random3D();
}

W/o p5 there's no apparent way to invoke static methods like p5.Vector.Random3D(): :crying_cat_face: http://p5js.org/reference/#/p5.Vector/random3D

GoToLoop commented 8 years ago

Found a workaround! But it's still a redundant & slower boilerplate; given we 1st need to create an instance and only then access its constructor: :disappointed: createVector().constructor.random3D()

const VECS = 5,
      RANGE = 10,
      vecs = Array(VECS);

function setup() {
  noCanvas();
  for (let i = 0; i < VECS; vecs[i++] = createVector().constructor.random3D().mult(RANGE));
  for (let i in vecs)  print(`${i} -> ${vecs[i]}`);
}

http://p5ide.HerokuApp.com/editor#?sketch=574bd0ad02c8c203008bbfdb

GoToLoop commented 8 years ago

Found out another hackish workaround for http://p5ide.HerokuApp.com/editor: window.p5 = _renderer._pInst.constructor;

Link for the latest sketch: http://p5ide.HerokuApp.com/editor#?sketch=5751b1d4591f900300aaf9de

Hope constructor p5 gets back to the p5js WebIDE soon, so we don't need those hacks anymore. :pray: