PVector.random2D() is javascript mode gives error "Uncaught TypeError: undefined is not a function"

edited August 2014 in Questions about Code

Execute this in 2.2.1 and get the above error.

void setup() { PVector v = PVector.random2D(); }

Should I file a bug report?



  • Answer ✓

    Method random2D() is from Processing 2 series. Processing.JS v1.4.1 is closer to Processing v1.5.1.
    Good news is that random2D() is present in Processing.JS v1.4.8:

    PVector.random2D = function(v) {
      return PVector.fromAngle(Math.random() * PConstants.TWO_PI, v);

    Perhaps you can insert that implementation above and magically it starts to work in v1.4.1 too! (*)

  • Ah thank you! Will all of these methods be implemented into Processing.JS eventually?

  • edited August 2014

    Processing.JS project is more or less halted, since they're focused on a true JS library now!
    But eventually I hope Java Mode & JS Mode gonna have their API matched 100%! [-O<
    And by some miracle, have more cross-mode libraries! But don't hold your breath! :-\"

  • Cool. So where can I find out more about the true JS library project? Thank you!

Sign In or Register to comment.