graphics.h

setlinestyle in c

Declaration:
void setlinestyle( int linestyle, unsigned upattern, int thickness );

Available line styles:

colors in c graphics

Following colors are available for use in c graphics programming.

Colors table

Color Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11

getimage function in c

getimage function saves a bit image of specified region into memory, region can be any rectangle.

Declaration:- void getimage(int left, int top, int right, int bottom, void *bitmap);

getimage copies an image from screen to memory. Left, top, right, and bottom define the area of the screen from which the rectangle is to be copied, bitmap points to the area in memory where the bit image is stored.

Smiling face animation program using getimage.

moverel function in c

moverel function moves the current position to a relative distance.

Declaration :- void moverel(int x, int y);

linerel function in c

Linerel function draws a line from the current position(CP) to a point that is a relative distance (x, y) from the CP, then advances the CP by (x, y). You can use getx and gety to find the current position.

C programming code for linerel

#include <graphics.h>
#include <conio.h>
 
main()
{
   int gd = DETECT, gm;
 
   initgraph(&gd, &gm, "C:\\TC\\BGI");
 
   moveto(250, 250);

sector function in c

Sector function draws and fills an elliptical pie slice.

Declaration :- void sector( int x, int y, int stangle, int endangle, int xradius, int yradius);

graphdefaults function in c

graphdefaults function resets all graphics settings to their defaults.

Declaration :- void graphdefaults();

It resets the following graphics settings :-

  • Sets the viewport to the entire screen.
  • Moves the current position to (0,0).
  • Sets the default palette colors, background color, and drawing color.
  • Sets the default fill style and pattern.
  • Sets the default text font and justification.

C programming source code for graphdefaults

#include <graphics.h>
#include <conio.h>
 
main()
{
   int gd = DETECT, gm;

imagesize function in c

imagesize function returns the number of bytes required to store a bitimage. This function is used when we are using getimage.

Declaration:- unsigned int imagesize(int left, int top, int right, int bottom);

C programming code for imagesize

#include <graphics.h>
#include <conio.h>
 
main()
{
   int gd = DETECT, gm, bytes;
   char array[100];
 
   initgraph(&gd, &gm, "C:\\TC\\BGI");
 
   circle(200, 200, 50);
   line(150, 200, 250, 200);
   line(200, 150, 200, 250);

getdrivername function

getdrivername function returns a pointer to the current graphics driver.

fillpoly function in c

Fillpoly function draws and fills a polygon. It require same arguments as drawpoly.

Declaration :- void drawpoly( int num, int *polypoints );
For details of arguments see drawpoly.
fillpoly fills using current fill pattern and color which can be changed using setfillstyle.

Pages

Subscribe to RSS - graphics.h
randomness