Friday, January 24, 2014

C graphics program to display Digital Clock

#include<dos.h>
#include<conio.h>
#include<graphics.h>

void main()
{
int gd=DETECT,gm,hr,min,sec;
char x[3],y[3],z[3];
static struct time *t;
initgraph(&gd,&gm,"..\\bgi");
setcolor(3);
rectangle(150,100,500,200);
setcolor(4);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
outtextxy(257,125,":");
outtextxy(367,125,":");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(250,50,"Digital Clock");
setcolor(6);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
while( kbhit()==0)
{
setcolor(15);
gettime(t);
hr=t->ti_hour;
min= t->ti_min;
sec=t->ti_sec;
sprintf(x,"%d",hr);
outtextxy(210,125,x);
sprintf(y,"%d",min);
outtextxy(320,125,y);
sprintf(z,"%d",sec);
outtextxy(430,125,z);
delay(1000);
setcolor(0);
outtextxy(430,125,z);
outtextxy(320,125,y);
outtextxy(210,125,x);
}
closegraph();
}



Tuesday, January 21, 2014

Animated Fan Rotation

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd= DETECT, gm,i,m;
initgraph(&gd,&gm,"..\\bgi");
while(kbhit()==0)
{
for(i=80;i>=0;i-=20)
{
setcolor(BLUE);
circle(320,240,65);
circle(320,240,67);
setfillstyle(SOLID_FILL,BLUE);
bar(310,307,330,360);
bar(290,360,350,375);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
pieslice(320,240,i,i+40,60);
pieslice(320,240,i+120,i+160,60);
pieslice(320,240,i+240,i+280,60);
setcolor(BLUE);
circle(320,240,10);
setfillstyle(SOLID_FILL,BLUE);
floodfill(320,240,BLUE);
delay(100);
setcolor(0);
setfillstyle(SOLID_FILL,0);
pieslice(320,240,i,i+40,60);
pieslice(320,240,i+120,i+160,60);
pieslice(320,240,i+240,i+280,60);
setcolor(BLUE);
circle(320,240,10);
setfillstyle(SOLID_FILL,BLACK);
floodfill(320,240,BLUE);
}
}
closegraph();
}

Analog Clock Program

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd= DETECT, gm,i,j=96,m;
float k=90.5;
initgraph(&gd,&gm,"..\\bgi");

rectangle(210,130,430,350);
circle(320,240,105);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
setcolor(14);
outtextxy(245,85,"Analog Clock");
setfillstyle(SOLID_FILL,4);
floodfill(211,131,15);
setfillstyle(SOLID_FILL,7);
floodfill(320,240,15);
settextstyle(GOTHIC_FONT,HORIZ_DIR,1);
outtextxy(315,130,"12");
outtextxy(370,145,"1");
outtextxy(402,182,"2");
outtextxy(415,228,"3");
outtextxy(398,280,"4");
outtextxy(360,313,"5");
outtextxy(312,325,"6");
outtextxy(264,311,"7");
outtextxy(231,276,"8");
outtextxy(217,229,"9");
outtextxy(230,180,"10");
outtextxy(264,144,"11");
while(kbhit()==0)
{
k -=0.5;
j -=6;
for(i=90;i>=1;i-=6)   // required to start rotation from 12 'O clock position
{
if(kbhit()!=0) exit();
setcolor(15);
setfillstyle(SOLID_FILL,WHITE);
pieslice(320,240,i,i-1,80);
pieslice(320,240,j,j-1,65);
pieslice(320,240,k,k-1,50);
sleep(1);
setcolor(7);   // required to erase the just drawn arms
setfillstyle(SOLID_FILL,7);
pieslice(320,240,i,i-1,80);
pieslice(320,240,j,j-1,65);
pieslice(320,240,k,k-1,50);

}
for(i=359;i>=91;i -=6)
{
if(kbhit()!=0) exit();
setcolor(15);
setfillstyle(SOLID_FILL,WHITE);
pieslice(320,240,i,i-1,80);
pieslice(320,240,j,j-1,65);
pieslice(320,240,k,k-1,50);
sleep(1);
setcolor(7);
setfillstyle(SOLID_FILL,7);
pieslice(320,240,i,i-1,80);
pieslice(320,240,j,j-1,65);
pieslice(320,240,k,k-1,50);
}
if(j<=6) j=365;
if(k<=0.5) k=359;
}
}
closegraph();
}

Character Generation using BitMap

Program for character generation using bitMap

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd= DETECT, gm,i,j,m;
char c[8][8],s[1];  // needed to delcare 's' as string inorder to use it with outtextxy()
initgraph(&gd,&gm,"..\\bgi");
printf("Enter a Character:");
scanf("%s",s);
clearviewport();
outtextxy(1,1,s);
for(i=0;i<textwidth("S");i++)      // any  capital character can be given instead of S
{
for(j=0;j<textheight("S");j++)
{
c[i][j]=getpixel(i,j);
}
}
printf("Enter the size to enlarge the inputted character \n");
scanf("%d",&m);
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
setfillstyle(SOLID_FILL,c[i][j]);
bar(100+(i*m),100+(j*m),100+(i+1)*m,100+(j+1)*m);
}
}
getch();
closegraph();
}


Sample input :
                       Enter a Character: A
                       Enter the size to enlarge the inputted character: 30