/* Filename: pg5.cpp * * Author: Br. David Carlson * * Date: July 6, 2009 * * Description: This GDK program draws a smiley face. The one eye blinks. * The user can press any key to end the program. */ #include "DarkGDK.h" const DWORD black = dbRGB(0, 0, 0); const DWORD white = dbRGB(255, 255, 255); // Function prototypes: void DrawBall(int x, int y, int r); void DrawFace(int x, int y, int r); void Blink(int x, int y, int time); void DarkGDK() { int CenterX = 319, CenterY = 239; int r = 60; dbSetWindowTitle("Smiley Face"); DrawFace(CenterX, CenterY, r); dbWait(2000); Blink(CenterX, CenterY, 600); dbWaitKey(); } /* Given: x the x-coordinate of the center of the ball. * y the y-coordinate of the center of the ball. * r the radius of the desired ball. * Task: To draw a filled-in ball with the given center and radius. * Return: Nothing. */ void DrawBall(int x, int y, int r) { int k; for (k = 0; k <=r; k++) dbCircle(x, y, k); } /* Given: x the x-coordinate of the center of the face. * y the y-coordinate of the center of the face. * r the radius of the desired face. * Task: To draw a smiley face with the given center and radius. * Return: Nothing. */ void DrawFace(int x, int y, int r) { dbCircle(x, y, r); // Outline of face DrawBall(x - 20, y - 15, 3); // First eye DrawBall(x + 20, y - 15, 3); // Second eye DrawBall(x, y, 2); // Nose dbLine(x - 20, y + 15, x + 20, y + 15); // Mouth } /* Given: x the x-coordinate of the center of the face. * y the y-coordinate of the center of the face. * time amount of time (in milliseconds) to blink the eye. * Assumes: The face (centered at x, y) has already been drawn. * Task: To blink the one eye for the indicated time. * Return: Nothing. */ void Blink(int x, int y, int time) { // Erase the ball for the one eye: dbInk(black, black); DrawBall(x + 20, y - 15, 3); // And draw a line for the closed eye: dbInk(white, black); dbLine(x + 20 - 4, y - 15, x + 20 + 4, y - 15); dbWait(time); // Erase the line: dbInk(black, black); dbLine(x + 20 - 4, y - 15, x + 20 + 4, y - 15); // Draw the circular eye again: dbInk(white, black); DrawBall(x + 20, y - 15, 3); }