/* Program: pumpkin2.c Draw a pumpkin. Cleaned up version. */ #include #include "genlib.h" #include "simpio.h" #include "graphics.h" /* Use math library */ #include #define PI 3.1415926 #define PUMPKIN_SIZE 2.0 #define EYE_SIZE (PUMPKIN_SIZE/4.0) #define PUMP_ANG 60.0 /* Pumpkin Angle */ /* Function Prototypes */ double deg2rad (double angle) ; void DrawEye(void) ; /* Convert degree to radians */ double deg2rad (double angle) { return (PI * angle / 180.0 ) ; } void DrawEye(void) { DrawLine(-EYE_SIZE/2, 0.0) ; DrawLine(EYE_SIZE/2, EYE_SIZE) ; DrawLine(EYE_SIZE/2, -EYE_SIZE) ; DrawLine(-EYE_SIZE/2, 0.0) ; } main() { double x, y, max_x, max_y ; double mid_x, mid_y, top, eye_offset ; double radius, start, sweep ; /* Initialize graphics routines */ InitGraphics() ; max_x = GetWindowWidth() ; max_y = GetWindowHeight() ; mid_x = max_x / 2.0 ; mid_y = max_y / 2.0 ; top = mid_y + PUMPKIN_SIZE * sin(deg2rad(PUMP_ANG)) ; eye_offset = PUMPKIN_SIZE * cos(deg2rad(PUMP_ANG)) ; /*** Draw stem */ MovePen(mid_x, top ) ; DrawLine(-PUMPKIN_SIZE/8.0, 3*PUMPKIN_SIZE/8.0); DrawLine(PUMPKIN_SIZE/4.0, 0.0 ) ; DrawLine(-PUMPKIN_SIZE/8.0, -3*PUMPKIN_SIZE/8.0); /*** Draw right side of pumpkin */ MovePen(mid_x, top) ; start = 180.0 - PUMP_ANG ; sweep = 360.0 - 2 * PUMP_ANG ; DrawArc(PUMPKIN_SIZE, start, -sweep ) ; /*** Draw left side of pumpkin */ start = -PUMP_ANG ; DrawArc(PUMPKIN_SIZE, start, -sweep ) ; /*** Draw Eyes */ MovePen(mid_x + eye_offset, mid_y) ; DrawEye() ; MovePen(mid_x - eye_offset, mid_y) ; DrawEye() ; /* Draw Mouth */ radius = PUMPKIN_SIZE / 2.0 ; start = 270.0 - PUMP_ANG ; sweep = 2 * PUMP_ANG ; x = mid_x + radius * cos(deg2rad(start)) ; y = mid_y + radius * sin(deg2rad(start)) ; MovePen(x,y) ; DrawArc(radius, start, sweep); radius = radius * sin(deg2rad(PUMP_ANG)) ; DrawArc(radius, 0.0, -180.0 ) ; }