Uso di frameCount con l'operatore %

Per ottenere un valore che riparta da 0 superato un certo limite, รจ possibile utilizzare l’operatore % (modulo).

    function draw() {
    background(220);

    let y = (frameCount-1) % height;
    circle( 50, y, 10 );
}
  

  

L’operatore % restituisce il resto della divisione e permette di ripartire da 0 ogni volta che frameCount-1 diventa un multiplo esatto di height.

Provare a sostituire height con un valore esplicito inferiore a 100.