setPixel = (img, { x, y }, color) => {
  // The ImageData data array is a flat 1D array.
  // Thus we need to convert x and y coordinates to the linear index.
  const i = y * img.width + x;
  const cellsPerColor = 4; // RGBA
  img.data.set(color, i * cellsPerColor);
}
Helper function that sets the color of the pixel.
@param {ImageData} img
@param {PixelCoordinate} coordinate
@param {PixelColor} color