C and C++ Programming Blog
RSS Feed

C Language Graphics Library Reference (part 3)

Tuesday, 5 February 2008 07:12

In the previous two posts I have discussed few important functions of graphics.h library in C Programming. As promised here is the sample function which will demonstrate the use of graphics functions and draw some nice shapes on the console. If you have followed the previous two posts the you will not find the source code difficult to compile and execute. If you still have any problems using the source code do let me know, and I will figure it out. If you are looking for more C Programming code then please click here.

#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <process.h>
void main(void)
{
int mx, my;
/* request auto detection */
int gd= DETECT, gm, errorcode;
initgraph(&gd,&gm,"F:\\tc\\bgi"); //Last argument is the path to the graphics library of Turbo C
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)  /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);             /* return with error code */
}
mx = (getmaxx() / 2);
my = (getmaxy() / 2);
//SET baqckground color
setfillstyle(9, 1);
bar(0,0,getmaxx(),getmaxy());
//DRAW a bar, and make it look like a 3d bar
setfillstyle(1,7);
//bar(50,20,600,400);
//DRAW lines for the top and left side
setcolor(15);
line(50,20,600,20);
line(51,21,599,21);
line(50,20,50,400);
line(51,21,51,399);
//DRAW lines for the bottom and right side
setcolor(8);
line(600,20,600,400);
line(599,21,599,400);
line(50,400,600,400);
line(51,399,600,399);
//DRAW two 3D bars for the left and right side
setfillstyle(9,8);
bar(70,40,100,380);
bar(70,40,550,70);
bar(70,350,550,379);
bar(545,40,575,380);
//PRINT 3D text CALENDAR 2002
settextstyle(1, 0, 4);
settextjustify(1,1);
setcolor(LIGHTGREEN);
outtextxy(mx+2, my - 46, "Thank You!");
setcolor(LIGHTGREEN);
outtextxy(mx + 1, my - 45, "Thank You!");
setcolor(GREEN);
outtextxy(mx + 2, my - 44, "Thank You!");
//PRINT 3D text 2002
setcolor(LIGHTGREEN);
outtextxy(mx, my + 10, "2006");
setcolor(LIGHTGREEN);
outtextxy(mx + 1, my + 11, "2006");
setcolor(GREEN);
outtextxy(mx + 2, my + 12, "2006");
//PRINT copyright notice
settextstyle(2, 0, 5);
setcolor(WHITE);
outtextxy(mx + 1, my + 150, "Copyright http://www.mycplus.com/");
//Print the circle around the text
//the text is "Thank You!"
setcolor(GREEN);
circle(mx,my-30,120);
//Print the ellipse around the text
//the text is "Thank You!"
setcolor(GREEN);
ellipse(mx,my-30,0,360,180,70);
//Print the 3D line below the text
//the text is "Thank You!"
setcolor(CYAN);
line(230,220,410,220);
bar3d(235,225,415,225,4,1);
getch(); //PAUSE for a while
closegraph();
}

I hope this explanation of commom functions present in graphics.h library and the sample code would help you learn graphics programming in C language.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment

Add comment
(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



 
Copyright © by MYCPLUS. All rights reserved. #