I suspect your main issue is understanding how to convert JS arrays to Java 1s.
As an example, take a look at this Java flavor sketch: “Conglomerate of Points (Java)”
That sketch declares & initializes 2 arrays of datatype PVector[]:
final PVector[] points = new PVector[QTY], tPoints = new PVector[QTY];
And then fill those up using a for ( ; ; )
loop:
for (int i = 0; i < QTY; ++i) {
points[i] = new PVector(random(width), random(height));
tPoints[i] = new PVector(random(width), random(height));
}
Now let’s take a look at its corresponding p5js flavor conversion: “Conglomerate of Points (p5js)”
http://p5js.SketchPad.cc/sp/pad/view/ro.$V3VWYDTmRb/latest
And the syntax being used for declaring & initializing those 2 arrays in JS:
const points = Array(QTY).fill(), tPoints = Array(QTY).fill();
Usually in JS we create arrays using the []
syntax, which is empty by default.
But JS also offers the Array constructor, where we can specify its initial length:
Method fill() merely solidifies the array by filling it up w/ an optional specified value:
And its corresponding for ( ; ; )
loop is very similar to the Java version:
for (let i = 0; i < QTY; ++i) {
points[i] = createVector(random(width), random(height));
tPoints[i] = createVector(random(width), random(height));
}
For a more complete tutorial about Java arrays please read this: