let can; let d; let g; function setup() { can = createCanvasClass(100, 100); can.parent("Example"); // Attach listener for clicks on the canvas only. // The CanvasClass way of handling events. can.mouseClicked(changeGray); d = 10; g = 100; } function draw() { can.background(g); can.ellipse(width / 2, height / 2, d, d); } // This function fires after the mouse has been // clicked anywhere. No CanvasClass equivalent. function mouseClicked() { d = d + 10 } // This function fires after the mouse has been clicked // on the canvas. The CanvasClass way to handle events. function changeGray() { g = random(0, 255); } |
James Brink, 6/27/2020