KEMBAR78
Graphics in C programming | PPTX
Introduction to Graphics
Introduction
• There are two modes of output device:
– Text Mode
– Graphics Mode
Graphics Characteristics
• Pixels
• Resolutions
• Colors
• Video Adapters
Initializing Graphics Mode
• We use initgraph() function
• Syntax:
– Intigraph(&graphics_driver,&graphics_mode,Path
_to_driver);
Closing Graphics Mode
• Function closegraph() is used.
• Syntax:
– closegraph();
Sample Program
Error Handling
• graphresult() function is used to check if
certain graphics operation succeeded or not.
• It return 0 for no error.
Some Functions in Graphics
• putpixel() and getpixel()
• setcolor() and setbcolor()
• line()
• circle()
• ellipse
• rectangle()
• settextstyle() and outtext()
• getmaxx() and getmaxy()
putpixel() and getpixel()
• Syntax:
– int getpixel(int x, int y);
– void putpixel(int x, int y, int color);
• getpixel returns the color of pixel present at
point(x, y).
• putpixel plots a pixel at a point(x, y) of
specified color.
setbcolor()
• Syntax :-
– void setbkcolor(int color);
• setbkcolor function changes current
background color e.g. setbkcolor(YELLLOW)
changes the current background color to
YELLOW.
• Remember that default drawing color is
WHITE and background color is BLACK.
setcolor()
• Syntax :-
– void setcolor(int color);
• setcolor function changes current drawing
color e.g. setcolor(YELLLOW) changes the
current drawing color to YELLOW.
line()
• line function is used to draw a line from a
point(x1,y1) to point(x2,y2)
• Syntax :-
– void line(int x1, int y1, int x2, int y2);
circle()
• Syntax :-
– void circle(int x, int y, int radius);
• Circle function is used to draw a circle with
center (x,y) and third parameter specifies the
radius of the circle.
ellipse()
• Syntax :-
– void ellipse(int x, int y, int stangle, int endangle, int
xradius, int yradius);
• Ellipse is used to draw an ellipse (x,y) are
coordinates of center of the ellipse, stangle is
the starting angle, end angle is the ending
angle, and fifth and sixth parameters specifies
the X and Y radius of the ellipse.
rectangle()
• Syntax:-
– void rectangle(int left, int top, int right, int
bottom);
• Coordinates of left top and right bottom
corner are required to draw the rectangle.
settextstyle()
• Syntax :-
– void settextstyle( int font, int direction, int
charsize);
• font argument specifies the font of text,
Direction can be HORIZ_DIR (Left to right) or
VERT_DIR (Bottom to top).
outtext()
• outtext function displays text at current
position.
• Syntax :-
– void outtext(char *string);
getmaxx() and getmaxy()
• getmaxx function returns the maximum X
coordinate for current graphics mode and
driver.
• Declaration :- int getmaxx();
• getmaxy function returns the maximum Y
coordinate for current graphics mode and
driver.
• Declaration :- int getmaxy();
Graphics in C programming
Graphics in C programming

Graphics in C programming

  • 1.
  • 2.
    Introduction • There aretwo modes of output device: – Text Mode – Graphics Mode
  • 3.
    Graphics Characteristics • Pixels •Resolutions • Colors • Video Adapters
  • 4.
    Initializing Graphics Mode •We use initgraph() function • Syntax: – Intigraph(&graphics_driver,&graphics_mode,Path _to_driver);
  • 5.
    Closing Graphics Mode •Function closegraph() is used. • Syntax: – closegraph();
  • 6.
  • 7.
    Error Handling • graphresult()function is used to check if certain graphics operation succeeded or not. • It return 0 for no error.
  • 9.
    Some Functions inGraphics • putpixel() and getpixel() • setcolor() and setbcolor() • line() • circle() • ellipse • rectangle() • settextstyle() and outtext() • getmaxx() and getmaxy()
  • 10.
    putpixel() and getpixel() •Syntax: – int getpixel(int x, int y); – void putpixel(int x, int y, int color); • getpixel returns the color of pixel present at point(x, y). • putpixel plots a pixel at a point(x, y) of specified color.
  • 11.
    setbcolor() • Syntax :- –void setbkcolor(int color); • setbkcolor function changes current background color e.g. setbkcolor(YELLLOW) changes the current background color to YELLOW. • Remember that default drawing color is WHITE and background color is BLACK.
  • 12.
    setcolor() • Syntax :- –void setcolor(int color); • setcolor function changes current drawing color e.g. setcolor(YELLLOW) changes the current drawing color to YELLOW.
  • 13.
    line() • line functionis used to draw a line from a point(x1,y1) to point(x2,y2) • Syntax :- – void line(int x1, int y1, int x2, int y2);
  • 14.
    circle() • Syntax :- –void circle(int x, int y, int radius); • Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle.
  • 15.
    ellipse() • Syntax :- –void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius); • Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, stangle is the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse.
  • 16.
    rectangle() • Syntax:- – voidrectangle(int left, int top, int right, int bottom); • Coordinates of left top and right bottom corner are required to draw the rectangle.
  • 17.
    settextstyle() • Syntax :- –void settextstyle( int font, int direction, int charsize); • font argument specifies the font of text, Direction can be HORIZ_DIR (Left to right) or VERT_DIR (Bottom to top).
  • 18.
    outtext() • outtext functiondisplays text at current position. • Syntax :- – void outtext(char *string);
  • 19.
    getmaxx() and getmaxy() •getmaxx function returns the maximum X coordinate for current graphics mode and driver. • Declaration :- int getmaxx(); • getmaxy function returns the maximum Y coordinate for current graphics mode and driver. • Declaration :- int getmaxy();