What is the best way to draw and re-draw rectangles on an image with JavaScript?
Here is what I'm trying to do. I have a program written in Java. I plan to move it to a web server because of the amount of CPU resources it uses. The program displays an image with a grid overlay. The user can indicate regions of the image by clicking in the grid. When a grid cell is clicked -- which is a rectangle -- it cycles from one color to the other and text is likewise cycled. In the desktop Java program I do this by making a copy of the original image and drawing rectangles on it with OpenCV library. Each time the user clicks, a fresh copy of the image has the updated grid drawn on it before it's displayed.
How might I do this in JavaScript? I could still use my current method combined with AJAX, but the user would have to wait for a round trip of the image on every click. It would be nice to have a JavaScript way of immediately updating the grid on each click.