Listing 4. Source code for project PutPixel01.
/*Project PutPixel01
The purpose of this project is to illustrate the most
fundamental aspects of writing code to control the
color of each individual pixel.

A window with dimensions of 256x256 is placed on the
screen.  Nested for loops are used to set the value of
each pixel in the window.  The color ranges from mid-
intensity blue in the upper left corner to yellow in the
bottom right corner.

The color of each pixel is changed directly on the screen.
As a result, the user can see the color of the pixels
change going from top to bottom down the window.

Changing the color depth from 32 to 16 causes the entire
window to be painted much more quickly.

Pressing any key causes the program to terminate.
*/
#include <allegro.h>

int main(){
  allegro_init();//Allegro initialization
  install_keyboard();//Set up for keyboard input
  //Need to set the color depth before setting the
  // graphics mode.
  set_color_depth(32);
  //Set the graphics mode to a 256x256-pixel window.
  set_gfx_mode(GFX_AUTODETECT_WINDOWED,256,256,0,0);

  //Cycle through the screen bitmap setting the color of
  // each pixel individually.
  for(int row = 0;row < 255;row++){
    for(int column = 0;column < 255;column++){
      putpixel(screen,column,row,makecol(column,row,128));
    }//end loop row
  }//end loop on column
  
  //Block and wait until the user presses a key.
  readkey();

  return 0;//Return 0 to indicate a successful run.
}//end main function
END_OF_MAIN()