0% found this document useful (0 votes)
72 views

Implement The C Program That Creates Animated Clock

This C program implements an animated clock by creating three line structures to represent the hour, minute, and second hands. It uses trigonometric functions like sine and cosine within a rotate function to manipulate the x and y coordinates of the lines based on continuously changing theta values, simulating clock hand rotation. The main draws the clock face as a circle and calls rotate in a loop to redraw the updated hands and display animation until the user presses a key.

Uploaded by

Neha Chindaliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Implement The C Program That Creates Animated Clock

This C program implements an animated clock by creating three line structures to represent the hour, minute, and second hands. It uses trigonometric functions like sine and cosine within a rotate function to manipulate the x and y coordinates of the lines based on continuously changing theta values, simulating clock hand rotation. The main draws the clock face as a circle and calls rotate in a loop to redraw the updated hands and display animation until the user presses a key.

Uploaded by

Neha Chindaliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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;
}

You might also like