Write a program to rotate a wheel clockwise or anticlockwise as per user’s choice.


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
          
#define R 3.14/180

void drawline(int, int, int , int, int);

void main()
{
int gdriver=DETECT, gmode,i,d,ch,x,y,r;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
cleardevice();

x=getmaxx()/2,    y=getmaxy()/2;
printf("Enter the Radius of the circle : ");
scanf("%d",&r);
printf("\n\n1.Clockwise -> Up-Arrow Key   \n2.Anticlockwise -> Down-Arrow Key");
printf("\n\nEnter the Direction of circle rotation : ");
ch = getch();

for(i=0 ; ; i++)
{
       if(kbhit())
       {
             ch = getch();
             if (ch == 72)
                   d = 1;
             else if (ch == 80)
                   d = -1;
             else if (ch == '\x1B')
                   exit(0);
       }
       drawline(x,y,r,d*i,15);
       circle(x,y,r);
       delay(300);
       drawline(x,y,r,d*i,0);
}
}
void drawline(int x, int y, int r, int a, int c)
{
setcolor(c);
line(x+r*cos(0*R+a),y+r*sin(0*R+x+r*cos(180*R+a),y+r*sin(180*R+a);
line(x+r*cos(45*R+a),y+r*sin(45*R+a),x+r*cos(225*R+a),y+r*sin(225*R+a);
line(x+r*cos(90*R+a), y+r*sin(90*R+a), x+r*cos(270*R+a),y+r*sin(270*R+a));
line(x+r*cos(135*R+a),y+r*sin(135*R+a),x+r*cos(315*R+a),y+r*sin(315*R+a));
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP