0% found this document useful (0 votes)
5 views

CG Unit1

Uploaded by

zeenat parveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CG Unit1

Uploaded by

zeenat parveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Unit 1

Introduction to Computer Graphics


The term ‘Computer Graphics’ was coined by Verne Hudson and William Fetter from Boeing
who were pioneers in the field. Computer graphics is a dynamic and essential field within
computing that involves the creation, manipulation, and rendering of visual content using
computers.
Computer Graphics including digital images, animations, and interactive graphics used in
various sectors such as entertainment, education, scientific visualization, and virtual reality.
Computer Graphics can be used in UI design, rendering, geometric objects, animation, and
many more. In most areas, computer graphics is an abbreviation of CG.

Computer Graphics refers to several things


 The manipulation and the representation of the image or the data in a graphical manner.
 Various technology is required for the creation and manipulation.
 Digital synthesis and its manipulation.

APPLICATIONS OF COMPUTER GRAPHICS

Computer Aided Design (CAD) : It is used in the design of Buildings, Automobiles, Aircraft,
Watercraft, Spacecraft, Computers, Textiles and many more products
For some design applications, objects are first displayed in a wireframe outline which shows
the overall shape and internal features of objects
Circuits and Networks for communications, water supply or other utilities are constructed
The shapes used in a design represent the different network or circuit components
Real time animations using wireframe displays on a video monitor are useful for testing
performance of a vehicle or system
Realistic displays are generated for advertising of automobiles and other vehicles using special
lighting effects and background scenes
Architects use interactive graphics methods to layout floor plans such as positioning of rooms,
windows, stairs, shelves and other building features
Presentation Graphics
Presentation Graphics is used to produce illustrations for reports, Slides or transparencies for
use with projectors. It is used to summarize Financial, Statistical, Mathematical, Scientific as
well as Economic Data. For example, Bar charts, Line Graphs, Surface Graphs, Pie charts and
other displays shows relationships between multiple parameters.

Fig 1.2 Example for Presentation Graphics

Computer Art
Computer Graphics are used in both fine art and commercial art applications. Artists use a
variety of computer methods including special purpose hardware, artists paint brush
programs, specially developed software, symbolic mathematical packages, CAD software,
Desktop publishing software and Animation packages that provide facilities for designing
object shapes and specifying object motions eg) LOGOs , TV advertising, Combining Text and
Graphics, Morphing, etc.
Entertainment
Graphics objects are combined with actors and live scenes. eg) Motion pictures, Music Videos,
Television shows.

Education and Training


Computer generated models of physical, financial and economic systems are often used as
educational aids. Eg) Simulators for practice sessions, Training of ship captions, Training of
pilots, Air traffic control personnel, etc.

Visualization
Scientists, Engineers, Medical Personnel, Business Analysts need to analyze large amount of
data. Numerical simulations carried out on super computers frequently produce data files
containing thousands and millions of data values. Satellite cameras and other sources can
process amassing large data files faster than they can be interpreted .
Visualization can be of two types :
Scientific : Graphical representation for scientific, engineering and Medical datasets
Business : Datasets related to commerce, industry and other non-scientific areas

Image Processing
Image processing is applied to modify / interpret existing pictures such as photographs and TV
scans.
Applications of Image Processing:
Improving picture quality
M/C perception of visual information as used in robotics
Display Processor
It is interpreter or piece of hardware that converts display processor code into pictures. It is one
of the four main parts of the display processor

Parts of Display Processor

1. Display File Memory


2. Display Processor
3. Display Generator
4. Display Console

Display File Memory: It is used for generation of the picture. It is used for identification of
graphic entities.

Display Controller:

1. It handles interrupt
2. It maintains timings
3. It is used for interpretation of instruction.
Display Generator:

1. It is used for the generation of character.


2. It is used for the generation of curves.

Display Console: It contains CRT, Light Pen, and Keyboard and deflection system.

The raster scan system is a combination of some processing units. It consists of the control
processing unit (CPU) and a particular processor called a display controller. Display Controller
controls the operation of the display device. It is also called a video controller.

Working: The video controller in the output circuitry generates the horizontal and vertical drive
signals so that the monitor can sweep. Its beam across the screen during raster scans.

As fig showing that 2 registers (X register and Y register) are used to store the coordinate of the
screen pixels. Assume that y values of the adjacent scan lines increased by 1 in an upward
direction starting from 0 at the bottom of the screen to ymax at the top and along each scan line
the screen pixel positions or x values are incremented by 1 from 0 at the leftmost position to
xmax at the rightmost position.

The origin is at the lowest left corner of the screen as in a standard Cartesian coordinate system.
At the start of a Refresh Cycle:

X register is set to 0 and y register is set to ymax. This (x, y') address is translated into a memory
address of frame buffer where the color value for this pixel position is stored.

The controller receives this color value (a binary no) from the frame buffer, breaks it up into
three parts and sends each element to a separate Digital-to-Analog Converter (DAC).

These voltages, in turn, controls the intensity of 3 e-beam that are focused at the (x, y) screen
position by the horizontal and vertical drive signals.

This process is repeated for each pixel along the top scan line, each time incrementing the X
register by Y.

As pixels on the first scan line are generated, the X register is incremented throughxmax.

Then x register is reset to 0, and y register is decremented by 1 to access the next scan line.

Pixel along each scan line is then processed, and the procedure is repeated for each successive
scan line units pixels on the last scan line (y=0) are generated.

For a display system employing a color look-up table frame buffer value is not directly used to
control the CRT beam intensity.

It is used as an index to find the three pixel-color value from the look-up table. This lookup
operation is done for each pixel on every display cycle.

As the time available to display or refresh a single pixel in the screen is too less, accessing the
frame buffer every time for reading each pixel intensity value would consume more time what
is allowed:
Multiple adjacent pixel values are fetched to the frame buffer in single access and stored in the
register.

After every allowable time gap, the one-pixel value is shifted out from the register to control
the warm intensity for that pixel.

The procedure is repeated with the next block of pixels,and so on, thus the whole group of pixels
will be processed.

Display Devices:
The most commonly used display device is a video monitor. The operation of most video
monitors based on CRT (Cathode Ray Tube). The following display devices are used:

1. Refresh Cathode Ray Tube


2. Random Scan and Raster Scan
3. Color CRT Monitors
4. Direct View Storage Tubes
5. Flat Panel Display
6. Lookup Table

Graphical User Interface


Uses Window manager which allows a user to display multiple window areas. It can be
activated by an icon.

VISUAL DISPLAY DEVICES


The Primary output device is Video Monitor. The operation is based on the Standard Cathode
Ray Tube.
A beam of electrons (cathode rays) emitted by the electron gun passes through focusing and
deflection systems that direct the beam towards specified positions on the phosphor-coated
screen. The phosphor emits a small spot of light at each position contacted by the electron
beam. Because the light emitted by the phosphor fades rapidly, some means is needed for
maintaining the picture. One way to keep the phosphor glowing is to redraw the picture
repeatedly and quickly by directing the electron beam back over the same points. This type of
display is Refresh CRT.

Main Components of CRT are:


Electron Gun: Electron gun consisting of a series of elements, primarily a heating filament
(heater) and a cathode. The electron gun creates a source of electrons which are focused into
a narrow beam directed at the face of the CRT.
Control Electrode: It is used to turn the electron beam on and off.
Focusing system: It is used to create a clear picture by focusing the electrons into a narrow
beam.
Deflection Yoke: It is used to control the direction of the electron beam. It creates an electric
or magnetic field which will bend the electron beam as it passes through the area. In a
conventional CRT, the yoke is linked to a sweep or scan generator. The deflection yoke which
is connected to the sweep generator creates a fluctuating electric or magnetic potential.
Phosphorus-coated screen: The inside front surface of every CRT is coated with phosphors.
Phosphors glow when a high-energy electron beam hits them. Phosphorescence is the term
used to characterize the light given off by a phosphor after it has been exposed to an electron
beam.

Functions of Heated metal Cathode and a Control Grid

Heat is supplied to the cathode by directing current through a coil of wire called filament,
inside a cylindrical cathode structure. This causes electrons to be “boiled off” the hot cathode
surface. In the vacuum inside the CRT envelope, the free negatively charged electrons are then
accelerated towards the phosphor coating by a high positive voltage or an accelerating anode
or focusing anode. Intensity of the electron beam is controlled by setting voltage levels on the
control grid will shut off the beam by repelling the electrons and stopping them from passing
through the small grid at the end of the control grid. A small negative charge will decrease the
electrons passing through.
The light emitted by the phosphor coating depends on the number of electrons striking the
screen, so we can control the brightness of a display by varying voltage on the control grid.
The focusing system in a CRT is needed to force the electron beam to converge into a small
spot as it strikes the phosphor, otherwise the electrons would repel each other and the beam
would spread out as it reaches the screen.
Deflection can be controlled by electric or magnetic fields. CRTs are constructed with magnetic
deflection coils mounted on the outside of the CRT. Spots of light are produced on the screen
by the transfer of CRT beam energy to the phosphor. When the electrons collide with
phosphor coated screen, they are stopped and their kinetic energy is absorbed by the
phosphor. Part of beam energy is converted by friction into heat energy and the remainder
causes electrons in the phosphor atoms to move upto high-quantum levels. After a short time,
the excited phosphor electrons begin dropping back to their stable ground state.

High resolution systems are called as High definition system


Aspect Ratio : Number of vertical points to horizontal points necessary to produce equal
length lines in both directions on the screen.
E.g., Aspect Ratio ¾ : Vertical points 3 plotted with horizontal 4
Different kinds of phosphors are available for use in CRT. Major factor is persistence (how long
they continue to emit light).
Persistence is defined as the time it takes the emitted light from the screen to decay to one-
tenth of its original intensity. Lower persistence phosphor requires higher refresh rates. Lower
persistence is used for animation. High persistence is used for highly complex and static
pictures. Persistence varies between 10-60 microsecond.

RASTER SCAN DISPLAYS


The most common type of CRT is the Raster Scan display, based on television technology. In a
raster-scan system, the electron beam is swept across the screen, one row at a time from top
to bottom. As the electron beam moves across each row, the beam intensity is turned on and
off to create a pattern of illuminated spots. Picture definition is stored
in a memory area called refresh buffer or frame buffer. The memory
area holds the set of intensity values for all screen points. Stored
intensity values are then retrieved from the refresh buffer and
“painted” on the screen one row at a time.
Each screen point is referred to as a Pixel or Pel (Picture element). eg) Home television sets
and printers are examples of
systems using raster-scan methods. Intensity range for pixel positions depends on the
capability of raster system. In a simple black and white system, each screen point is either on
or off . (i.e.) only one pixel is needed to control the intensity of screen positions
In High Quality system upto 24 bits / pixel is required. 3MB of storage is required for Frame
buffer. Black and White Frame buffer is called as Bitmap. Color monitor is called as Pixmap.
Refreshing on a raster scan is carried out at a rate of 60-80 frames/second.
Scanning left to right is called as Horizontal retrace. At the end of each frame, the electron
beam returns to the top left corner of the screen (vertical retrace) to begin the next frame.
The CRT has the electron beam directed only to the parts of the screen where a picture is to be
redrawn.

Random Scan (Vector Scan)


In this technique, the electron beam is directed only to the part of the screen where the
picture is to be drawn rather than scanning from left to right and top to bottom as in raster
scan. It is also called vector display, stroke-writing display, or calligraphic display.
Picture definition is stored as a set of line-drawing commands in an area of memory referred
to as the refresh display file. To display a specified picture, the system cycles through the set
of commands in the display file, drawing each component line in turn. After all the line-
drawing commands are processed, the system cycles back to the first line command in the list.
Random- scan displays are designed to draw all the component lines of a picture 30 to 60
times each second.
Refresh rates depends on the no. of lines to be drawn. Picture definition is stored as a set of
line- drawing commands in an area of memory called refresh display file (refresh buffer).
Suppose we want to display a square ABCD on the screen. The commands will be:
Draw a line from A to B
Draw a line from B to C
Draw a line from C to D
Draw a line from D to A

