Program : Rotating Wheel
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h> //header file inclusion
#include <conio.h>
#include<math.h>
int main(void) //main function
{
int gdriver = DETECT, gmode, errorcode,i,x1,y1;
initgraph(&gdriver, &gmode, "D:\\TC\\"); //initializing graphics window
errorcode = graphresult();
if (errorcode != grOk) //an error occurred
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:"); //error recovery
getch();
exit(1); //return with error code
}
printf("\n\nenter the centre coordinates of the circle");
scanf("%d%d",&x1,&y1); //Inputting circle center
for(i=0;i<360;i++)
{
setcolor(RED);
line(x1,y1,x1+100*cos(3.14*i/180),y1+100*sin(3.14*i/180)); //draw lines for wheel
line(x1,y1,x1-100*cos(3.14*i/180),y1-100*sin(3.14*i/180)); //draw lines for wheel
circle(x1,y1,100); //draw circle
delay(20);
setcolor(0);
line(x1,y1,x1+100*cos(3.14*i/180),y1+100*sin(3.14*i/180)); //draw lines for wheel
line(x1,y1,x1-100*cos(3.14*i/180),y1-100*sin(3.14*i/180)); //draw lines for wheel
circle(x1,y1,100); //draw circle
delay(20);
x1++; //translate circle
y1++;
}
closegraph();
return 0; //terminate
}
0 comments:
Post a Comment