GRAPHICS



p
{
max-width:700px;
background-color:#909090;
}

GRAPHICS IN “C”


FUNCTIONS OF GRAPHICS.H


C graphics using graphics.h functions or WinBGIM (Windows 7 ) can be used to draw different shapes, display text in different fonts, change colors and many more.


Using functions of graphics.h in turbo c compiler you can make graphics programs, animations, projects and games.You can draw circles, lines, rectangles, bars and many other geometrical figures. 

You can change their colors using the available functions and fill them.


Following is a list of functions of graphics.h header file. Every function is discussed with the arguments it needs, its description, possible errors while using that function and a sample c graphics program with its output.

C GRAPHICS FUNCTIONS


•arc
•bar
•bar3d
•circle
•cleardevice
•closegraph
•drawpoly
•ellipse
•fillellipse
•fillpoly
•floodfill
•getarccords
•getbkcolor
•getcolor
•getdrivername
•getimage
•getmaxcolor
•getmaxx
•getmaxy
•getpixel
•getx
•gety
•graphdefaults
•grapherrormsg
•imagesize
•line
•lineto
•linerel
•moveto
•moverel
•outtext
•outtextxy
•pieslice
•putimage
•putpixel
•rectangle
•sector
•setbkcolor
•setcolor
•setfillstyle
•setlinestyle
•settextstyle
•setviewport
•textheight
•textwidth


GRAPHICS IN WINDOWS 7 OR VISTA


Most of the functions are two dimensional except bar3d which draws a 3d bar, you can also implement these functions using already existing algorithms.

You can also use these functions in c++ programs. You can use these functions for developing programs in Windows 7 and Vista using Dev C++ compiler.


For that you need to download an additional package WinBGIm, download WinBGIm. Now open Dev C++ compiler go to tools->Package Manager, click on install and then browse the package location. Now create new project and select WinBGIm.


This library also offers many functions which can be used for image manipulation, you can open image files, create bitmaps and print images, RGB colors and mouse handling.


C GRAPHICS PROGRAMS

Draw shapes
Bar chart
Pie chart
3d bar chart
Smiling face animation
captcha
Circles in circles
Countdown
Paint program in c
Press me button game
Web browser program
Traffic Light Simulation
Mouse pointer restricted in circle
Drawing concentric circles
C graphics program moving car


C GRAPHICS EXAMPLES


DRAWING CONCENTRIC CIRCLES


#INCLUDE


INT MAIN()
{
INT GD = DETECT, GM;
INT X = 320, Y = 240, RADIUS;

INITGRAPH(&GD, &GM, "C:\\TC\\BGI");

FOR ( RADIUS = 25; RADIUS <= 125 ; RADIUS = RADIUS + 20)       CIRCLE(X, Y, RADIUS);    GETCH();    CLOSEGRAPH();    RETURN 0;





C GRAPHICS PROGRAM MOVING CAR



#INCLUDE
#INCLUDE
INT MAIN()
{
INT I, J = 0, GD = DETECT, GM;

INITGRAPH(&GD,&GM,"C:\\TC\\BGI");

SETTEXTSTYLE(DEFAULT_FONT,HORIZ_DIR,2);

OUTTEXTXY(25,240,"PRESS ANY KEY TO VIEW THE MOVING CAR");


GETCH();

FOR( I = 0 ; I <= 420 ; I = I + 10, J++ )    {       RECTANGLE(50+I,275,150+I,400);       RECTANGLE(150+I,350,200+I,400);       CIRCLE(75+I,410,10);       CIRCLE(175+I,410,10);       SETCOLOR(J);       DELAY(100);       IF( I == 420 )          BREAK;       IF ( J == 15 )          J = 2;       CLEARDEVICE(); // CLEAR SCREEN    }    GETCH();    CLOSEGRAPH();    RETURN 0; }





No comments:

Post a Comment