Fig 1.10 Example for construction of square with Random scan display

Drawbacks of random scan display


 It can be used for line drawing applications
 Cannot display realistic shaded scenes
 Not stored as a set of intensity
COLOR CRT MONITOR
A CRT monitor displays color pictures by using a combination of phosphors that emit different
colored light. Techniques for color displays :
1) Beam penetration method
2) Shadow mask method

1) Beam penetration method


Color pictures can be displayed with random scan monitors. Two layers of phosphors (Red and
Green) are coated on the inside of CRT screen. A beam of slow electrons excites only the outer
red color. A beam of very fast electrons penetrates through the red layer and excites the inner
green color.
At intermediate beam speeds, combinations of red and green are emitted which gives
additional two colors orange and yellow. Beam penetration is
inexpensive way to produce color in random- scan monitors
but only few colors are possible. Quality of picture is not as
good as with other methods.
Advantages:

1. Inexpensive

Disadvantages:

1. Only four colors are possible


2. Quality of pictures is not as good as with another method.

2) Shadow-Mask Method:

Shadow Mask Method is commonly used in Raster-Scan System because they produce a much
wider range of colors than the beam-penetration method.It is used in the majority of color TV
sets and monitors.

Construction: A shadow mask CRT has 3 phosphor color dots at each pixel position.

o One phosphor dot emits: red light


o Another emits: green light
o Third emits: blue light
This type of CRT has 3 electron guns, one for each color dot and a shadow mask grid just
behind the phosphor coated screen.
Shadow mask grid is pierced with small round holes in a triangular pattern.
Working: Triad arrangement of red, green, and blue guns.

The deflection system of the CRT operates on all 3 electron beams simultaneously; the 3
electron beams are deflected and focused as a group onto the shadow mask, which contains a
sequence of holes aligned with the phosphor- dot patterns.

When the three beams pass through a hole in the shadow mask, they activate a dotted triangle,
which occurs as a small color spot on the screen.
The phosphor dots in the triangles are organized so that each electron beam can activate only
its corresponding color dot when it passes through the shadow mask.

Inline arrangement: Another configuration for the 3 electron guns is an Inline arrangement in
which the 3 electron guns and the corresponding red-green-blue color dots on the screen, are
aligned along one scan line rather of in a triangular pattern.
This inline arrangement of electron guns in easier to keep in alignment and is commonly used
in high-resolution color CRT's.

Advantage:

1. Realistic image
2. Million different colors to be generated
3. Shadow scenes are possible

Disadvantage:

1. Relatively expensive compared with the monochrome CRT.


2. Relatively poor resolution
3. Convergence Problem
Direct View Storage Tube
DVST terminals use random scan approach to generate the image on the CRT screen. The term
"storage tube" refers to the ability of the screen to retain the image once it is projected.

Function of guns: Two guns are used in DVST


Primary guns: It is used to store the picture pattern.
Flood gun or Secondary gun: It is used to maintain picture display.

Fig 1.13 Structure of CRT with Direct View Storage Tube

Advantage:
1) No refreshing is needed.
2) High Resolution
3) Cost is very less
Disadvantage:
1) It is not possible to erase the selected part of a picture.
2) It is not suitable for dynamic graphics applications.
3) They do not display colors and are available with single level of line intensity
4) If a part of picture is to modify, then time is consumed.
5) Erasing of screen produces unpleasant flash over the entire screen surface which prevents
its use of dynamic graphics applications.
6) It has poor contrast as a result of the comparatively low accelerating potential applied to
the flood electrons.

7) The performance of DVST is inferior to Refresh CRT.

FLAT PANEL DISPLAYS


Flat panel displays refer to a class of video devices that have reduced volume, weight and
power requirements in comparison with CRT
TV monitors, Calculators, Laptop,Pocket video games, armrest viewing of movies on airlines,
advertisement boards in elevators, etc.
Flat panel displays are divided into two categories:
1) Emissive display
2) Non-Emissive display
1) EMISSIVE DISPLAYS (E.G., PLASMA PANEL AND LED)
These displays convert electric energy into light
Plasma Panel

They are constructed by filling the region between two glass plates with a mixture of gases
that usually includes neon. A series of vertical conducting ribbon is placed on one glass panel
and a series of horizontal ribbon is built into the other glass panel.
Voltages applied to a pair of horizontal and vertical conductors cause the gas at the
intersection of the two conductors to break down into glowing plasma of electrons and icons.
Picture definition is stored in the refresh buffer and voltages are applied to refresh the pixel
positions 60 times / sec.

Advantages:
1) High Resolution
2) Large screen size is also possible.
3) Less Volume
4) Less weight
5) Flicker Free Display Disadvantage:
6) Poor Resolution
7) Its addressing is also complex.
LED (Light Emitting Diode):

In an LED, a matrix of diodes is organized to form the pixel positions in the display and picture
definition is stored in a refresh buffer. Data is read from the refresh buffer and converted to
voltage levels that are applied to the diodes to produce the light pattern in the display.

2. NON-EMISSIVE DISPLAY (E.G., LCD)


Liquid Crystal Displays are the devices that produce a picture by passing polarized light
through a liquid-crystal material that transmits the light.LCD uses the liquid-crystal material
between two glass plates; each plate is the right angle to each other between plates liquid is
filled. One glass plate consists of rows of conductors arranged in vertical direction. Another
glass plate is consisting of a row of conductors arranged in horizontal direction. The pixel
position is determined by the intersection of the vertical & horizontal conductor. This position
is an active part of the screen.

Advantage:

1) Low power consumption.


2) Small Size
3) Low Cost Disadvantage:
4) LCDs are temperature-dependent (0-70°C)
5) The resolution is not as good as that of a CRT.

INPUT DEVICES
The Input Devices are the hardware that is used to transfer input to the computer. The data
can be in the form of text, graphics, sound, and text. Output device display data from the
memory of the computer. Output can be text, numeric data, line, polygon, and other objects.
The following are some of the examples of Input Devices :
1) Keyboard
2) Mouse
3) Trackball
4) Spaceball
5) Joystick
6) Lightpen
7) Digitizer
8) Touch panels
9) Image Scanner

