Converting from java to p5js, not working as intended