// Programming Assignment 4 - Example Solution.
// CS 176, Summer 2001


// Construct in image a representation of the object that resulted in the list
// of x_size energy measurments in x_energies and the list of y_size energy
// measurments in y_energies.


void generate_image(
  const int x_energies[], int x_size, 
  const int y_energies[], int y_size, 
  int image[25][25]) {

  // Sanity checks.

     if ((x_size < 0) || (25 < x_size)) return;
     if ((y_size < 0) || (25 < y_size)) return;


  // If both beams passing through obj[x][y] are obstructed then assume
  // obj[x][y] contains energy absorbing material; otherwise then there can't
  // be an obstruction at obj[x][y] becasue at least one of the beams made it
  // through the object.

     for (int x = 0; x < x_size; x++)
       for (int y = 0; y < y_size; y++)
	 image[x][y] = ((x_energies[x] == 0) && (y_energies[y] == 0)) ? 1 : 0;
  }


syntax highlighted by Code2HTML, v. 0.9