Code:
#include <graphics.h>
/*
line(x, y, x+cos(degrees)*length, y+sin(degrees)*length);
x, and y would be the point around which to rotate. In C you also need to
convert degrees to radians tho.
I didn't use the above info.
*/
int main()
{
int i, msec; //milliseconds used by delay()
int gd=DETECT, gm, errorcode; //int gd=DETECT,gm;
//initgraph(&gd,&gm,""); //for my system
initgraph(&gd,&gm,"e:\\lab\\tc\\bgi");
/* check if it loaded OK */
errorcode = graphresult();
if (errorcode != grOk) { /* an error occurred */
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
for(i=100;i<400;i++)
{
setcolor(3);
line(i,100,i+15,85); //RISING LINE
line(i+15,85,i+70,85); //ST.LINE AT TOP
line(i+70,85,i+100,100); //FALLING LINE
rectangle(i+100,150,i,100); //BODY
rectangle(i+10,130,i+30,110); //WINDOW1
rectangle(i+40,130,i+60,110); //WINDOW2
rectangle(i+70,130,i+90,110); //WINDOW3
circle(i+15,125,5); //FACE1
circle(i+45,125,5); //FACE2
circle(i+75,125,5); //FACE3
circle(i+20,160,10); //WHEEL1
circle(i+20,160,12); //Wheel depth
circle(i+80,160,10); //WHEEL2
msec = 10;
line(i+20, 160, i+20, 164); //6 o'clock line
//delay(msec); //after a delay
if(i % 3 == 0) {
setcolor(0); //erase it
line(i+20, 160, i+20, 164);
}
setcolor(3);
line(i+20, 160, i+16, 163); //8 o'clock line
//delay(msec); //after a delay
if(i % 4 == 0) {
setcolor(0); //erase it
line(i+20, 160, i+16, 163);
}
setcolor(3);
line(i+20, 160, i+10, 160); //9 o'clock
//delay(msec);
if(i % 5 == 0) {
setcolor(0);
line(i+20, 160, i+10, 160);
}
setcolor(3);
line(i+20, 160, i+15, 158); //10 o'clock
//delay(msec);
if(i % 6 == 0) {
setcolor(0);
line(i+20, 160, i+15, 158);
}
setcolor(3);
line(i+20, 160, i+20, 156); //12 o'clock
delay(msec);
if(i % 7 == 0) {
setcolor(0);
line(i+20, 160, i+20, 156);
}
setcolor(3);
line(i+20, 160, i+25, 158); //2 o'clock
delay(msec);
if(i % 8 == 0) {
setcolor(0);
line(i+20, 160, i+25, 158);
}
setcolor(3);
line(i+20, 160, i+30, 160); //3 o'clock
delay(msec);
if(i % 9 == 0) {
setcolor(0);
line(i+20, 160, i+30, 160);
}
setcolor(3);
line(i+20, 160, i+25, 162); //4 o'clock
delay(msec);
if(i % 10 == 0) {
setcolor(0);
line(i+20, 160, i+25, 162);
}
delay(msec); //was 25
cleardevice(); //last o'clock line erased here
}
closegraph();
return 0;
}
The delay before erasing gave way to a better looking scheme involving the a sliding scale use of mod on i, to determine if a line should be erased.