1) Keyboard :

The most commonly used input device is a keyboard. The data is entered by pressing the set of
keys. All keys are labeled. A keyboard with 101 keys is called a QWERTY keyboard.
The keyboard has alphabetic as well as numeric keys. Some special keys are also available.
1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Alphabetic keys: a to z (lower case), A to Z (upper case)
Special Control keys: Ctrl, Shift, Alt
Special Symbol Keys: ; , " ? @ ~ ? :
Cursor Control Keys: ↑ → ← ↓
Function Keys: F1 F2 F3. F9.
Numeric Keyboard: It is on the right-hand side of the keyboard and used for fast entry of
numeric data.
Functions of Keyboard:
Alphanumeric Keyboards are used in CAD. (Computer Aided Drafting)
Keyboards are available with special features line screen co-ordinates entry, Menu selection or
graphics functions, etc.
Special purpose keyboards are available having buttons, dials, and switches.

Advantage:
1) Suitable for entering numeric data.
2) Function keys are a fast and effective method of using commands, with fewer errors.
Disadvantage:
3) Keyboard is not suitable for graphics input.
2) Mouse

A Mouse is a pointing device and used to position the pointer on the screen. There are two or
three depression switches on the top. The movement of the mouse along the x-axis helps in
the horizontal movement of the cursor and the movement along the y-axis helps in the vertical
movement of the cursor on the screen. The mouse cannot be used to enter text.
Advantage:
1) Easy to use
2) Not very expensive

Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in notebook or laptop
computer, instead of a mouse. This is a ball which is half inserted, and by changing fingers on
the ball, the pointer can be moved.
Advantage:
1) Trackball is stationary, so it does not require much space to use it.
2) Compact Size

3) Space ball
It is similar to trackball, but it can move in six directions where trackball can move in two
directions only. The movement is recorded by the strain gauge. Strain gauge is applied with
pressure. It can be pushed and pulled in various directions. The ball has a diameter around 7.5
cm. The ball is mounted in the base using rollers. One-third of the ball is an inside box, the rest
is outside.
Applications:
1) It is used for three-dimensional positioning of the object.
2) It is used to select various functions in the field of virtual reality.
3) It is applicable in CAD applications.
4) Animation is also done using spaceball.
5) It is used in the area of simulation and modeling.
4) Joystick
A Joystick is also a pointing device which is used to change cursor position on a monitor
screen. Joystick is a stick having a spherical ball as its both lower and upper ends as shown in
Fig. 1.20.
The lower spherical ball moves in a socket. The joystick can be changed in all four directions.
The function of a joystick is similar to that of the mouse. It is mainly used in Computer Aided
Designing (CAD) and playing computer games.

5) Light Pen

Light Pen (similar to the pen) is a pointing device which is used to select a displayed menu item
or draw pictures on the monitor screen. It consists of a photocell and an optical system placed
in a small tube. When its tip is moved over the monitor screen, and pen button is pressed, its
photocell sensing element detects the screen location and sends the corresponding signals to
the CPU.
Uses:
1) Light Pens can be used as input coordinate positions
2) If background color or intensity, a light pen can be used as a locator.
3) It is used as a standard pick device with many graphics system.
4) It can be used as stroke input devices.
5) It can be used as valuator

Digitizers
The digitizer is an operator input device, which contains a large, smooth board (the
appearance is similar to the mechanical drawing board) & an electronic tracking device
The electronic tracking device contains a switch for the user to record the desire x & y
coordinate positions. The coordinates can be entered into the computer memory or stored or
an off-line storage medium such as magnetic tape.

Advantages:
1) Drawing can easily be changed.
2) It provides the capability of interactive graphics.
3) Disadvantages:
4) Costly
5) Suitable only for applications which required high-resolution graphics

Touch Panels
Touch Panels is a type of display screen that has a touch-sensitive transparent panel covering
the screen. A touch screen registers input when a finger or other object comes in contact with
the screen. When the wave signals are interrupted by some contact with the screen, that
located is recorded. Touch screens have long been used in military applications.

Voice Recognition
Voice Recognition is one of the newest, most complex input techniques used to interact with
the computer. The user inputs data by speaking into a microphone. The simplest form of voice
recognition is a one-word command spoken by one person. Each command is isolated with
pauses between the words. Voice Recognition is used in some graphics workstations as input
devices to accept voice commands. The voice-system input can be used to initiate graphics
operations or to enter data. These systems operate by matching an input against a predefined
dictionary of words and phrase.

Advantage:

1) More efficient device.


2) Easy to use
3) Unauthorized speakers can be identified

Disadvantages:

1) Very limited vocabulary


2) Voice of different operators can't be distinguished.

10. Image Scanner


It is an input device. The data or text is written on paper. The paper is feeded to scanner. The
paper written information is converted into electronic format; this format is stored in the
computer. The input documents can contain text, handwritten material, picture extra.
By storing the document in a computer document became safe for longer period of time. The
document will be permanently stored for the future. We can change the document when we
need. The document can be printed when needed. Scanning can be of the black and white or
colored picture. On stored picture 2D or 3D rotations, scaling and other operations can be
applied.
Types of image Scanners:
Flat Bed Scanner:
It resembles a photocopy machine. It has a glass top on its top. Glass top in further covered
using a lid. The document to be scanned is kept on glass plate. The light is passed underneath
side of glass plate. The light is moved left to right. The scanning is done the line by line. The

process is repeated until the complete line is scanned. Within 20-25 seconds a document of 4"
* 6" can be scanned.
Fig 1.24 Flatbed Scanner
Hand Held Scanner:

It has a number of LED's (Light Emitting Diodes). The LED's are arranged in the small case. It is
called a Hand held Scanner because it can be kept in hand which performs scanning. For
scanning the scanner is moved over document from the top towards the bottom. Its light is on,
while we move it on document. It is dragged very slowly over document. If dragging of the
scanner over the document is not proper, the conversion will not correct.
HARDCOPY DEVICES

Fig 1.26 Classification of Printers

Types of printers
1) Impact Printers: The printers that print the characters by striking against the ribbon and
onto the papers are known as Impact Printers.
These Printers are of two types:
1) Character Printers
2) Line Printers
2) Non-Impact Printers: The printers that print the characters without striking against the
ribbon and onto the papers are called Non-Impact Printers. These printers print a complete
page at a time, therefore, also known as Page Printers.

Page Printers are of two types:


1) Laser Printers
2) Inkjet Printers
Impact Printers
1. Dotmatrix printers

Dot matrix has printed in the form of dots. A printer has a head which contains nine pins. The
nine pins are arranged one below other. Each pin can be activated independently.
All or only the same needles are activated at a time. When needless is not activated, and then
the tip of needle stay in the head. When pin work, it comes out of the print head.
In nine pin printer, pins are arranged in 5 * 7 matrixes.

Fig 1.27 Dotmatrix printer


Advantages of Dotmatrix printers

Dot Matrix Printers prints output as dots, so it can print any shape of the character. This allows
the printer to print special character, charts, graphs, etc.
Dot Matrix Printers come under the category of impact printers. The printing is done when the
hammer pin strikes the inked ribbon. The impressions are printed on paper. By placing
multiple copies of carbon, multiple copies of output can be produced.
It is suitable for printing of invoices of companies.
Daisy Wheel Printers

Head is lying on a wheel and Pins corresponding to characters are like petals of Daisy, that's
why called Daisy wheel printer.
Advantage:
More reliable than Dot Matrix Printers
Better Quality
Disadvantage:
Slower than Dot Matrix Printers

Drum Printers

These are line printers, which prints one line at a time. It consists of a drum. The shape of the
drum is cylindrical. The drum is solid and has characters embossed on it in the form of vertical
bands. The characters are in circular form. Each band consists of some characters.
Each line on drum consists of 132 characters. Because there are 96 lines so total characters are
(132 * 95) = 12, 672.

Chain Printers:

These are called as line printers. These are used to print one line at a line. Basically, chain
consists of links. Each link contains one character. Printers can follow any character set style,
i.e., 48, 64 or 96 characters. Printer consists of a number of hammers also.

Advantages:
Chain or Band if damaged can be changed easily.
It allows printing of different form.
Different Scripts can be printed using this printer.

Disadvantages:
It cannot print charts and graphs.
It cannot print characters of any shape.
Chain Printers is impact printer, hammer strikes so it is noise
2) Non-Impact Printers – Inkjet printers

These printers use a special link called electrostatic ink. The printer head has a special nozzle.
Nozzle drops ink on paper. Head contains up to 64 nozzles. The ink dropped is deflected by the
electrostatic plate. The plate is fixed outside the nozzle. The deflected ink settles on paper.
Advantages:
1) These produce high quality of output as compared to the dot matrix.
2) A high-quality output can be produced using 64 nozzles printed.
3) Inkjet can print characters in a variety of shapes.
4) Inkjet can print special characters.
5) The printer can print graphs and charts.
Disadvantages:
1) Inkjet Printers are slower than dot matrix printers.
2) The cost of inkjet is more than a dot matrix printer.

Non-Impact Printers – Laser printers

These printers uses laser lights to produces the dots needed to form the characters to be
printed on a page & hence the name laser printers.

The output is generated in the following steps:


Step1: The bits of data sent by processing unit act as triggers to turn the laser beam on & off.
Step2: The output device has a drum which is cleared & is given a positive electric charge.
To print a page the laser beam passing from the laser scans back & forth the surface of the
drum.
Step3: The laser exposed parts of the drum attract an ink powder known as toner.
Step4: The attracted ink powder is transferred to paper.
Step5: The ink particles are permanently fixed to the paper by using either heat or pressure
technique.
Step6: The drum rotates back to the cleaner where a rubber blade cleans off the excess ink &
prepares the drum to print the next page.
PLOTTERS

Plotters are a special type of output device. It is suitable for applications:


Architectural plan of the building.
CAD applications like the design of mechanical components of aircraft.
Many engineering applications.

Advantage:
1) It can produce high-quality output on large sheets.
2) It is used to provide the high precision drawing.
3) It can produce graphics of various sizes.
4) The speed of producing output is high

GRAPHICS SOFTWARE
There are two types of Graphics Software.
General Purpose Packages: Basic Functions in a general package include those for generating
picture components (straight lines, polygons, circles and other figures), setting color and
intensity values, selecting views, and applying transformations. Example of general-purpose
package is the GL (Graphics Library), GKS, PHIGS, PHIGS+ etc.
Special Purpose Packages: These packages are designed for non programmers, so that these
users can use the graphics packages, without knowing the inner details.
Example of special purpose package is :
1) Painting programs
2) Package used for business purpose
3) Package used for medical systems.
4) CAD packages
LINE DRAWING ALGORITHMS

A line connects two points. It is a basic element in graphics. To draw a line, you need two
end points (x1,y1) and (x2,y2). The line segment is sampled at unit intervals in one
coordinate and corresponding integer values nearer to the line path are determined for
other coordinates.

Equation of a line is given by :


y = mx+b

where m is the slope of the line and b is the slope intercept.

b = y-mx

Considering a line with positive slope, if the slope is less than or equal to 1, we sample at
unit x intervals (dx=1) and compute successive y values as :

Yk+1 =Yk + m

Subscript k takes integer values starting from 0, for the 1st point and increases along x axis
in unit intervals until the endpoint is reached. Y is rounded off to a nearest integer to
correspond to a screen pixel.

Similarly, if the slope is greater than or equal to 1, we sample at unit y intervals (dy=1) and
compute x in successive manner as :

X k+1 = X k + 1/m

In computer graphics, popular algorithms used to generate lines are-


1. Digital Differential Analyzer (DDA) Line Drawing Algorithm
2. Bresenham Line Drawing Algorithm

1. Digital Differential Analyzer (DDA) line drawing algorithm


The digital differential analyzer (DDA) algorithm is an incremental scan-conversion method.
Such an approach is characterized by performing calculations at each step using results
from the preceding step.
Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using DDA Algorithm involves the following steps-
Step-01:
Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
ΔX = Xn – X0
ΔY =Yn – Y0
M = ΔY / ΔX

Step-02:

Find the number of steps or points in between the starting and ending coordinates.

if (absolute (ΔX) > absolute (ΔY))


Steps = absolute (ΔX);
else
Steps = absolute (ΔY);

Step-03:

Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Find the next point by following the below three cases-

Step-04:

Keep repeating Step-03 until the end point is reached or the number of generated new
points (including the starting and ending points) equals to the steps count.

Example: Calculate the points between the starting point (5, 6) and ending point (8, 12).
Given-
 Startingcoordinates = (X0, Y0) = (5, 6)
 Ending coordinates = (Xn, Yn) = (8, 12)

Step-01:
Calculate ΔX, ΔY and M from the given input.
 ΔX= Xn – X0 = 8 – 5 = 3
 ΔY =Yn – Y0 = 12 – 6 = 6

 M = ΔY / ΔX = 6 / 3 = 2

Step-02:
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
Step-03:
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)

5 6 5.5 7 (6, 7)

5.5 6 6 8 (6, 8)

6 8 6.5 9 (7, 9)

6.5 9 7 10 (7, 10)

7 10 7.5 11 (8, 11)

7.5 11 8 12 (8, 12)


Advantages of DDA Algorithm
The advantages of DDA Algorithm are:
 It is a simple algorithm.
 It is easy to implement.
 It avoids using the multiplication operation which is costly in terms of time complexity.
Disadvantages of DDA Algorithm
The disadvantages of DDA Algorithm are:
 There is an extra overhead of using round off( ) function.
 Using round off( ) function increases time complexity of the algorithm.
 Resulted lines are not smooth because of round off( ) function.
 The points generated by this algorithm are not accurate.

2. Bresenham line drawing algorithm


The big advantage of this algorithm is that it uses
only integer calculations.
The main idea of the Bresenham’s line drawing
algorithm: Move across the x-axis in unit intervals
and at each step choose between two different y
coordinates. For example from position (2,3) we
have to choose between (3,3) and (3,4), we would
like the point that is closer to the original line.
Given the starting and ending coordinates of a
line,
Bresenham Line Drawing Algorithm attempts to
generate the points between the starting and
ending coordinates.

Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)

The points generation using Bresenham Line Drawing Algorithm involves the following
steps-

Step-01:
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
ΔX = Xn – X0
ΔY =Yn – Y0

Step-02:
Calculate the decision parameter Pk.
It is calculated as-
Pk = 2ΔY – ΔX

Step-03:

Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter Pk.

Follow the below two cases-

Step-04:

Keep repeating Step-03 until the end point is reached or number of iterations equals to (ΔX-
1) times.

Example: Calculate the points between the starting coordinates (9, 18) and ending
coordinates (14, 22).

Given-
Starting coordinates = (X0, Y0) = (9, 18)
Ending coordinates = (Xn, Yn) = (14, 22)
Step-01:

Calculate ΔX and ΔY from the given input.


ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4

Step-02:

Calculate the decision parameter.


Pk
= 2ΔY – ΔX
=2x4–5
=3
So, decision parameter Pk = 3

Step-03:

As Pk >= 0, so case-02 is satisfied.

Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
Xk+1 = Xk + 1 = 9 + 1 = 10
Yk+1 = Yk + 1 = 18 + 1 = 19

Similarly, Step-03 is executed until the end point is reached or number of iterations equals
to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)

Pk Pk+1 Xk+1 Yk+1


9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Advantages of Bresenham Line Drawing Algorithm-
The advantages of Bresenham Line Drawing Algorithm are-
 It is easy to implement.
 It is fast and incremental.
 It executes fast but less faster than DDA Algorithm.
 The points generated by this algorithm are more accurate than DDA Algorithm.
 It uses fixed points only.

Disadvantages of Bresenham Line Drawing Algorithm-


The disadvantages of Bresenham Line Drawing Algorithm are-
 Though it improves the accuracy of generated points but still the resulted line is not
smooth.
 This algorithm is for the basic line drawing.
 It can not handle diminishing jaggies.

Difference between DDA Line Drawing Algorithm and Bresenhams Line Drawing
Algorithm

Features Digital Differential Analyzer Bresenham’s Line Drawing


Line Drawing Algorithm Algorithm
Arithmetic DDA algorithm uses floating Bresenham’s algorithm uses fixed
points i.e. Real Arithmetic. points i.e. Integer Arithmetic
Operation DDA algorithm uses Bresenham’s algorithm uses only
s multiplication and division in subtraction and addition in its
its operations. operations.
Speed DDA algorithm is rather Bresenham’s algorithm is faster
slowly than Bresenham’s than DDA algorithm in line
algorithm in line drawing drawing because it performs only
because it uses real addition and subtraction in its
arithmetic (floating point calculation and uses only integer
operations) arithmetic so it runs significantly
faster.
Accuracy DDA algorithm is not as Bresenham’s algorithm is more
& accurate and efficient as efficient and much accurate than
Efficiency Bresenham’s algorithm DDA algorithm.
Drawing DDA algorithm can draw Bresenham’s algorithm can draw
circles and curves but that are circles and curves with much
not as accurate as more accuracy than DDA
Bresenham’salgorithm algorithm.
Round off DDA algorithm round off the Bresenham’s algorithm does not
coordinates to integer that is round but takes the incremental
nearest to the line value in its operation.
Expensive DDA algorithm uses an Bresenham’s algorithm is less
enormous number of floating- expensive than DDA algorithm as
point multiplications so it is it uses only addition and
expensive subtraction.
Circle Drawing Algorithm

Circle is an eight-way symmetric figure. The shape of circle is the same in all quadrants. In
each quadrant, there are two octants. If the calculation of the point of one octant is done,
then the other seven points can be calculated easily by using the concept of eight-way
symmetry.

