Sunteți pe pagina 1din 14

GRAPHICS

LABORATORY

REPORT
CONTENTS
 ABSTRACT

 INTRODUCTION

 TOOLS USED

 GENERAL DESCRIPTION

 REQUIREMENT SPECIFICATION

 DETAILED DESIGN

 CONCLUSION

 BIBLIOGRAPHY
ABSTRACT

The Graphics Editor is aimed at supporting the requirements of the Computer


Graphics package. It is a mini Graphics Editor project which is made up by using
various algorithm like Mid-point algorithm, Cohen-Sutherland line-clipping algorithm,
Scan-line area filling algorithm, Hermite and Bezier curves algorithm etc. The editor
has been implemented under the DOS environment using the TURBO C++ package
using the C as the language tool.

The various features have been supported by an easy to understand mouse


interface. All the tools have been organized under the toolbar. The color palette has
been organized under the color bar. The drawing work is carried out in the
rectangular work area (canvas) provided in the main window.

The drawing features supported are :


1. Line.
2. Pen/pencil.
3. Rectangle/square.
4. Circle.
5. Floodfill
6. Paint.
7. Free Hand Drawing
8. Line clipping.
9. Clear

The drawing is done in the canvas which is a rectangular drawing space. The colors
can be chosen from the color bar.

The following file options are provided: -


Clear (clears the canvas)
Exit (exit from the EDITOR)
INTRODUCTION

1. PURPOSE

The aim of this project is to develop a 2-D graphics package which supports basic
operations which include creating objects like lines, circles, polygons, spirals, etc and
also transformation operations like translation, rotation, etc on such objects.The
package must also have a user-friendly interface that may be menu-oriented, iconic
or a combination of both.

All the basic editing features are made available with minimum complexity. This
editor is designed for creation/editing/deleting of simple graphics operations and
simple graphics drawings with simple graphics primitives.

2. SCOPE

 With very user-friendly interface this editor helps in creation of simple


drawings, graphics operations in no time.
 The 2-D graphics package designed here provides an interface for the users
for handling the display and manipulation of basic picture objects like point,
line, rectangle, ellipse, polygon, spiral, etc.
 The application can also load/save files from the secondary devices, such as 3
½ floppy etc.
 The files created are upward compatible (can be opened/edited in more
advanced editors).

3. OVERVIEW

 A graphics oriented screen editor is mainly used fro drawing and modifying
pictures. It includes few operations on pictures or primitives outline
windowing, clipping, object moving etc.
 The graphics editor extensively uses the standard header file “graphics.h”
available in TURBO C++ package to implement the user interface, i.e.,
Windows and popup menus.

4. PORTABILITY AND CONFIGURATION

Code written for the editor may assume an ANSI-standard C compiler. It is


encouraged (but do not require) developers to make the code friendly to less-
capable DOS environments wherever possible. We encourage developers to support
OS-specific optimizations and methods not available under ANSI provided only that:

 All such code is properly conditioned so the build process does not attempt to
compile it under a plain ANSI environment.
 Adding such implementation methods does not introduce incapability.

5. DESIGN OPTIONS

The Graphics Package is designed using the in built graphics library. The objects,
which can be drawn using the editor, are stored as functions that can be used
according to the requirements.

We can say that based on the design philosophy used during their implementation,
the graphics editors can be of two main types.

 One is an Object oriented editor where in each thing drawn in the view port is
an object. Such objects can be selected individually and can be subjected to
any of the transformations provided in the editor. The advantage of such
editors is that the code can be easily written in using an Object Oriented
Programming language like C++. Also undo functionalities can be easily
implemented because all that the editor has to do is to keep a stack of
objects being drawn on the screen. The disadvantage is that the user can only
select objects and not a part of the screen.

 The other kind of an editor is a pixel-based editor where in drawing anything


on the view port is like painting on a canvas. Once an object is drawn it
cannot be individually selected. Instead only a rectangular portion of the
screen can be usually selected and subjected to various transformations or
other operations. In other words the smallest object that can be selected and
modified is a pixel. The basic advantage is that of the simplicity in code of
such an editor where in the smallest unit is a pixel. The disadvantage being
that an individual object cannot be selected and subjected to transformations.

Given the advantages and disadvantages of the two ways of implementing, the
programmer is free to choose one that is more appealing to him .The end product
needs to be a user-friendly interface. Ease of understanding and speed of working
are two main requirements for it, which should be kept in mind during each phase of
design and implementation.

6. SPECIFICATION

The editor is implemented using turbo C++ IDE under DOS platform. The graphics.h
library has proven to be a very useful tool. The C programming language is used to
implement the entire code of the graphics editor. The graphical user interface
provided to the graphics editor is done with the help of the input device “ mouse “
which uses manipulation of basic registers.
TOOLS USED

WINDOW

A data structure describes a sub-rectangle of the screen (possibly the


entire screen). You can write to a window as thought it were a miniature screen,
scrolling independently of other windows on the physical screen.

SCREENS

A subset of windows which area as large as the terminal screen, i.e., they
start at the upper left hand corner and encompass the lower right hand corner. One
of these, initgraph is automatically provided for the programmer.

TERMINAL SCREEN

The package’s ideal of what the terminal display currently looks like, i.e.,
what the user sees now. This is a special screen.

THE GRAPHICS LIBRARY

The graphics library provides a lot of functions and routines for the
drawing of graphics primitives and for doing graphics operations.

USING THE LIBRARY

In order to use the screen package, the routines must know about terminal
characteristics, and the space for curser and initgraph must be allocated. These
functions initgraph () does both these things.
Since it must allocate space for the windows, it can overflow memory when
attempting to do so. On the rare occasions this happens, initgraph () will terminate
the program with an error message.

Initgraph () must always be called before any of the routines, which affect
windows, are used. If it is not, the program will core dump as soon as either curser
or screen initialize are referenced.
Once the screen windows have been allocated, you can set them up for
your program. If you want the cursor to be left in place after the last change, set the
curser to the window’s current (x, y) coordinates after updating it.

OUTPUT

After you have put on the window what you want there, when you want
the portion of the terminal covered by the window to be made to look it, you must
call cleardevice ().
In order to optimize finding changes, cleardevice () assumes that any part
of the window not changed since the last cleardevice ().
After all the graphics operations and graphics drawings are over the
memory associated with all the data structures are to be freed up and the routine
closegraph () is to be called. It returns the window to normal screen by exiting from
the graphics window.

FINISHING UP

In order to clean up after the graphics routines, the routine closegraph ()


is provided. It restores tty modes to what they were initgraph () was first called, and
moves the curser down to the lower-left corner. Thus, anytime after the call to
initgraph (), closegraph () should be called before exiting.

DEBUGGING

Debug ()
This function can be used to explicitly see if any error occurs at any level
of execution. Tracing can be done by using breakpoints and single stepping can be
done using single stepping trace using break points and watches. The perror ()
function can be used to display the error messages, error values on to the screen by
specifying the coordinates of the screen.
GENERAL DESCRIPTION

Product Perspective:

This is a graphics editor that enables the user to input graphical data. Using the
editor, the user can also save the information input by him/her into files or open
existing files for editing. This editor provides a graphical user - friendly interface to
create and edit the files. In keeping with the low-end users, help files have been
provided for each of the actions.

Product Functions:

As mentioned previously, the main objective of the editor is to help the user to input
graphical data and edit it conveniently. For ease in input and to help the user to
traverse through the text easily, the editor provides functionality through the mouse.

User Characteristics:

The editor provides a very easy-to-use interface and does not expect any extra
technical knowledge from the user. A basic understanding of all the options provided
in the editor would facilitate him in using the editor to the best possible extent. Since
it is a mouse-driven interface it is sufficiently easy for any kind of end user to run it.

General Constraints:

 As the software is being built to run on a DOS platform, which gives access to
a maximum of only 640kB of conventional memory, efficient use of the
memory is very important.

 As the software needs to be run even on low-end machines the code should
be efficient and optimal with the minimal redundancies.

 Needless to say, the editor should also be robust and fast.

 It is assumed that the standard output device, namely the monitor, supports
colors.

Assumptions and Dependencies:

 One of the assumptions made in the file saving and retrieval process is that
the required file is in the current directory.
 The user's system is required to have the C++ compiler of the appropriate
version.

 The system is also expected to have a mouse connected since most of the
drawing and other graphical operations implemented assume the presence of
a mouse.

REQUIREMENT Specification

SOFTWARE REQUIREMENTS SPECIFICATION:

 This section attempts to bring out the requirements and specifications as


given out by the Vishweshwaraiah Technological University for the completion
of the package.

 Minimum requirements expected are cursor movement, editing picture


objects like point, line, circle, box, arc, ellipse, spiral, and polygon.
Transformations on objects/selected area should be possible. Clipping and
filling of areas should be possible. User should be able to load pre existing
files, save newly created ones, clear some graphical data.

 Good user interface, which can be GUI or Iconic or Menu based, should be
provided. On-line help for all the options and methods of usage should be
given. Should use all most all the graphical input technologies for efficient
programming of input devices. Should be a device independent package that
is able to compile and create an executable.

