COMPUTER GRAPHICS
SUBMITTED TO: SUBMITTED FROM:
PRABHA SHARMA MAM NAME: PRAVEEN KUMAR
ROLL NO: SG21336
CSE 5th SEM
Computer Science & Engineering
University Institute of Engineering and Technology
Panjab University SSG Regional Centre, Hoshiarpur
INDEX
S.NO Description Page No
1 Write a Program to Draw a Hut 3
2 Write a Program to draw a Flag 5
3 Write a Program for Moving Fish 7
4 Write a Program for a Flying Kite 8
5 Write a Program for a Landscape 10
6 Write a Program for a Moving Clock 21
7 Write a Program for a Moving Car 28
8 Write a Program for a Human Emotion Face 30
9 Write a Program for any Historical Building 32
(TAJ MAHAL)
10 Write a Program for a Digital Clock 44
1. write a program to draw a hut.
// C program to draw a house using graphics.h library
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
// Driver Code
void main ()
{
// Initialize of gdriver with DETECT macros
int gdriver = DETECT, gmode;
// Initialize structure of the house
initgraph (&gdriver, &gmode, "");
// Create lines for structure of the House
line(100, 100, 150, 50);
line(150, 50, 200, 100);
line(150, 50, 350, 50);
line(350, 50, 400, 100);
// Draw rectangle to give proper shape to the house
rectangle(100, 100, 200, 200);
rectangle(200, 100, 400, 200);
rectangle(130, 130, 170, 200);
rectangle(250, 120, 350, 180);
// Set color using setfillstyle() which take style and color as an argument
setfillstyle(2, 3);
// Fill the shapes with colors white
floodfill(131, 131, WHITE);
floodfill(201, 101, WHITE);
// Change the filling color
setfillstyle(11, 7);
// Fill the shapes with changed colors
floodfill(101, 101, WHITE);
floodfill(150, 52, WHITE);
floodfill(163, 55, WHITE);
floodfill(251, 121, WHITE);
// Close the initialized gdriver
closegraph();
}
2. write a program to draw a flag.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
int main ()
{
int gdriver = DETECT, gmode, a, b, i, r,x,y;
initgraph(&gdriver, &gmode ,"C:\\TC\\BGI");
//draw the bottom rectangle
setfillstyle(SOLID_FILL,1);
rectangle(10,320,200,340);
floodfill(11,321,15);
rectangle(30,300,175,320);
floodfill(31,301,15);
rectangle(50,280,155,300);
floodfill(51,281,15);
//pole
setfillstyle(SOLID_FILL,3);
rectangle(100,38,110,280);
floodfill(101,39,15);
//draw the top rectangle
setfillstyle(SOLID_FILL,RED);
rectangle(110,40,220,58);
floodfill(111,43,15);
setfillstyle(SOLID_FILL,15);
rectangle(110,58,220,78);
floodfill(111,59,15);
setfillstyle(SOLID_FILL,GREEN);
rectangle(110,78,220,98);
floodfill(111,79,15);
//Ashok chakra
a=160;
b=68;
r=13;
setcolor(BLUE);
circle(a,b,r);
for(i=0;i<=360;i=i+25)
{
x=r*cos(i*3.14/180);
y=r*sin(i*3.14/180);
line(a,b,a+x,b-y);
}
getch();
return 0;
closegraph();
}
3. write a program to draw a moving fish.
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<ctype.h>
void main () {
int gd=DETECT,gm;
int newx=0,newy=0,inc_y=5;
initgraph(&gd,&gm," ");
cleardevice();
while(!kbhit()) {
ellipse(520-newx,200,30,330,90,30);
circle(450-newx,193,3);
line(430-newx,200,450-newx,200);
line(597-newx,185,630-newx,170);
line(597-newx,215,630-newx,227);
line(630-newx,170,630-newx,227);
line(597-newx,200,630-newx,200);
line(597-newx,192,630-newx,187);
line(597-newx,207,630-newx,213);
line(500-newx,190,540-newx,150+newy);
line(530-newx,190,540-newx,150+newy);
if(new x>=500)
new x = 0;
if(new y>=82)
int_y = -5;
new x = new x+5;
if(new y<=0)
int_y = 5;
new y = new y +int_y;
delay(50);
cleardevice();
}
cleardevice();
}
4. write a program for a flying kite.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gm,gd=DETECT;
int i= 0,j=0,rnd_x=0,rnd_y,stop_me=0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
srand(time());
while(stop_me<=1000)
{
if(i>=180 &&j>=100 ) // controlling kite, so that it wouldn't disappear from screen
{
rnd_x = rand()%4 -3;
rnd_y = rand()%5 -4;
}
else{
rnd_x = rand()%3;
rnd_y = rand()%3;
}
line(200+i,200-j,250+i,250-j);
line(200+i,200-j,150+i,250-j);
line(150+i,250-j,200+i,350-j);
line(200+i,350-j,250+i,250-j);
line(200+i,200-j,200+i,350-j);
arc(200+i,275-j,25,155,50);
line(0,500,200+i,225-j);
i= i+rnd_x;
j= j+rnd_y;
stop_me = 5+stop_me;
delay(100);
clearviewport(); // clearing image which would make illusion of flying kite
}
getch();
closegraph();
5. write a program for a landscape.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define x 500
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax,i;
int poly[100];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/*************************/
/* draw a diagonal line */
delay(x);
line(10, 10, 600, 10);
delay(x);
line(600,10,600,450);
delay(x);
line(600,450,10,450);
delay(x);
line(10,450,10,10);
/*mountain 1*/
delay(x);
line(10,250,180,50);
delay(x);
line(180,50,380,270);
delay(x);
line(360,250,600,250);
delay(x);
line(450,250,600,150);
/*mountain1 co*/
poly[0]=10;
poly[1]=250;
poly[2]=180;
poly[3]=50;
poly[4]=380;
poly[5]=270;
poly[6]=10;
poly[7]=280;
delay(x);
setfillstyle(1,6);
delay(x);
fillpoly(4,poly);
/*mountein 2 */
delay(x);
line(315,200,400,100);
delay(x);
line(400,100,520,200);
delay(x);
line(10,280,380,270);
/*mountain2*/
poly[0]=315;
poly[1]=200;
poly[2]=400;
poly[3]=100;
poly[4]=520;
poly[5]=200;
poly[6]=450;
poly[7]=250;
poly[8]=360;
poly[9]=250;
setfillstyle(12,6);
delay(x);
fillpoly(5,poly);
/*3rd mountain*/
poly[0]=450;
poly[1]=250;
poly[2]=600;
poly[3]=250;
poly[4]=600;
poly[5]=150;
setfillstyle(1,6);
delay(x);
fillpoly(3,poly);
/*river*/
line(420,250,500,300);
delay(x);
line(500,300,400,370);
delay(x);
line(400,370,500,370);
delay(x);
line(500,370,290,450);
/*3d view*/
delay(x);
line(500,300,500,325);
delay(x);
line(500,325,440,340);
delay(x);
line(500,370,500,400);
delay(x);
line(500,400,390,410);
/*river colour*/
poly[0]=420;
poly[1]=250;
poly[2]=600;
poly[3]=250;
poly[4]=600;
poly[5]=450;
poly[6]=290;
poly[7]=450;
poly[8]=390;
poly[9]=410;
poly[10]=500;
poly[11]=400;
poly[12]=500;
poly[13]=370;
poly[14]=400;
poly[15]=370;
poly[16]=440;
poly[17]=340;
poly[18]=500;
poly[19]=325;
poly[20]=500;
poly[21]=300;
poly[22]=420;
poly[23]=250;
setfillstyle(1,1);
delay(x);
fillpoly(12,poly);
/*land fill*/
poly[0]=10;
poly[1]=280;
poly[2]=380;
poly[3]=270;
poly[4]=360;
poly[5]=250;
poly[6]=420;
poly[7]=250;
poly[8]=500;
poly[9]=300;
poly[10]=400;
poly[11]=370;
poly[12]=500;
poly[13]=370;
poly[14]=290;
poly[15]=450;
poly[16]=10;
poly[17]=450;
setfillstyle(9,2);
delay(x);
fillpoly(9,poly);
//Water //
arc(550,430,30,160,15);
arc(450,450,30,160,20);
arc(585,375,30,160,10);
arc(500,350,30,160,10);
arc(560,300,30,160,10);
arc(525,305,30,160,5);
arc(545,375,30,160,15);
/* sky fill*/
poly[0]=10;
poly[1]=10;
poly[2]=10;
poly[3]=250;
poly[4]=180;
poly[5]=50;
poly[6]=315;
poly[7]=200;
poly[8]=400;
poly[9]=100;
poly[10]=520;
poly[11]=200;
poly[12]=600;
poly[13]=150;
poly[14]=600;
poly[15]=10;
setfillstyle(1,9);
delay(x);
fillpoly(8,poly);
/*hut*/
delay(x);
line(310,370,350,370);
delay(x);
line(350,370,400,340);
delay(x);
line(350,370,350,320);
delay(x);
line(310,370,310,320);
delay(x);
line(305,325,330,300);
delay(x);
line(330,300,355,325);
delay(x);
line(355,325,405,310);
delay(x);
line(400,340,400,310);
delay(x);
line(330,300,388,290);
delay(x);
line(388,290,405,310);
poly[0]=320;
poly[1]=370;
poly[2]=320;
poly[3]=330;
poly[4]=335;
poly[5]=330;
poly[6]=335;
poly[7]=370;
drawpoly(4,poly);
setfillstyle(1,11);
//Change RED to WHITE.
delay(x);
floodfill(322,365,WHITE);
/*front wall*/
setfillstyle(10,6);
//Change RED to WHITE.
delay(x);
floodfill(312,365,WHITE);
/*front wall*/
setfillstyle(8,6);
//Change RED to WHITE.
delay(x);
floodfill(390,294,WHITE);
setfillstyle(5,4);
//Change RED to WHITE.
delay(x);
floodfill(355,327,WHITE);
/* clean up */
/* sun*/
arc(315,195,40,140,30);
setfillstyle(1,14);
//Change RED to WHITE.
delay(x);
floodfill(317,190,WHITE);
delay(x);
line(285,160,265,120);
line(295,155,285,130);
line(300,150,290,110);
line(308,150,305,115);
line(315,150,320,110);
line(320,150,328,105);
line(330,150,340,110);
line(340,155,360,110);
/*maker*/
delay(x);
moveto(15, 435);
/* output text starting at the C.P. */
outtext("Mayank ");
outtext("Khare // mail // ");
outtext("[email protected] ");
/*close*/
getch();
closegraph();
return 0;
}
6. write a program for a moving clock.
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
int xmax, ymax, x, y, i = 0, j = 0, k = 0, m = 0, s = 0, h = 0, m1 = 0;
float l = 0.0;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
xmax = getmaxx();
ymax = getmaxy();
x = xmax / 2;
y = ymax / 2;
setcolor(15);
setbkcolor(0);
rectangle(x + 150, y - 200, x + 300, y - 170);
line(x + 200, y - 200, x + 200, y - 170);
line(x + 250, y - 200, x + 250, y - 170);
circle(x, y, 179);
circle(x, y, 180);
setfillstyle(0, 0);
floodfill(x, y, 0);
settextstyle(1, 0, 4);
outtextxy(x - 200, y - 25, "9");
outtextxy(x + 186, y - 25, "3");
outtextxy(x - 20, y - 220, "12");
outtextxy(x - 10, y + 176, "6");
outtextxy(x + 90, y - 195, "1");
outtextxy(x + 165, y - 120, "2");
outtextxy(x + 155, y + 80, "4");
outtextxy(x + 86, y + 152, "5");
outtextxy(x - 109, y + 148, "7");
outtextxy(x - 180, y + 72, "8");
outtextxy(x - 195, y - 120, "10");
outtextxy(x - 120, y - 195, "11");
settextstyle(1, 0, 3);
outtextxy(0, ymax - 30, "PRESS ANY KEY FOR STOP");
outtextxy(x + 150, y + 210, "PUSKAR JASU");
settextstyle(1, 0, 6);
outtextxy(0, 0, "CLOCK");
while (!kbhit())
{
setcolor(14);
if (m == 60)
{
if (k <= 90)
{
setcolor(14);
pieslice(x, y, 91 - k, 90 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);
pieslice(x, y, 97 - k, 96 - k, 175);
}
if (k > 90)
{
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175);
}
if (k == 360)
k = 0;
k = k + 6;
}
else
{
if (k <= 90)
{
pieslice(x, y, 91 - k, 90 - k, 175);
setcolor(0);
pieslice(x, y, 97 - k, 96 - k, 175);
}
if (k > 90)
{
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175);
}
}
setcolor(4);
if (j == 60 * 5)
{
if (l <= 90)
{
setcolor(4);
pieslice(x, y, 91 - l, 90 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175);
}
if (l > 90)
{
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175);
}
if (l == 360)
l = 0;
l = l + 2.5;
}
else
{
if (l <= 90)
{
setcolor(4);
pieslice(x, y, 91 - l, 90 - l, 175);
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175);
}
if (l > 90)
{
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175);
}
}
if (i <= 90)
{
setcolor(10);
pieslice(x, y, 91 - i, 90 - i, 175);
delay(1000);
sound(220);
delay(5);
nosound();
setcolor(0);
pieslice(x, y, 91 - i, 90 - i, 175);
}
if (i > 90)
{
setcolor(10);
pieslice(x, y, 451 - i, 450 - i, 175);
delay(1000);
sound(220);
delay(5);
nosound();
setcolor(0);
pieslice(x, y, 451 - i, 450 - i, 175);
}
if (i == 360)
i = 0;
i = i + 6;
s = i / 6;
if (j == 60 * 5)
j = 0;
j++;
if (m == 60)
m = 0;
m++;
if (s == 60)
{
m1++;
s = 0;
}
if (h == 24)
h = 0;
if (m1 == 60)
{
h++;
m1 = 0;
}
gotoxy(62, 4);
printf("%02d", h);
gotoxy(68, 4);
printf("%02d", m1);
gotoxy(74, 4);
printf("%02d", s);
s++;
}
getch();
closegraph();
return 0;
}
7. write a program for a moving car.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gd=DETECT;
int i= 0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
while(i<=800)
{
line(0,300,800,300); // Path
//Body of the car
line(50+i,220,100+i,220);
line(50+i,220,30+i,250);
line(100+i,220,120+i,250);
rectangle(0+i,250,160+i,270);
// Tyres of the car
circle(30+i,285,12);
circle(130+i,285,12);
if(i>=800)
{
break;
}
i=i+2;
clearviewport(); // clearing image which would make illusion of moving car
}
getch();
closegraph();
}
8. write a program for a face with emotion.
// C program to create a smiley face
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdio.h>
// Driver Code
int main()
{
// Initialize graphic driver
int gr = DETECT, gm;
// Initialize graphics mode by passing
// three arguments to initgraph function
// &gdriver is the address of gdriver
// variable, &gmode is the address of
// gmode and "C:\\Turboc3\\BGI" is the
// directory path where BGI files
// are stored
initgraph(&gr, &gm, "C:\\Turboc3\\BGI");
// Set color of smiley to yellow
setcolor(YELLOW);
// creating circle and fill it with
// yellow color using floodfill.
circle(300, 100, 40);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(300, 100, YELLOW);
// Set color of background to black
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
// Use fill ellipse for creating eyes
fillellipse(310, 85, 2, 6);
fillellipse(290, 85, 2, 6);
// Use ellipse for creating mouth
ellipse(300, 100, 205, 335, 20, 9);
ellipse(300, 100, 205, 335, 20, 10);
ellipse(300, 100, 205, 335, 20, 11);
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system
closegraph();
return 0;
}
9. write a program for any historical building.
// C program to implement the above approach
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
// Declaring functions used in this program
void taj_body();
void left_minars();
void right_minars();
// Driver Code
void main()
{
int gd = DETECT, gm;
// Initialize of gdriver with
// DETECT macros
initgraph(&gd, &gm, "C:\\turboc3\\bgi");
// Calling taj_body() function
taj_body();
// Calling left_minars() function
left_minars();
// Calling right_minars() function
right_minars();
// Holding screen for a while
getch();
// Close the initialized gdriver
closegraph();
}
void taj_body()
{
// Main Base
rectangle(10, 650, 1350, 680);
rectangle(550, 300, 800, 650);
rectangle(540, 290, 810, 650);
// Left Door Line
line(600, 650, 600, 400);
// Right Door Line
line(750, 650, 750, 400);
line(600, 400, 675, 390);
line(675, 390, 750, 400);
arc(675, 240, 330, 210, 155);
// Main Finial
line(655, 85, 675, 30);
line(675, 30, 695, 87);
// Left Side
line(540, 315, 445, 315);
arc(490, 315, 0, 180, 45);
// Left Finial
line(480, 270, 490, 250);
line(490, 250, 500, 270);
// Left Vertical Line
line(445, 315, 445, 355);
// Lower Left Join
line(445, 355, 540, 355);
// Again Lower Left Join
line(445, 375, 540, 375);
// Left Tangent
line(445, 355, 375, 370);
// Lower Left Tangent
line(445, 375, 375, 390);
// Left Last Vertical
line(375, 370, 375, 650);
// Middle Left Rectangle
rectangle(450, 390, 530, 650);
// Left Rectangle Divider
line(450, 520, 530, 520);
// Left Rectangle Side Structure
line(440, 650, 440, 390);
line(385, 650, 385, 405);
line(440, 390, 385, 405);
// Divider
line(440, 520, 385, 520);
// Creating Left Lower Spike
line(460, 650, 460, 585);
line(520, 650, 520, 585);
line(460, 585, 490, 555);
line(520, 585, 490, 555);
// Creating Left Upper Spike
line(460, 520, 460, 455);
line(520, 520, 520, 455);
line(460, 455, 490, 425);
line(520, 455, 490, 425);
// Right Side
line(810, 315, 905, 315);
arc(860, 315, 0, 180, 45);
// Right Finial
line(850, 270, 860, 250);
line(860, 250, 870, 270);
// Right Vertical Line
line(905, 315, 905, 355);
line(905, 355, 810, 355);
// Lower Right Join
line(905, 355, 810, 355);
// Again Right Left Join
line(905, 375, 810, 375);
// Right Tangent
line(905, 355, 975, 370);
// Lower Right Tangent
line(905, 375, 975, 390);
// Right Last Vertical
line(975, 370, 975, 650);
// Middle Right Rectangle
rectangle(820, 390, 900, 650);
// Right Rectangle Divider
line(820, 520, 900, 520);
// Right Rectangle Side Structure
line(910, 650, 910, 390);
line(965, 650, 965, 405);
line(910, 390, 965, 405);
// Divider
line(910, 520, 965, 520);
// Creating Right Lower Spike
line(830, 650, 830, 585);
line(890, 650, 890, 585);
line(830, 585, 860, 555);
line(890, 585, 860, 555);
// Creating Right Upper Spike
line(830, 520, 830, 455);
line(890, 520, 890, 455);
line(830, 455, 860, 425);
line(890, 455, 860, 425);
}
void left_minars()
{
// 1st Left Minar
// 1st Step
line(20, 650, 30, 500);
line(120, 650, 110, 500);
line(110, 500, 30, 500);
// 2nd Step
line(30, 500, 20, 480);
line(110, 500, 120, 480);
line(120, 480, 20, 480);
line(30, 480, 40, 330);
line(110, 480, 100, 330);
line(40, 330, 100, 330);
line(40, 330, 30, 310);
line(100, 330, 110, 310);
line(110, 310, 30, 310);
// 3rd Step
line(40, 310, 50, 160);
line(100, 310, 90, 160);
line(50, 160, 90, 160);
line(50, 160, 40, 140);
line(90, 160, 100, 140);
line(40, 140, 100, 140);
line(40, 140, 60, 120);
line(100, 140, 80, 120);
line(60, 120, 80, 120);
line(60, 120, 70, 100);
line(70, 100, 80, 120);
// 2nd Left Minar
// 1st Step
line(170, 650, 180, 575);
line(270, 650, 260, 575);
line(180, 575, 260, 575);
// 2nd Step
line(180, 575, 170, 555);
line(260, 575, 270, 555);
line(170, 555, 270, 555);
line(180, 555, 190, 480);
line(260, 555, 250, 480);
line(190, 480, 250, 480);
// 3rd Step
line(190, 480, 180, 460);
line(250, 480, 260, 460);
line(180, 460, 260, 460);
line(190, 460, 200, 385);
line(250, 460, 240, 385);
line(200, 385, 240, 385);
line(200, 385, 190, 365);
line(240, 385, 250, 365);
line(190, 365, 250, 365);
line(190, 365, 210, 345);
line(250, 365, 230, 345);
line(210, 345, 230, 345);
line(210, 345, 220, 325);
line(220, 325, 230, 345);
}
void right_minars()
{
// 1st Right Minar
// 1st Step
line(1340, 650, 1330, 500);
line(1240, 650, 1250, 500);
line(1330, 500, 1250, 500);
// 2nd Step
line(1330, 500, 1340, 480);
line(1250, 500, 1240, 480);
line(1240, 480, 1340, 480);
line(1330, 480, 1320, 330);
line(1250, 480, 1260, 330);
line(1320, 330, 1260, 330);
line(1320, 330, 1330, 310);
line(1260, 330, 1250, 310);
line(1250, 310, 1330, 310);
// 3rd Step
line(1320, 310, 1310, 160);
line(1260, 310, 1270, 160);
line(1310, 160, 1270, 160);
line(1310, 160, 1320, 140);
line(1270, 160, 1260, 140);
line(1320, 140, 1260, 140);
line(1320, 140, 1300, 120);
line(1260, 140, 1280, 120);
line(1300, 120, 1280, 120);
line(1280, 120, 1290, 100);
line(1290, 100, 1300, 120);
// 2nd Right Minar
// 1st Step
line(1090, 650, 1100, 575);
line(1190, 650, 1180, 575);
line(1100, 575, 1180, 575);
// 2nd Step
line(1100, 575, 1090, 555);
line(1180, 575, 1190, 555);
line(1090, 555, 1190, 555);
line(1100, 555, 1110, 480);
line(1180, 555, 1170, 480);
line(1110, 480, 1170, 480);
// 3rd Step
line(1110, 480, 1100, 460);
line(1170, 480, 1180, 460);
line(1180, 460, 1100, 460);
line(1110, 460, 1120, 385);
line(1170, 460, 1160, 385);
line(1120, 385, 1160, 385);
line(1110, 365, 1120, 385);
line(1160, 385, 1170, 365);
line(1110, 365, 1170, 365);
line(1110, 365, 1130, 345);
line(1170, 365, 1150, 345);
line(1130, 345, 1150, 345);
line(1130, 345, 1140, 325);
line(1140, 325, 1150, 345);
}
10. write a program for digital clock.
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <time.h>
#include <dos.h>
#include <string.h>
int main() {
/* request auto detection */
int gdriver = DETECT, gmode;
int midx, midy, err;
long mytime;
char date[256];
/* initialize graphic mode */
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != 0) {
/* error occurred */
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
}
/* mid positions in x and y axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* mid positions in x and y axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
while (!kbhit()) {
/* clears graphic screen */
cleardevice();
/* get time in seconds */
mytime = time(NULL);
/* store the date and time in the given string */
strcpy(date, ctime(&mytime));
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);
/* locate the postion to write */
moveto(midx, midy);
/* print the date and time */
outtext(date);
/* sleep for a second */
sleep(1);
}
getch();
/* deallocate memory allocated for graphic screen */
closegraph();
return 0;
}