1

I have created a class which takes in an array of vector coordinates, and then sketches leafs where those coordinates are. I am writing a getter and a setter where you can change the colour of these leafs. The leaf colour rages from a minHue and a maxHue. I am getting a "Script error. (: line 0)" when running the class but cannot locate what is wrong.

I have looked through the code for any case errors but cant final any.

class drawLeaves {

  constructor(leafArray) {
    this.leafs = leafArray;
    this.randomColor = true;
    this.minHue = 0;
    this.maxHue = 0;
  }

  genLeaves(minDiam, maxDiam, minAlpha, maxAlpha) {

    if (this.randomColor) {
      var rdn0 = random(255);
      var rdn1 = random(255);
      this.minHue = min(rdn0, rdn1);
      this.maxHue = max(rdn0, rdn1);
    } else {
      var colors = this.leafColor;
      minHue = colors[0];
      maxHue = colors[1];
    }



    let i;
    for (i = 0; i < this.leafs.length; i++) {
        let h = map(i, 0, this.leafs.length, this.minHue, this.maxHue);
        let s = 255;
        let b = 255;
        let a = random(minAlpha, maxAlpha);
        fill(h, s, b, a);
        let diam = random(minDiam, maxDiam);
        let jitterX = random(-30, 30);
        let jitterY = random(-30, 30);  
        ellipse(this.leafs[i].x + jitterX, this.leafs[i].y + jitterY, diam, diam);
    }
  }



  draw() {
    this.genLeaves(0, 90, 0, 0.03);  // big leaves
    this.genLeaves(0, 15, 0, 0.25);  // small leaves

  }


  set leafColor(minHue, maxHue) {
    this.minHue = minHue;
    this.maxHue = maxHue;
    this.randomColor = false;
  }

  get leafColor() {
    return [this.minHue, this.maxHue]
  }
}

Looking for feedback to help remove the error, many thanks.

1 Answers1

0

When I run this in the Babel REPL I get the following error:

repl: setter should have exactly one param (48:2)

According to the documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set#Description) a setter should only have 1 parameter.

Try refactoring so you can have only 1 parameter or change it to this:

setLeafColor(minHue, maxHue) {
    code
}
Eddy Vinck
  • 410
  • 1
  • 4
  • 16