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

Passing arrays to functions in C programming

Like any other variables, we can also pass entire array to a function. An array name can be named as an argument for the prototype declaration and in function header. When we call the function no need to subscript or square brackets. When we pass array that pass as a call by reference because the array name is address for that array. /* Program to illustrate passing array to function */ #include<stdio.h> void display(int) ; /* function prototype */ main( ) { int num[5] = {100, 20, 40, 15, 33, i ; clrscr( ) ; printf (“\n The content of array is \n”) ; for (i=0; i<5; i++) display (num[i]) ; /*Pass array element fo fun */ getch{ } ; } void display(int n) { printf (“\t%d”, n ) ; } Output:     The content of array is 100      20       40       15 3 /* Program to read 10 numbers from keyboard to store these num into array and then c...

CPU (Central Processing Unit)

PGA reffered as pin grid array in which pins of CPU are lined up in a straight format. SPGA referred as staggered pin grid array. in which pins of CPU are arranged staggered format. LGA reffered to as Land Grid Array in which pins are available within inside the socket but not in the CPU in other words in line grid array, in CPU ther are no pinsbut insteadpins areattached with in a socket which contact with with the CPU. for e.g. LGA775 socket(no pins on cpu) has better cooling system. better contact and better locking(climbing). LGA1155: Letest generation I socket, also reffered as sandy bridge, Turbo boost overclocking. More resent than LGA 1156 socket. LGA1156: ability to north bridge Doul channel DDR3 optional integreted graphics PCI express LGA1366: hi end core i series socket integreted tiple channal memmory controller external control bridge(HUB) Upgrading CPU: need to check its core suppert check multiprocessor supports or not check on the ...

Recursive Function in C programming

             If a statement within the body of a function calls the same function, the function is called recursive function. Actually, recursion is a process by which a function calls itself repeatedly until some specified condition has been satisfied. This process is used for repetitive computations in which each action is stated in term of previous result. Many iterative or repetitive problems can be written in this form.                To solve a problem using recursive method, two conditions must be satisfied. They are: 1)       Problem could be written or defined in term of its previous result. 2)       Problem statement must include a stopping condition. /*   An example of recursive function to calculate factorial of a number.*/    #include<stdio.h>    #include<conio.h...