How I resolved these issues:
- For change colors:
Move JS code from function draw() to function setup()
- For add change color button on HTML
I use the button function and write - onClick="window.location.reload()" which means to reload the page.
Reloading the page means rerunning the code. So when the user clicks, they can print random colors.
Code look like
<button onClick="window.location.reload();">change Color</button>
- For load image inside of ellipse
From "https://editor.p5js.org/jeremydouglass/sketches/T2ooOe6Nx", I know that WEBGL is required if we wan to load image.
WEBGL enables web content to perform 2D and 3D rendering in an HTML canvas in browsers that support it without the use of plug-ins.
- For piano keys:
Checking the if statement and using && to add more rules, the code will be like :
if (mouseX > x && mouseX < x + w && mouseY < height && mouseY > 200) {