EXTERNAL INTERFACE REQUIREMENTS:

User Interface:
 The interface for the editor requires for the user to have a mouse connected,
and the corresponding drivers installed. This is because most of the
implementation details require and presume the presence of a mouse.

 For the convenience of the user, there are palettes and icons displayed on the
screen.

ICONS:

The icons consists of the file saving and opening options. It also has the 'exit' option
for termination of the editor's execution.
PALETTES:

 Color palette, which displays the different colors available to the user. He/she
can pick the required color by clicking on the particular block.
 Shapes palette, which displays the various shapes that can be drawn by the
user. This typically consists of line, circle, ellipse, and rectangle, spiral and
freehand. User can choose the required shape by clicking on the icon
representing the shape.
 2D Transformations palette gives options like translation and rotation for the
2D objects created on the canvas. Again the user has to click on the icon to
select the particular transformation.
 Icons that represent other options like clipping and filling.

Hardware Interface:

The standard output device, as mentioned earlier has been assumed to be a color
monitor. It is quite essential for any graphics package to have this, as provision of
color options to the user is a must. The mouse, the main input device, has to be
functional. A keyboard is also required.
Apart from these hardware requirements, there should be sufficient hard disk space
and primary memory available for proper working of the package.

Software Interface:

The editor has been implemented on the DOS platform and mainly requires an
appropriate version of the compiler to be installed and functional. Though it has been
implemented on DOS, it is pretty much platform independent with the restriction that
there is support for the execution of C++ files. Text mode is recommended.
DETAILED DESIGN

Platform

The graphics editor is implemented using turbo C++ IDE, under the DOS
platform. The C programming language is the tool used for the package
development.

Data structures

As such the graphics editor does not use any data structures but for rubber
banding purposes a structure is maintained to hold the co-ordinates as well as the
color of the pixels at their respective points.

ALGORITHMS:

Various algorithms have been used in this editor to provide the functionalities it
boasts of. Few of them have been explained here.

Bresenham's Line and Circle:

This is the most important algorithm used here in this editor. This is an accurate and
efficient raster line-generating algorithm that scans converts line using only
incremental integer calculations that is adapted here to display lines. The algorithm
can be suitably adapted for drawing circles and other curves.

Free- hand Drawing:

Free- hand drawing is a special case of polyline drawing where we have a large
number of points obtained by continuously poling the mouse position during the time
the mouse' left button is clicked.

Translation:

Translation is done by adding the required amount of translation quantities to each


of the points of the objects in the selected area. If P(x,y) be the a point and (tx, ty)
translation quantities then the translated point is given by
P'(x,y) = p(x+tx,y+ty)

Rotation:

The rotation of an object by an angle 'a' is accomplished by rotating each of the


points of the object. The rotated points can be obtained using the formula
Newx = oldx*cos(a) - oldy*sin(a)
Newy = oldx*sin(a) + oldy*cos(a)

Scaling:

The scaling operation on an object can be carried out for an object by multiplying
each of the points (x,y) by the scaling factors sx, sy.
Newx = oldx*sx
Newy = oldy*sy

Rubber-Banding Technique:

Drawing of the various objects such as line, rectangle, polygons, circles etc is based
on the rubber-band technique where the user marks the initial point and then as the
cursor moves around the screen the object is displayed with the current mouse
coordinates being taken as the second point. This is useful in applications where we
might want to explore different possibilities before selecting a final position. This can
be accomplished by continuously polling the mouse for its coordinates and drawing in
the X-OR mode. By doing so if the figure has been originally drawn then it would be
erased, else it would be newly drawn. By coordinating this action we can implement
rubber-band action.
conclusion

The editor completed by this project has almost all the basic facilities of any simple
graphics editor. The editor is interactive and user friendly since, many hot keys are
provided a . There is also online help feature provided, which is displayed on the
status bar all the time, as a result it does not hamper the user’s views as to its
context. Even online documentation of the editor is also provided to help user
customizing the editor.

Though the editor provides all the basic facilities needed, it lacks many of
the advanced facilities such as insert and delete word or line or character, page
setup, osshell, high technology graphics operations, graphics features.
Implementation of these facilities was not possible due to time constraints. Thus with
these details we conclude our project report on editor.
Bibliography

 Computer Graphics – Principals And Practice (Foley, Van Dam, Fenier and
Hughes) This book helped me to understand graphics generation algorithms,
user interface and dialogue design

 Graphics Programming in ‘c’ (Yashawant Kanetkar) helped me to understand


the various functions of “graphics.h”

 The Intel Microprocessors (Barry B. Brey) referred for mouse interrupts