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

Database Management System(DBMS)

Data and Information  Data is an unprocessed raw fact which does  not give complete meaning about any object,person, entity etc. But when various inter-related data arranged in a row, it gives a complete meaning which is referred to as information. For Example: ID Name Address Program 1101 Ram Shrestha Biratnagar BScIT         is information of a specific person. Database Database is a repository(storage) for the organized collection of related information  of data items. It Consist of meaningful arrangement of data, relationship, constraints, schema etc. In modern days we define database as a computerized record-keeping system used to store information and allows users to retrieve and update these information on their request. Some example of databases are telephone directory, data of SLC result, student and employee records etc. Database Management System(DBMS) Database is the softw...

What is Java Applets?

An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser. Furthermore, an applet is downloaded on demand, without further interaction with the user. If the user clicks a link that contains an applet, the applet will be automatically downloaded and run in the browser. Applets are intended to be small programs. They are typically used to display data provided by the server, handle user input, or provide simple functions, such as a loan calculator, that execute locally, rather than on the server. In essence, the applet allows some functionality to be moved from the server to the client.

What is manipulator in C++?

Answer: Manipulators are special functions that can be included in the I/O statement to alter the format parameters of a stream. Table-2 shows some important manipulator functions that are frequently used. To access these manipulators, the file < iomanip.h > should be included in program.                               Table-2               Manipulators                                                    Equivalent ios function               set...