Pjs is pretty much Processing v1.5.1 w/ some few bits from Processing 2.x.x.
Once upon a time, most non-static
methods from class PVector , like add() , mult() , etc., were all void
:
ProcessingJS.org/reference/void/
1 day, the devs had the idea to make all those void
methods to return this
instead; thus turning them all chainable:
ProcessingJS.org/reference/this/
In your sketch you’ve got some statements like:
new Bobble(new PVector(-halfSide, -halfSide).add(center), ballS, ballC),
this.vel.add(this.acc).mult(this.damp);
PVector newAcc = PVector.sub(this.posRest, this.posCurr).mult(k);
Those work under Java Mode b/c .add(center)
, .add(this.acc)
& .mult(k)
return the PVector current object which had invoked them.
However, due to the fact Pjs hadn’t implemented those neat feature changes, all of those method calls above simply return undefined
:
BtW, I made a pull request on Pjs’ repo 4 years ago for it; but unfortunately it’s got rejected:
processing-js:master
← GoToLoop:patch-1
opened 05:48PM - 19 Aug 15 UTC
https://gist.github.com/GoToLoop/acbf106aa784820aff23
https://github.com/process… ing/processing/blob/master/core/src/processing/core/PVector.java
https://github.com/processing-js/processing-js/blob/master/src/Objects/PVector.js
https://github.com/processing-js/processing-js/issues/200
As a workaround, those affected statements can be rewritten like this:
PVector shiCen = PVector.add(shift, center);
bobbles = new Bobble[] {
new Bobble(PVector.add(new PVector(-halfSide, -halfSide), center), ballS, ballC),
new Bobble(PVector.add(new PVector(halfSide, -halfSide), center), ballS, ballC),
new Bobble(PVector.add(new PVector(halfSide, halfSide), center), ballS, ballC),
new Bobble(PVector.add(new PVector(-halfSide, halfSide), center), ballS, ballC),
new Bobble(PVector.add(new PVector(-halfSide, -halfSide), shiCen), ballS, ballC),
new Bobble(PVector.add(new PVector(halfSide, -halfSide), shiCen), ballS, ballC),
new Bobble(PVector.add(new PVector(halfSide, halfSide), shiCen), ballS, ballC),
new Bobble(PVector.add(new PVector(-halfSide, halfSide), shiCen), ballS, ballC),
};
vel.add(acc);
vel.mult(damp);
PVector newAcc = PVector.sub(posRest, posCurr);
newAcc.mult(.05);