Failing to "resizeCanvas" in instance mode within a for loop

  1. Calling resizeCanvas clears the canvas, so you need to re-fill the canvas with the background color.
  2. When you are resizing the canvases you need to check the actual offsetWidth and offsetHeight of the respective.
  3. As written, canvasDiv is function scoped, so even if you fix #2 and use canvasDiv.offset..., each instance mode sketch is going to be resized to match the size of the last div created. This is a wonderful example of the absolute evil of the var keyword. If you declare canvasDiv with the let keyword then it will be block scoped inside the for loop so that for each instance the canvasDiv variable will reference the appropriate div.

To better illustrate point #3 here is a simplified example: