// File: snowmen.cxx 01/11/2010
// Written by: Dmitry Duplyakin (Dmitry.Duplyakin@colorado.edu)
// and Michael Main (main@colorado.edu)
// The main purpose of this program is to show a first example of animation
// with double-buffering with the WinBGIm graphics library.

// Directives:
#include <graphics.h>
#include <cstdlib>
#include <cmath>
using namespace std;

//-----------------------------------------------------------------------------
// This named constant tells the width and height of the graphics window.
const int S = 500;
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Function Prototypes.
// This is a list of all the functions that I plan to write because the
// author of the graphics library did not have them!

// The draw_snowman function draws one snowman with the body center at (cx,cy)
// and the radius of the body given by the paramter radius.
void draw_snowman(int cx, int cy, int radius);

// The draw_frame function draws a picture of several snowmen. The number dy
// tells how far the snowmen have dropped down from the original drawing.
void draw_frame(int dy);
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// The main program defines wat the program will do. The commands are
// executed one after another from initwindow down to the final delay(20000).
int main()
{   
    int shift = 0;

    // The 6th argument is a bool value to tell whether double buffering
    // should be turned on.
    initwindow(S, S, "Let It Snow!", 100, 200, true);
    
    while (shift < S)
    {
	// Draw the next frame
	cleardevice();
	draw_frame(shift);
	// Swap the buffers and pause
	swapbuffers();
	delay(20);
	// Set things up for the next frame
	shift++;
    }
    
    delay(20000);
    return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void draw_frame(int dy)
{
    draw_snowman(S/5, S/5 + dy, S/15);
    draw_snowman(4*S/5, S/5 + dy, S/15);
    draw_snowman(S/2, S/2 + dy, S/5);

}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void draw_snowman(int cx, int cy, int radius)
{
    circle(cx, cy, radius);
    circle(cx, cy - radius*3/2, radius/2);
}
//-----------------------------------------------------------------------------

