JavaScript Basic Question

How can I make it so that the grass is “cut” at a certain height?

I think I should be changing something in line 21, but not sure… also, when the grass is cut, all that happens is a white rectangle is being placed over it

function setup() {
  createCanvas(400, 200);
  colorMode(HSB);
}

var x = 0;
var h = 10;

function draw() {
  stroke(random(60, 70), 100, 90);
  line(x, height-10, x+random(-10, 10), height-10-random(h));
  noStroke();

  x = x + 10;

  if (x > width) {
    x = random(10);
    h = h + 3;
  }

  if (random() > 0.999) {
    fill(255);
    rect(0, 0, width, height-15);
    h = 10;
  }

  fill(40, 100, 60);
  rect(0, height-10, width, 10);
}
  if (random() > 0.995) {    0.999
    fill(255);
    rect(0, 0, width, height-25); //15);
    h = 10;
    console.log("cut");
  }

well, the grass is cut at at certain height already,
you see that you have the ground area at
height - 10
and the cut above
height - 15
so you see some short grass after cut.
you can change the height like i show,
same you can change how often the grass is cut,

1 Like