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

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...

Network Topology

A network topology is the arrangement of the computers cable and other components on a network. The major goal of network topology is to find out the most economical and efficient way to connect all the users to the network resources while providing adequate capacity to handle users demand, maintain system reliability and decrease the delay.    Topology is the map of physical network. The type of topology we use defect the type and capabilities network hardware’s its management and possibilities for future expansion. There are many types of network topology, some of these are:   Bus Topology Star Topology Mesh Topology   Ring Topology Tree Topology

What is Servlet in Java?

A servlet is a small program that executes on a server. Just as applets dynamically extend the functionality of a web browser, servlets dynamically extend the functionality of a web server. It is helpful to understand that as useful as applets can be, they are just one half of the client/server equation. Not long after the initial release of Java, it became obvious that Java would also be useful on the server side. The result was the servlet. Thus, with the advent of the servlet, Java spanned both sides of the client/server connection.