// File: nested.cxx
// Written by: Michael Main
// This program shows nested loops drawing some patterns

//-----------------------------------------------------------------------
#include <cstdlib>
#include <graphics.h>
using namespace std;
const int S = 400;
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
int main( )
{
    int px, py; // Pixel coordinates
    int startx, stopx; // Starting and stopping points for an inner loop
    
    // Open the graphics window
    initwindow(S, S, "Nested");

    // Color all red
    cleardevice( );
    for (px = 0; px < S; ++px)
    {
	for (py = 0; py < S; ++py)
	{
	    putpixel(px, py, RED);
	}
    }
    delay(3000);

    // Color yellow lower triangle
    cleardevice( );
    for (px = 0; px < S; ++px)
    {
	for (py = px; py < S; ++py)
	{
	    putpixel(px, py, YELLOW);
	}
    }
    delay(3000);

    // Color tall green triangle
    cleardevice( );
    for (py = 0; py < S; ++py)
    {
	startx = (S - py)/2;
	stopx = (S + py)/2;
	for (px = startx; px < stopx; ++px)
	{
	    putpixel(px, py, GREEN);
	}
    }
    delay(3000);

    return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------

	