For drawing, circle considers it at the origin. If a point is P1(x, y), then the other seven points
will be

So we will calculate only 45°arc. From which the whole circle can be determined easily.

If we want to display circle on screen then the putpixel function is used for eight points as
shown below:
putpixel (x, y ,color)
putpixel (x, -y, color)
putpixel (-x, y, color)
putpixel (-x, -y, color)
putpixel (y, x, color)
putpixel (y, -x, color)
putpixel (-y, x, color)
putpixel (-y, -x, color)

Example: Let we determine a point (2, 7) of the circle then other points will be (2, -7), (-2, -
7), (-2, 7), (7, 2), (-7, 2), (-7, -2), (7, -2)

These seven points are calculated by using the property of reflection. The reflection is
accomplished in the following way:

The reflection is accomplished by reversing x, y co-ordinates.

Mid Point Subdivision algorithm for Circle


The mid-point circle drawing algorithm is an algorithm used to determine the points
needed for generating a circle. We use the mid-point algorithm to calculate all the
perimeter points of the circle in the first octant and then print them along with their mirror
points in the other octants. This will work because a circle is symmetric about it’s centre.
Procedure-

Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R

The points generation using Mid Point Circle Drawing Algorithm involves the following
steps-

Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R

Step-02:
Calculate the value of initial decision parameter P0 as-

P0 = 1 – R
Step-03:

Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
Follow the below two cases-
Step-04:

If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0

Here, (Xc, Yc) denotes the current value of X and Y coordinates.

Step-05:

Keep repeating Step-03 and Step-04 until Xplot >= Yplot.

Step-06:

Step-05 generates all the points for one octant.


To find the points for other seven octants, follow the eight symmetry property of circle.
This is depicted by the following figure-
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to form
a circle.

Solution-

Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 10

Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 10

Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Step-03:

As Pinitial < 0, so case-01 is satisfied.

Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6

Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).

Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-

Pk Pk+1 (Xk+1, Yk+1)


(0, 10)
-9 -6 (1, 10)
-6 -1 (2, 10)
-1 6 (3, 10)
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm Terminates
These are all points for Octant-1.

Algorithm calculates all the points of octant-1 and terminates.


Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y
coordinates.

Octant-1 Points Octant-2 Points


(0, 10) (8, 6)
(1, 10) (9, 5)
(2, 10) (9, 4)
(3, 10) (10, 3)
(4, 9) (10, 2)
(5, 9) (10, 1)
(6, 8) (10, 0)
These are all points for Quadrant-1.

Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.

Here, all the points have been generated with respect to quadrant-1-

Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y)


(0, 10) (0, 10) (0, -10) (0, -10)
(1, 10) (-1, 10) (-1, -10) (1, -10)
(2, 10) (-2, 10) (-2, -10) (2, -10)
(3, 10) (-3, 10) (-3, -10) (3, -10)
(4, 9) (-4, 9) (-4, -9) (4, -9)
(5, 9) (-5, 9) (-5, -9) (5, -9)
(6, 8) (-6, 8) (-6, -8) (6, -8)
(8, 6) (-8, 6) (-8, -6) (8, -6)
(9, 5) (-9, 5) (-9, -5) (9, -5)
(9, 4) (-9, 4) (-9, -4) (9, -4)
(10, 3) (-10, 3) (-10, -3) (10, -3)
(10, 2) (-10, 2) (-10, -2) (10, -2)
(10, 1) (-10, 1) (-10, -1) (10, -1)
(10, 0) (-10, 0) (-10, 0) (10, 0)
These are all points of the Circle.

The advantages of Mid-Point Circle Drawing Algorithm are-


 It is a powerful and efficient algorithm.
 The entire algorithm is based on the simple equation of circle X2 + Y2 = R2.
 It is easy to implement from the programmer’s perspective.
 This algorithm is used to generate curves on raster displays.

The disadvantages of Mid Point Circle Drawing Algorithm are-


 Accuracy of the generating points is an issue in this algorithm.
 The circle generated by this algorithm is not smooth.
 This algorithm is time consuming.

Bresenham Circle Drawing Algorithm

One of the most efficient and easiest to drive of the circle algorithms is due to Bresenham.
To begin, note that only one octant of the circle need be generated. The other parts can be
obtained by successive reflections. If the first octant ( 0 to 45 ccw ) is generated, the second
octant can be obtained by reflection through the line y=x to yield the first quadrant. The
results in the first quadrant are reflected through the line x=0 to obtain those in the second
quadrant.

The combined result in the upper semicircle are reflected through the line y=0 to complete
the circle. Bresenham`s Algorithm is consider the first quadrant of an origin- centered circle.
If the algorithm begins at x=0 , y=r, then for clockwise generation of the circle y is a
monotonically decreasing function of x in the first quadrant. Here the clockwise generation
starting at x=0, y=r is chosen. The center of the circle is ( 0,0 ).

We cannot display a continuous arc on the raster display. Instead, we have to choose the
nearest pixel position to complete the arc. From the following illustration, you can see that
we have put the pixel at (X, Y) location and now need to decide where to put the next pixel:
at N (X+1, Y) or at S (X+1, Y-1).

This can be decided by the decision parameter p.


 If p <= 0, then N(X+1, Y) is to be chosen as next pixel.
 If p > 0, then S(X+1, Y-1) is to be chosen as the next pixel.

Algorithm

Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R

The points generation using Bresenham Circle Drawing Algorithm involves the following
steps-

Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R

Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R

Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
Follow the below two case:

Step-04:
If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0

Here, (Xc, Yc) denotes the current value of X and Y coordinates.

Step-05:
Keep repeating Step-03 and Step-04 until Xplot => Yplot.

Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
Example: Given the centre point coordinates (0, 0) and radius as 8, generate all the points to
form a circle.
Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 8

Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 8

Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P0 = -13

Step-03:
As Pinitial < 0, so case-01 is satisfied.

Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 8
Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3

Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).

Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-

Pk Pk+1 (Xk+1, Yk+1)


(0, 8)
-13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y
coordinates.

Octant-1 Points Octant-2 Points


(0, 8) (5, 5)
(1, 8) (6, 4)
(2, 8) (7, 3)
(3, 7) (8, 2)
(4, 6) (8, 1)
(5, 5) (8, 0)
These are all points for Quadrant-1.

Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.

Here, all the points have been generated with respect to quadrant-1-

Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y)


(0, 8) (0, 8) (0, -8) (0, -8)
(1, 8) (-1, 8) (-1, -8) (1, -8)
(2, 8) (-2, 8) (-2, -8) (2, -8)
(3, 7) (-3, 7) (-3, -7) (3, -7)
(4, 6) (-4, 6) (-4, -6) (4, -6)
(5, 5) (-5, 5) (-5, -5) (5, -5)
(6, 4) (-6, 4) (-6, -4) (6, -4)
(7, 3) (-7, 3) (-7, -3) (7, -3)
(8, 2) (-8, 2) (-8, -2) (8, -2)
(8, 1) (-8, 1) (-8, -1) (8, -1)
(8, 0) (-8, 0) (-8, 0) (8, 0)
These are all points of the Circle.

Midpoint ellipse drawing algorithm


This is an incremental method for scan converting an ellipse that is centered at the origin in
standard position i.e., with the major and minor axis parallel to coordinate system axis. It is
very similar to the midpoint circle algorithm. Because of the four-way symmetry property we
need to consider the entire elliptical curve in the first quadrant.
Midpoint ellipse algorithm plots(finds) points of an ellipse on the first quadrant by dividing
the quadrant into two regions.
Each point(x, y) is then projected into other three quadrants (-x, y), (x, -y), (-x, -y) i.e. it uses
4-way symmetry.
Function of ellipse:
fellipse(x, y)=ry2x2+rx2y2-rx2ry2
fellipse(x, y)<0 then (x, y) is inside the ellipse.
fellipse(x, y)>0 then (x, y) is outside the ellipse.
fellipse(x, y)=0 then (x, y) is on the ellipse.

Decision parameter:
Initially, we have two decision parameters p1 0 in region 1 and p20 in region 2.
These parameters are defined as : p1 0 in region 1 is given as :
p10=ry2+1/4rx2-rx2ry
Mid-Point Ellipse Algorithm:
1. Take input radius along x axis and y axis and obtain center of ellipse.
2. Initially, we assume ellipse to be centered at origin and the first point as : (x, y 0)= (0, ry).
3. Obtain the initial decision parameter for region 1 as: p1 0=ry2+1/4rx2-rx 2ry
4. For every xk position in region 1 :
If p1k<0 then the next point along the is (x k+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
5. Obtain the initial value in region 2 using the last point (x 0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
6. At each yk in region 2 starting at k =0 perform the following task.
If p2k>0 the next point is (xk, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
7. Else, the next point is (xk+1, yk -1) and p2k+1.=p2k+2ry2xk+1 -2rx2yk+1+rx2
8. Now obtain the symmetric points in the three quadrants and plot the coordinate value as:
x=x+xc, y=y+yc
9. Repeat the steps for region 1 until 2r y2x =2rx2y

Area Filling Algorithm


Polygon Filling Algorithm
Polygon is an ordered list of vertices. For filling polygons with particular colors, you need to determine the pixels falling
on the border of the polygon and those which fall inside the polygon. Filled Area primitives are used to filling
solid colors to an area or image or polygon. Filling the polygon means highlighting its pixel
with different solid colors. Following are two filled area primitives:
1. Seed Fill Algorithm
2. Scan Fill Algorithm

Seed Fill Algorithm:

In this seed fill algorithm, we select a starting point called seed inside the boundary of the
polygon. The seed algorithm can be further classified into two algorithms: Flood Fill and
Boundary filled.

Flood Fill Algorithm:

In this flood-fill algorithm, a seed point is taken inside the polygon. The flood fill algorithm
is used when the polygon has multiple color boundaries. In this method, the related pixels
are replaced with the selected color using fill color. The selected pixel values before are
reassigned with the selected color value. This can be done using two approaches either
4-connected or 8-connected.

Algorithm:
Function floodfill(x, y, fillcolor, previouscolor)
if (getpixel (x, y) = previouscolor)
{
setpixel (x, y, fillcolor);
floodfill( x+1, y, fillcolor,previouscolor);
floodfill( x-1, y, fillcolor,previouscolor);
floodfill( x, y+1, fillcolor,previouscolor);
floodfill( x, y-1, fillcolor,previouscolor);
}
getpixel() - The color of specified pixel.
setpixel() - Sets the pixel to specified color.
Advantages:
 This method is easy to fill colors in computer graphics.
 It fills the same color inside the boundary.
Disadvantages:
 Fails with large area polygons.
 It is a slow method to fill the area.

Boundary Fill Algorithm:

The boundary fill algorithm uses polygon boundaries. It is also called an edge fill algorithm.
In this method, a seed point is taken in the polygon boundary and checks whether the
adjacent or neighboring pixel is colored or not. If the adjacent pixel is not colored then, fill
it. This can be done using two approaches: 4-connected or 8-connected.

Algorithm:
Function boundaryfill(x, y, color, color1)
int c;
c = getpixel(x ,y);
if (c! =color) & (c!=color1)
{
setpixel (x, y, color);
boundaryfill( x+1, y, color, color1);
boundaryfill( x-1, y, color, color1);
boundaryfill( x, y+1, color, color1);
boundaryfill( x, y-1, color, color1);
}
Advantages:
 The boundary fill algorithm is used to create attractive paintings.
Disadvantages:
 In the 4-connected approach, it does not color corners.

Scan Fill Algorithm:

Scan fill algorithm is an area-filling algorithm that fill colors by scanning horizontal lines.
These horizontal lines intersect the boundaries of the polygon and fill colors between the
intersection points. Its main purpose is to fill colors in the interior pixels of the polygon.

Scan Line Algorithm

Advantages:
 Scan fill algorithm fills the polygon in the same order as rendering.
 It takes advantage of coherence thus, a fast algorithm.
Disadvantages:
 The intensity of the pixels is unequal.
 Staircase-like appearance when scan line converted to circles.

You might also like