Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor p5 nowhere to be found! #120

Open
GoToLoop opened this issue May 30, 2016 · 2 comments
Open

Constructor p5 nowhere to be found! #120

GoToLoop opened this issue May 30, 2016 · 2 comments

Comments

@GoToLoop
Copy link

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(): 😿
http://p5js.org/reference/#/p5.Vector/random3D

@GoToLoop
Copy link
Author

GoToLoop commented May 30, 2016

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: 😞 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
Copy link
Author

GoToLoop commented Jun 3, 2016

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. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant