ACPLD Self Learning
ACPLD Self Learning
h
Presented by:
Pranjal Nikhare & Pranjal Deshpande
Table of contents
1. INTRODUCTION
2. USING GRAPHICS
3. BGI
4. COLORS IN GRAPHICS
5. FUNCTION IN GRAPHICS
6. DRAWING POINT ON SCREEN
7. CURIOSITY
Introduction :
A header file is a file with extension " . h "which contains C function declarations
and macro definitions to be shared between several source files. There are two types
of header files: the files that the programmer writes and the files that comes with
your compiler.
Graphics.h is one of the predefined Header files in c programming. It provides
access to a simple graphics library that makes it possible to draw lines, rectangles,
ovals, arcs, polygons, images, and strings on a graphical window.
Displaying the information in terms of text is the most traditional way of
representing data but we can also represent the data in terms of graphs ,
polygons ,images etc Graphics provide the way to represent data in graphical format .
Using Graphics :
Step 1 : Including graphics.h header at the top of program.
Step 2 : Initialize the graphics drivers on the computer using initgraph method of
graphics.h library i.e. set the computer to graphics mode .
Syntax :
void initgraph(int *graphicsDriver, int *graphicsMode,
char*driverDirectoryPath);
Step 3 : use the functions present in graphics .h according to the requirement .
Step 4 : use getch(); and clrscr(); function in Conio.h header for presenting
output in a clean format..
Step 5 : use closegraph(); function to return back to normal mode.
Borland Graphics Interface :
The Borland Graphics Interface, also known as BGI, is a
graphics library bundled with several Borland compilers for the
DOS operating systems since 1987.The library loaded graphic
drivers (*.BGI) and vector fonts (*.CHR) from disk in order to
provide device independent graphics support. It was possible for
the programmer to embed the graphic driver into the executable
file by linking the graphic driver as object code with the aid of a
utility provided by the compiler (bgiobj.exe).
Extraspace for explanation :
Color in graphics :-->
#include<graphics.h>
#include<stdio.h>
There are 16 colors declared in #include<conio.h>
graphics.h header file. We use void main(){
colors to set the current drawing int gd = DETECT, gm;
color, change the color of clrscr();
background, change the color of initgraph(&gd, &gm, "c:\\tc\\
text, to color a closed shape etc.To bgi");
specify a color, we can either use setcolor(BLUE);
color constants like setcolor(RED),
rectangle(50,50,100,100);
or their corresponding integer
codes like setcolor(4). getch();
closegraph();
}
Functions in graphics.h
1. circle(); :--> this function draws a circle in current drawing color
Syntax : circle(int x,int y, int radius);
2. rectangle(); :--> this function draws a rectangle in current line style,
thickness and drawing color
Syntax : rectangle(int left , int top , int right , int bottom);
3. arc(); :--> it draws circular arc in current drawing color
Syntax : circle(int x,int y, int stangle ,int endangle ,int radius);
4. line(); :--> it draws a line from (x1 ,y1) to (x2,y2) in current color , style
thickness
Syntax : line(int x1, int y1 ,int x2, int y2);
5. ellipse(); : --> it draws eliptical arc in current drawing color
Syntax : ellipse(int x,int y,int stangle ,int endangle,int xradius, int
yradius);
6. lineto(); :--> it draws a line from current position to position (x,y) in
current line style and thickness.
Syntax :lineto(int x ,int y);
7.bar(); :--> it draws a filled in rectangular two dimensional bar
Syntax : bar(int left ,int top , int right ,int bottom);
8.closegraph(); :--> it shuts down the graphics mode and restores the
previous mode.it deallocate all the memory allocated by graphics system.
Syntax : closegraph();
9.drawpoly(); :--> it draws the outline of a polygon in current style and
color.
Syntax : drawpoly(int numpoints, int *polypoints);
Drawing a point on screen :-->
#include<graphics.h> clrscr();
#include<stdio.h> initgraph(&gd,&gm,"c:\\tc\\gi");
#include<conio.h> putpixel(x,y,10);
void main(){ getch();
int gd=DETECT,gm; closegraph();
int x,y; }
clrscr(); output (s1):
printf("Enter adress of point x,y :"); Enter the address of x, y : 5
scanf("%d%d",&x,&y); 6
output (s2) :
.
Curiosity : drawing rainbow
#include<stdio.h> for(i = 0 ; i < 300 ; i++)
#include<graphics.h> {
#include<dos.h> if(i % 25 == 0)
void main() setcolor(i);
{ arc(300 , 400 , 0 , 180 , i) ;
int i , gd = DETECT , gm; delay(10);
initgraph(&gd , &gm ,"c:\\tc\\ }
bgi"); getch();
closegraph();
}
Output :
LOGIC :
Rainbow as we all know is a
multicolor concentric arc or
semiCircular band of colors formed
due to diffraction,dispersion and
total internal reflection of light .
To print this rainbow ,I have
used a for loop to print arcs in
continuous manner (using arc
function .for multicolor i have given
"i " to setcolor() function as a
argument and as the value of
changes with loop the color
changes. live also used delay
function to let each arc get
completely printed on screen
Thanks for all your
patience