C++ code to Display Time as an Analog Clock


bosky101

New Member
Disciple
Jan 24, 2005
465
90
0
35
bosky101.blogspot.com
Folowing is a program made in TurboC ,for displaying the system time as a analog clock in the output.Since i was jobless thought id post the code here as well .Nothing much,pretty small toobut just goes to show that reading the tuorials and samples from within the documentation can help u a lot even in turboC.you'll have to use ctrl+break to come out of it.

Code:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
int main()
{
clrscr(); [b]//to clear anything else you may have been doing[/b]
struct time *t1;      //c++ has this structure made available from dos.h
  [B] // or use 
  //struct dostime_t t; _dos_gettime(&t);
  // then use t.hour , t.min , t.sec as values directly[/B]
int gdriver =DETECT,gmode;
initgraph(&gdriver,&gmode,"");
while(1)
{[B]//start infinite loop ,to keep updating time[/B]
gettime(t1); 
circle(300,150,100); [B]// the basic clock outline[/B]
printf("The current time is: %2d:%02d:%02d.%02d\n", t1->ti_hour,t1->ti_min,t1->ti_sec); //print time for debugging etc
if ( (t1->ti_hour) >12) {t1->ti_hour=t1->ti_hour-12;} [b]//change from 24 hour scale[/b]
setfillstyle(1,BLUE);[b]//filling color[/b]
pieslice(300,150,(360-(t1->ti_hour*30))+90,(360-(t1->ti_hour*30))+95,40);
setfillstyle(1,RED);
pieslice(300,150,360-(t1->ti_min *6)+90,360-(t1->ti_min*6)+95,80);
pieslice(300,150,360-(t1->ti_sec *6)+90,360-(t1->ti_sec*6)+91,90);
sleep(1);
cleardevice(); [b]//before refreshing the device[/b]
}[b]//end while[/b]
getch();
closegraph();
return 0; [b]// since return type is int[/b]
}
"You have permission to rip of the follwoing code for use in your programs :p" - bosky101
(gee i never thought id reach a stage to say those legal blah blah stuff that u see in all those huge documentaitons and open source projects ..sniff sniff ..well theres always a start )
 
  • Like
Reactions: 2 people

bosky101

New Member
Disciple
Jan 24, 2005
465
90
0
35
bosky101.blogspot.com
The C language itself does not support graphics. What you'll want to
learn is a particular graphics library (or API, to be more accurate)
in a specific environment.

Resource
1.Easy Graphics: A Beginner's Guide to SVGAlib
SVGAlib is a low-level graphics library for Linux. It augments the C programming language, which doesn't provide support for graphics.
Intersting to note that the follwong are available in the SVGAlib programs site:hap2:
Doom
Fastball
Fastball 2
Font Builder
Fractal Fern
Land - Fractal landscapes
Punch Bill Gates
Quake
Sasteroids - Arcade classic
Binary available here
Staipan
Traffic Signal Simulator
vmanpg
v/xhyperoid
zblast - Shoot-em-up
zgv - Picture viewer
2.OpenGL Programming
OpenGL is a hardware dependant graphics library that was designed using the C++ programming language. The OpenGL source code is distributed by Silicon Graphics, Inc. and is open for the public to download free. OpenGL's popularity in the past few years has grown tremendously because of it open source code, and elegant design, and ease of use.
3.Graphics/Multimedia, 2D/3D api's and tools ,you may find interesting.

4.Basic Graphics Routines in C & Assembly Language
5.some sample programs here and ...more
 

hooman_8050

New Member
Disciple
Jun 7, 2005
6
0
0
i have no idea

hooman_8050 posted 0.73 minutes later:

me be but may be not

hooman_8050 posted 0.45 minutes later:

i just want to have 10 post
 

wahb

New Member
Recruit
Oct 8, 2005
1
0
0
what must be include here
#include
#include
#include
#include
#include
please hlep as soon as u can

wahb
 

Genius

New Member
Disciple
Aug 30, 2005
320
9
0
34
Will give errors... What to includ here is,

#include<graphics.h>//for grafix stuff

#include<dos.h>//for time struct

#include<conio.h>//for getch()

Anything ore required??? i dont think so...