Program : Rotating Wheel on Inclined Plane
#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,x1,y1,x2,y2,m,x,y; //variable initializations
int stepx,stepy, no_of_steps,i;
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:");
getch();
exit(1); //return with error code
}
x1=10;
y1=300;
x2=300; //initializing inclined plane
y2=10;
m=(float)(y2-y1)/(x2-x1); //computing slope
setcolor(BLUE);
line(x1+140,x2,y1+140,y2); //draw line for plane
x=x1+140;y=y1+140;
i=0;
no_of_steps=abs(y2-y1);
while(i<no_of_steps) //while not bottom
{
y1=y1+m;
x1=x1+1; //updating coordinates
setcolor(RED);
line(x1,y1,x1+100*cos(3.14*i/180),y1+100*sin(3.14*i/180));
line(x1,y1,x1-100*cos(3.14*i/180),y1-100*sin(3.14*i/180));
circle(x1,y1,100); //draw wheel
delay(20);
setcolor(0);
line(x1,y1,x1+100*cos(3.14*i/180),y1+100*sin(3.14*i/180));
line(x1,y1,x1-100*cos(3.14*i/180),y1-100*sin(3.14*i/180));
circle(x1,y1,100); //rolling wheel
delay(20);
i++;
setcolor(RED);
line(x,x2,y,y2); //draw line
}
closegraph();
return 0; //terminate
}
0 comments:
Post a Comment