Implement The C Program That Creates Animated Clock
Implement The C Program That Creates Animated Clock
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
struct line
{
int x1,x2,y1,y2,mx,my;
};
void rotate(struct line l1,float t) {
struct line l2;
l2.x1=l1.x1*cos(t)+l1.y1*sin(t)+(1-cos(t))*l1.mx-l1.my*sin(t);
l2.y1=(l1.x1*sin(t))*(-1)+l1.y1*cos(t)+(1-cos(t))*l1.my+l1.mx*sin(t);
l2.x2=l1.x2*cos(t)+l1.y2*sin(t)+(1-cos(t))*l1.mx-l1.my*sin(t);
l2.y2=(l1.x2*sin(t))*(-1)+l1.y2*cos(t)+(1-cos(t))*l1.my+l1.mx*sin(t);
line(l2.x1,l2.y1,l2.x2,l2.y2);
}
int main(void)
{
struct line l1,l2,l3;
intgdriver = DETECT, gmode, errorcode;
inti,theta=360,theta2=360,theta3=360;
float t,t2,t3,c=0;
initgraph(&gdriver, &gmode, "");
detectgraph(&gdriver, &gmode);
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
l1.x1=250;
l1.y1=250 ;
l1.x2=250 ;
l1.y2=185 ;
l1.mx=(l1.x1);
l1.my=(l1.y1);
l2=l1;
l2.y2=200;
l3=l2;
l3.y2=225;
circle(l1.x1,l1.y1,100);
t=(3.14)*theta/180;
t2=(3.14)*theta2/180;
t3=(3.14)*theta3/180;
while(c!=78)
{
if(theta==0)
theta=360;
if(theta2==0)
theta2=360;
if(theta3==0)
theta3=360;
t=(3.14)*theta/180;
t2=(3.14)*theta2/180;
t3=(3.14)*theta3/180;
if(theta2==360)
theta3=theta3-30;
if(theta==360)
theta2=theta2-6;
theta=theta-6;
rotate(l1,t);
rotate(l2,t2);
rotate(l3,t3);
circle(l1.x1,l1.y1,100);
sleep(1);
cleardevice();
c++;
}
getch();
closegraph();
return 0;
}