Home | Mailing List | Blog | Tutorial Videos

Direction of Loops

In which direction will the following code scan an image?

const image = new Image;
const maxHeight = image.height + 1;
const maxWidth = image.width + 1;

for (let i = 0; i < image.maxHeight; i++) {
  for (let j = 0; j < image.maxWidth; j++) {
    // Obtaining values of pixels, assuming function getPixel(y, x) takes argument y as Y-coordinate and x as X-coordinate
    const pixel = getPixel(i, j);
    const pixelValues = { 
      red: pixel.getRed(), 
      green: pixel.getGreen(), 
      blue: pixel.getBlue()
    };
    // Update pixel color scheme
    pixelValues.red /= 2;
    pixelValues.green /= 3;
    pixelValues.blue *= 2;
  }
}

Select one: