Search
 
SCRIPT & CODE EXAMPLE
 

C

analog clock c code for turbo

/* Graphical Analog Clock designed in C*/
/*Note press ctrl+pause break to stop the clock while executing in TC*/
 
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<dos.h>
#include<time.h>
 
#define PI 3.147
 
void clockLayout();
void secHand();
void hrHand();
void minHand();
int maxx,maxy;
 
void main()
{
int gdriver=DETECT,gmode,error;
initgraph(&gdriver,&gmode,"c:	urboc3gi");
error=graphresult();
if(error!=grOk)
{
  printf("Error in graphics, code= %d",grapherrormsg(error));
  exit(0);
}
 
while(1)
{
  clockLayout();
  secHand();
  minHand();
  hrHand();
  sleep(1);                /* pausing the outputscreen for 1 sec */
  cleardevice();           /* clearing the previous picture of clock */
}
}
 
void clockLayout()
{
int i,x,y,r;
float j;
maxx=getmaxx();
maxy=getmaxy();
 
for(i=1;i<5;i++)
{                   /* printing a round ring with outer radius of 5 pixel */
  setcolor(YELLOW);
  circle(maxx/2,maxy/2,120-i);
}
 
pieslice(maxx/2,maxy/2,0,360,5);    /* displaying a circle in the middle of clock */
x=maxx/2+100;y=maxy/2;
r=100;
setcolor(BLUE);
 
for(j=PI/6;j<=(2*PI);j+=(PI/6))
{    /* marking the hours for every 30 degrees */
  pieslice(x,y,0,360,4);
  x=(maxx/2)+r*cos(j);
  y=(maxy/2)+r*sin(j);
}
 
x=maxx/2+100;y=maxy/2;
r=100;
setcolor(RED);
 
for(j=PI/30;j<=(2*PI);j+=(PI/30))
{  /* marking the minutes for every 6 degrees */
  pieslice(x,y,0,360,2);
  x=(maxx/2)+r*cos(j);
  y=(maxy/2)+r*sin(j);
}
}
 
void secHand()
{
struct time t;
int r=80,x=maxx/2,y=maxy/2,sec;
float O;
 
maxx=getmaxx();maxy=getmaxy();
gettime(&t);                     /*getting the seconds in system clock */
sec=t.ti_sec;
O=sec*(PI/30)-(PI/2);           /* determining the angle of the line with respect to vertical */
setcolor(YELLOW);
line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
}
 
void hrHand()
{
int r=50,hr,min;
int x,y;
struct time t;
float O;
 
maxx=getmaxx();
maxy=getmaxy();
x=maxx/2,y=maxy/2;
gettime(&t);                     /*getting the seconds in system clock */
hr=t.ti_hour;
min=t.ti_min;
 
/* determining the angle of the line with respect to vertical */
if(hr<=12)O=(hr*(PI/6)-(PI/2))+((min/12)*(PI/30));
if(hr>12) O=((hr-12)*(PI/6)-(PI/2))+((min/12)*(PI/30));
setcolor(BLUE);
line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
}
 
void minHand()
{
int r=60,min;
int x,y;
float O;
struct time t;
maxx=getmaxx();
maxy=getmaxy();
x=maxx/2;
y=maxy/2;
gettime(&t);  /*getting the seconds in system clock */
min=t.ti_min;
O=(min*(PI/30)-(PI/2)); /* determining the angle of the line with respect to vertical */
setcolor(RED);
line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
}
Comment

PREVIOUS NEXT
Code Example
C :: C program determines the height status for heights in cm 
C :: command line coursera 
C :: sue murry 
C :: Print the number 0 using write() 
C :: C #define preprocessor 
C :: c how to include variables of other c file 
C :: Laravel installation on Linux 
C :: profile time bash script 
C :: iulia vântur 
C :: C fgets() and puts() 
C :: function of science writing of a number 
C :: c text modifiers 
C :: how to get a string input in c 
C :: create a buffer in c 
C :: how to declare a structure in c 
C :: fibonacchi series in c 
C :: 4k stogram chave 
Dart :: flutter validate email 
Dart :: flutter sharedpreferences clear 
Dart :: round container flutter 
Dart :: canonical tag 
Dart :: options = null firebaseoptions cannot be null when creating the default app. flutter 
Dart :: flutter chip labelstyle 
Dart :: flutter loading images over network 
Dart :: flutter snackbar width 
Dart :: dart string to color 
Dart :: create publisher account on pub.dev 
Dart :: change password firebase flutter 
Dart :: dart almashtirish 
Dart :: flutter get argument values data 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =