Complete the code for the following screenshots.

ex15-6a

size(255, 255);
_________________;
for (int x = 0; x < width; x++) {
  for (int y = 0; y < height; y++) {
    int loc = ____________________________;
    float distance = ____________________);
    pixels[loc] = ________________________;	
  }
}
_________________;

Answer:

size(255, 255);
loadPixels();
for (int x = 0; x < width; x++) {
  for (int y = 0; y < height; y++) {
    int loc = x+y*width;
    float distance =dist(x,y,width/2,height/2);
    pixels[loc] = color(distance);	
  }
}
updatePixels();

ex15-6b

size(255, 255);
_________________;
for (int x = 0; x < width; x++) {
  for (int y = 0; y < height; y++) {
    _____________________________;
    if (______________) {
      ___________________________;
    } else {
     ___________________________;
    }
  }
}
_________________;

Answer:

size(255, 255);
loadPixels();
for (int x = 0; x < width; x++) {
  for (int y = 0; y < height; y++) {
    int loc = x + y*width;
    if (x < width/2) {
      pixels[loc] = color(x);
    } else {
      pixels[loc] = color(y);
    }
  }
}
updatePixels();