Questions on static methods

Thank you for the answer :slight_smile:

I would have something like this then:

static class MyVector {
  final PApplet pa;
  float v1, v2;

  MyVector(final PApplet pa, float v1, float v2) {
    this.v1 = v1;
    this.v2 = v2;
    this.pa = pa;
  }

  public static MyVector createUnitVector(final PApplet pa) {
    return new MyVector(pa, 1, 0);
  }
  
  public static MyVector createRandomVector(final PApplet pa) {
    return new MyVector(pa, pa.random(1), pa.random(1));
  }

  public void randomize() {
    v1 = pa.random(1);
    v2 = pa.random(1);
  }
}
1 Like