Skip to main content

Some Graphics Mode Graphics Functions in C programming


putpixel( ): Plot a point with specified color. Its syntax is
Putpixel (int x, int y, int color),
getpixel( ): gets color of specified pixel. Its syntax is
integer_variable = getpixel (int x, int y);
setcolor( ): It changes current drawing/ foreground color. Its syntax is
setcolor (int color);
setbkcolor( ): It changes the background color. Its syntax is
setbkcolor(int color);
line( ): The line ( ) function can draw a line. The syntax of line( ) function is:
line(x1, y1, x2, y2),
where x1, y1, x2, y2 are integer type and they represent the coordinate (x1, y1) and (x2, y2). The above command draws a line joining two points with coordinates (x1, y1) and (x2, y2).
lineral( ): the function lineral (x, y) draws a line joining the current cursor position and a point at a distance of x in the horizontal and y in vertical direction. Note that x and y both are integer type.
lineto( ): The function lineto (x, y) draws a line joining the current cursor position and a point with coordinates x and y. Where x and y both are integer type.
moveto( ): The function moveto (x, y) moves the cursor position to a point with coordinates x and y.
moveral( ): The function moveral (x, y) moves the current cursor position a relative distance of x in x-direction & a relative distance of y in y-direction.
rectangle( ): The function rectangle (x1, y1, x2, y2) draw rectangle where point (x1, y1) is left top corner point of rectangle and point (x2, y2) is right bottom corner.
circle( ): The function circle (x, y, r) draws a circle of radius r. The coordinates of the centre of the circle is (x, y).
arc( ): Function arc (x, y, a1, a2, r) draws an arc on the screen starting from angle a1 to a2.
The radius of the circle of which the arc forms a part is r and x, y are its centre coordinates.
For example:
arc (100, 45, 90, 30) ;
ellipse( ): The function ellipse (x1, y1, c1, c2, a1, a2, x, y) draws an ellipse of centre (c1, c2).
The a1 and a2 are start and end angle of the arc x and y are the x-axis and y-axis radii.
drawpoly( ): Function drawpoly (int n, int p[ ]); draws n vertices of polygon. P is an array of integer numbers which gives x and y co-ordinates of the points to be joined. To draw a closed polygon with n vertices, we must pass n+ 1 co-ordinate.
Int P={10, 75, 50, 25, 100, 25, 140, 75, 100, 125, 50, 125, 10, 75};
Drawpoly (7, P);
setlinestyle( ): This function can select different style of line. Its syntax is
setlinestyle (int style, patern, thickness)
The type of style and thickness is int type and the type of pattern is unsigned int type. Where style are SOLID_LINE, DOTTED_LINE, CENTRE_LINE, DASHED_LINE, USERBIT_LINE or integer number 0, 1, 2, 3, 4 respectively. The pattern is required only if user defined style (USERBIT_LINE) is used. We can specify it to zero. The thickness parameter can have value NORM_WIDTH or THICK_WIDTH or integer value 1 or 3 respectively.
fillpoly( ): It draws and fills polygon. Its syntax is
fillpoly ( int n, int p[ ] );


|* Program to draw 3 concentric circle having radius 25m 50 and 75 units *|
#include <graphics.h>
main( )
{
int gd = DETECT, gm;
clrscr ( );
initgraph ( &gd, &gm, “C:\\tc\\bgi”);
setcolor (3);
circle (150, 150, 25);
circle (150, 150, 50);
circle (150, 150, 75);
getch ( );
closegraphc ( );
}

|* Program to draw an arc *|
#include <graphics.h>
main ( )
{
int gd = DETECT, gm;
clrscr ( );
initgraph ( &gd, &gm, “C:\\tc\\bgi”),
arc (150, 150, 0, 90, 30);
getch ( );
closegraph ( );
}

|* Program to draw a polygon *|
# include <graphics.h>
main ( )
{
int gd = DETECT, gm;
int P [ ] = (10, 75, 50, 25, 100, 25, 140, 75, 100, 125, 50, 125, 10, 753);
clrscr ( );
initgraph ( &gd, &gm, “C:\\tc\\bgi”);
drawpoly (7, P);
fillp[oly (7, P);
getch ( );
closegraph ( );
}
|* Program in c to draw a line, a circle, a rectangle and an ellipse *|
#include <graphics.h>
main( )
{
int gd, gm;
clrscr ( );
gd = DETECT;
initgraph ( &gd, &gm, “C:\\tc\\bgi”)
setcolor (2);
line (150,150,250,250);
circle (300, 300, 25)
setcolor (5);
rectangle (0, 0, 100, 200);
ellipse (150, 250, 0, 360, 80, 60);
getch ( );
closegraph ( );

}

Comments

Popular posts from this blog

Object Oriented Programming

Object Oriented Programming Programming paradigm that represents the concept of "objects" that have data fields (attributes that describe the object) and associated procedures known as methods Programming methodology based on objects, instead of just functions and procedures Focuses on data rather than process As individual objects can be modified without affecting other aspects of the program, it is easier for programmers to structure and organize software programs Easier to update and change programs written in object-oriented languages Simula was the first object oriented programming language Eg: C++, Java, etc. Features of OOPS Objects Referred as instance of class Basic run-time entities in an object-oriented system a person, a place, a bank account, a table of data, etc can be an object They occupy space in memory that keeps its state  Each object contains data and code to manipulate the data  Classes Blue print or prototype  which defi

How structure elements are stored?

  The elements of a structure are always stored in contiguous memory locations. This can be illustrated as void main() {     struct student      {      int roll;      float marks;      char remarks;   };   struct student st={200,60.5,'P'};   printf("\nAddress of roll=%u",&st.roll);   printf("\nAddress of marks=%u",&st.marks);   printf("\nAddress of remarks=%u",&st.remarks);   getch(); } Output: Address of roll=65518 Address of marks=65520 Address of remarks=65524                  st.roll               st.marks                          st.remarks 200 60.5 ‘P’               65518             65520                               65524           

How containership is different than inheritance ?

               Inheritance is the mechanism of deriving properties of one class into another. While containership is mechanism in which one class contain objects of other classes as its member.                     class alpha{_ _ _ _ _ };                     class beta{_ _ _ _ _ };                      class gamma                      {                         alpha a;                         beta b;                       _ _ _ _ _ };            All objects of gamma class will contain the objects a and b, this kind of relationship is called containership or nesting.