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

Unit I-computer graphics

The document provides an overview of computer graphics, detailing various video display devices such as CRT, LCD, LED, and plasma displays, along with their components, advantages, and disadvantages. It also covers input devices like keyboards, mice, and joysticks, as well as output devices including plotters and printers, explaining their functionalities and applications. The increasing demand for high-quality displays and the evolution of input/output technologies are emphasized throughout the text.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Unit I-computer graphics

The document provides an overview of computer graphics, detailing various video display devices such as CRT, LCD, LED, and plasma displays, along with their components, advantages, and disadvantages. It also covers input devices like keyboards, mice, and joysticks, as well as output devices including plotters and printers, explaining their functionalities and applications. The increasing demand for high-quality displays and the evolution of input/output technologies are emphasized throughout the text.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Unit I

Overview Of computer Graphics


Video Display Devices
Computer graphics is an art of drawing pictures on computer screens with the help of
programming. It involves computations, creation, and manipulation of data. In other words, we
can say that computer graphics is a rendering tool for the generation and manipulation of images.
The display device is an output device used to represent the information in the form of images
(visual form). Display systems are mostly called a video monitor or Video display unit (VDU).
Display devices are designed to model, display, view, or display information. The purpose of
display technology is to simplify information sharing.
Today, the demand for high-quality displays is increasing.
There are some display devices given below:
Cathode-Ray Tube(CRT)
Color CRT Monitor
Liquid crystal display(LCD)
Light Emitting Diode(LED)
Direct View Storage Tubes(DVST)
Plasma Display
3D Display
Cathode-ray Tube (CRT): Here, CRT stands for Cathode ray tube. It is a technology which is
used in traditional computer monitor and television.
Cathode ray tube is a particular type of vacuum tube that displays images when an electron beam
collides on the radiant surface.

Component of CRT
Electron Gun: The electron gun is made up of several elements, mainly a heating filament
(heater) and a cathode. The electron gun is a source of electrons focused on a narrow beam
facing the CRT.
Focusing & Accelerating Anodes: These anodes are used to produce a narrow and sharply
focused beam of electrons.
Horizontal & Vertical Deflection Plates: These plates are used to guide the path of the electron
the beam. The plates produce an electromagnetic field that bends the electron beam through the
area as it travels.
Phosphorus-coated Screen: The phosphorus coated screen is used to produce bright spots when
the high-velocity electron beam hits it.
There are two ways to represent an object on the screen:
Raster Scan: It is a scanning technique in which the electron beam moves along the screen. It
moves from top to bottom, covering one line at a time.
A raster scan is based on pixel intensity control display as a rectangular box on the screen called
a raster.
Picture description is stored in the memory area called as Refresh buffer, or Frame Buffer.
Frame buffer is also known as Raster or Bitmap. Raster scan provides the refresh rate of 60 to 80
frames per second.
For Example: Television
The beam refreshing has two types:
Horizontal Retracing
Vertical Retracing
When the beam starts from the top left corner and reaches bottom right, and again return to the
top left, it is called the vertical retrace.
It will call back from top to bottom more horizontally as a horizontal reversal.

Advantages:
Real image
Many colors to be produced
Dark scenes can be pictured
Disadvantages:
Less resolution
Display picture line by line
More costly
2. Random Scan (Vector scan): It is also known as stroke-writing display or calligraphic
display. In this, the electron beam points only to the area in which the picture is to be drawn.
It uses an electron beam like a pencil to make a line image on the screen. The image is
constructed from a sequence of straight-line segments. On the screen, each line segment is drawn
by the beam to pass from one point on the screen to the other, where its x & y coordinates define
each point.
After compilation of picture drawing, the system cycle back to the first line and create all the
lines of picture 30 to 60 times per second.

Fig: A Random Scan display draws the lines of an object in a specific order
Advantages:
High Resolution
Draw smooth line Drawing
Disadvantages:
It does only the wireframe.
It creates complex scenes due to flicker.
2. Color CRT Monitor: It is similar to a CRT monitor.
The basic idea behind the color CRT monitor is to combine three basic colors- Red, Green, and
Blue. By using these three colors, we can produce millions of different colors.
The two basic color display producing techniques are:
Beam-Penetration Method: It is used with a random scan monitor for displaying pictures. There
are two phosphorus layers- Red and Green are coated inside the screen. The color shown
depends on how far the electron beam penetrates the phosphorus surface.
A powerful electron beam penetrates the CRT, it passes through the red layer and excites the
green layer within.
A beam with slow electrons excites only the red layer.
A beam with the medium speed of electrons, a mixture of red and green light is emitted to
display two more colors- orange and yellow.

Advantages:
Better Resolution
Half cost
Inexpensive
Disadvantages:
Only four possible colors
Time Consuming
2. Shadow-Mask Method: It is used with a raster scan monitor for displaying pictures. It has
more range of color than the beam penetration method. It is used in television sets and monitors.
Structure:
It has three phosphorus color dots at each position of the pixel.
First Dot: Red color
Second Dot: Green color
Third Dot: Blue color
It has three different guns. Each for one color.
It has a metal screen or plate just before the phosphorus screen, named “Shadow-Mask.”
It also has a shadow grid just behind the phosphorus coated screen with tiny holes in a triangular
shape.
Working: A Shadow Mask is a metal plate with tiny holes present inside a color monitor.
A Shadow Mask directs the beam by consuming the electrons so that the beam hits only the
desired point and displays a resulting picture.
It has three different guns. These guns direct their beams to shadow mask, which allows them to
pass. It is a task of a shadow mask to direct the beam on its particular dot on the screen and
produce a picture on the screen.
A Shadow Mask can display a wider range of pictures than beam penetration.

Advantages:
Display a wider range picture.
Display realistic images.
In-line arrangement of RGB color.
Disadvantages:
Difficult to cover all three beams on the same hole.
Poor Resolution.
3. Liquid crystal display (LCD): The LCD depends upon the light modulating properties of
liquid crystals.
LCD is used in watches and portable computers. LCD requires an AC power supply instead of
DC, so it is difficult to use it in circuits.
It generally works on flat panel display technology. LCD consumes less power than LED. The
LCD screen uses the liquid crystal to turn pixels on or off.
Liquid Crystals are a mixture of solid and liquid. When the current flows inside it, its position
changes into the desired color.
For Example: TFT (Thin Film Transistor)
Advantages:
Produce a bright image
Energy efficient
Completely flat screen
Disadvantages:
Fixed aspect ratio & Resolution
Lower Contrast
More Expensive
4. Light Emitting Diode (LED): LED is a device which emits when current passes through it. It
is a semiconductor device.
The size of the LED is small, so we can easily make any display unit by arranging a large
number of LEDs.
LED consumes more power compared to LCD. LED is used on TV, smartphones, motor
vehicles, traffic light, etc.
LEDs are powerful in structure, so they are capable of withstanding mechanical pressure. LED
also works at high temperatures.
Advantages:
The Intensity of light can be controlled.
Low operational Voltage.
Capable of handling the high temperature.
Disadvantages:
More Power Consuming than LCD.
5. Direct View Storage Tube (DVST): It is used to store the picture information as a charge
distribution behind the phosphor-coated screen.
There are two guns used in DVST:
Primary Gun: It is used to store the picture information.
Flood / Secondary Gun: It is used to display a picture on the screen.
Advantages:
Less Time Consuming
No Refreshing Required
High-Resolution
Less Cost
Disadvantages:
The specific part of the image cannot be erased.
They do not display color.
6. Plasma Display: It is a type of flat panel display which uses tiny plasma cells. It is also
known as the Gas-Discharge display.
Components of Plasma display
Anode: It is used to deliver a positive voltage. It also has the line wires.
Cathode: It is used to provide negative voltage to gas cells. It also has fine wires.
Gas Plates: These plates work as capacitors. When we pass the voltage, the cell lights regularly.
Fluorescent cells: It contains small pockets of gas liquids when the voltage is passed to this neon
gas. It emits light.
Advantages:
Wall Mounted
Slim
Wider angle
Disadvantages:
Phosphorus loses luminosity over time.
It consumes more electricity than LCD.
Large Size
7. 3D Display: It is also called stereoscope display technology. This technology is capable of
bringing depth perception to the viewer.
It is used for 3D gaming and 3D TVs.
For Example: Fog Display, Holographic Display, Retina Display Etc.
Advantages:
Impressive Picture Quality
Impressive Picture Quality
Impressive Picture Quality
Disadvantage:
Expensive
Binocular Fusion
Input Devices
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.
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.
Function 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. Dials are used to
enter scalar values. Dials also enter real numbers. Buttons and switches are used to enter
predefined function values.
Advantage:
Suitable for entering numeric data.
Function keys are a fast and effective method of using commands, with fewer errors.
Disadvantage:
Keyboard is not suitable for graphics input.
Mouse:
A Mouse is a pointing device and used to position the pointer on the screen. It is a small palm
size box. 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. Therefore, they are used in conjunction with a keyboard.
Advantage:
Easy to use
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:
Trackball is stationary, so it does not require much space to use it.
Compact Size

Spaceball:
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:
It is used for three-dimensional positioning of the object.
It is used to select various functions in the field of virtual reality.
It is applicable in CAD applications.
Animation is also done using spaceball.
It is used in the area of simulation and modeling.

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

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:
Light Pens can be used as input coordinate positions by providing necessary arrangements.
If background color or intensity, a light pen can be used as a locator.
It is used as a standard pick device with many graphics system.
It can be used as stroke input devices.
It can be used as valuators

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, which can be changed
over the surface to follow existing lines. 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.
digitizer
Advantages:
Drawing can easily be changed.
It provides the capability of interactive graphics.
Disadvantages:
Costly
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 Systems (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
phrases.
Advantage:
More efficient device.
Easy to use
Unauthorized speakers can be identified
Disadvantages:
Very limited vocabulary
Voice of different operators can't be distinguished.
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.

Plotter
Advantage:
It can produce high-quality output on large sheets.
It is used to provide the high precision drawing.
It can produce graphics of various sizes.
The speed of producing output is high.
Drum Plotter:
It consists of a drum. Paper on which design is made is kept on the drum. The drum can rotate in
both directions. Plotters comprised of one or more pen and penholders. The holders are mounted
perpendicular to drum surface. The pens are kept in the holder, which can move left to the right
as well as right to the left. The graph plotting program controls the movement of pen and drum.

Flatbed Plotter:
It is used to draw complex design and graphs, charts. The Flatbed plotter can be kept over the
table. The plotter consists of pen and holder. The pen can draw characters of various sizes. There
can be one or more pens and pen holding mechanism. Each pen has ink of different color.
Different colors help to produce multicolor design of document. The area of plotting is also
variable. It can vary A4 to 21'*52'.
Flatbed Plotter
It is used to draw
Cars
Ships
Airplanes
Shoe and dress designing
Road and highway design

Hard copy Devices


Printers
Printer is an output device, which is used to print information on paper.
There are two types of printers −
Impact Printers
Non-Impact Printers
Impact Printers
Impact printers print the characters by striking them on the ribbon, which is then pressed on the
paper.
Characteristics of Impact Printers are the following −
Very low consumable costs
Very noisy
Useful for bulk printing due to low cost
There is physical contact with the paper to produce an image
These printers are of two types −
Character printers
Line printers
Character Printers
Character printers are the printers which print one character at a time.
These are further divided into two types:
Dot Matrix Printer(DMP)
Daisy Wheel
Dot Matrix Printer
In the market, one of the most popular printers is Dot Matrix Printer. These printers are popular
because of their ease of printing and economical price. Each character printed is in the form of
pattern of dots and head consists of a Matrix of Pins of size (5*7, 7*9, 9*7 or 9*9) which come
out to form a character which is why it is called Dot Matrix Printer.

Advantages
Inexpensive
Widely Used
Other language characters can be printed
Disadvantages
Slow Speed
Poor Quality
Daisy Wheel
Head is lying on a wheel and pins corresponding to characters are like petals of Daisy (flower)
which is why it is called Daisy Wheel Printer. These printers are generally used for word-
processing in offices that require a few letters to be sent here and there with very nice quality.

Advantages
More reliable than DMP
Better quality
Fonts of character can be easily changed
Disadvantages
Slower than DMP
Noisy
More expensive than DMP
Line Printers
Line printers are the printers which print one line at a time.

Line printer
These are of two types −
Drum Printer
Chain Printer
Drum Printer
This printer is like a drum in shape hence it is called drum printer. The surface of the drum is
divided into a number of tracks. Total tracks are equal to the size of the paper, i.e. for a paper
width of 132 characters, drum will have 132 tracks. A character set is embossed on the track.
Different character sets available in the market are 48 character set, 64 and 96 characters set. One
rotation of drum prints one line. Drum printers are fast in speed and can print 300 to 2000 lines
per minute.
Advantages
Very high speed
Disadvantages
Very expensive
Characters fonts cannot be changed

Chain Printer
In this printer, a chain of character sets is used, hence it is called Chain Printer. A standard
character set may have 48, 64, or 96 characters.
Advantages
Character fonts can easily be changed.
Different languages can be used with the same printer.
Disadvantages
Noisy
Non-impact Printers
Non-impact printers print the characters without using the ribbon. These printers print a complete
page at a time, thus they are also called as Page Printers.
These printers are of two types −
Laser Printers
Inkjet Printers
Characteristics of Non-impact Printers
Faster than impact printers
They are not noisy
High quality
Supports many fonts and different character size
Laser Printers
These are non-impact page printers. They use laser lights to produce the dots needed to form the
characters to be printed on a page.

Advantages
Very high speed
Very high quality output
Good graphics quality
Supports many fonts and different character size
Disadvantages
Expensive
Cannot be used to produce multiple copies of a document in a single printing
Inkjet Printers
Inkjet printers are non-impact character printers based on a relatively new technology. They print
characters by spraying small drops of ink onto paper. Inkjet printers produce high quality output
with presentable features.
They make less noise because no hammering is done and these have many styles of printing
modes available. Color printing is also possible. Some models of Inkjet printers can produce
multiple copies of printing also.
Advantages
High quality printing
More reliable
Disadvantages
Expensive as the cost per page is high
Slow as compared to laser printer
Graphics software refers to a program or collection of programs that enable a person to
manipulate images or models visually on a computer.
Computer graphics can be classified into distinct categories: raster graphics and vector graphics,
with further 2D and 3D variants. Many graphics programs focus exclusively on either vector or
raster graphics, but there are a few that operate on both. It is simple to convert from vector
graphics to raster graphics, but going the other way is harder. Some software attempts to do this.
In addition to static graphics, there are animation and video editing software. Different types of
software are often designed to edit different types of graphics such as video, photos, and vector-
based drawings. The exact sources of graphics may vary for different tasks, but most can read
and write files.

Points and Lines


A line connects two points. It is a basic element in graphics. To draw a line, you need two
points between which you can draw a line. In the following three algorithms, we refer the one
point of line as X0,Y0X0,Y0 and the second point of line as X1,Y1X1,Y1.
 Point plotting is done by converting a single coordinate position
furnished by an application program into appropriate operations for the
output device inuse.
 Line drawing is done by calculating intermediate positions along the line
path between two specified endpointpositions.
 The output device is then directed to fill in those positions between the
endpoints with somecolor.
 For some device such as a pen plotter or random scan display, a straight
line can be drawn smoothly from one end point together.
 Digital devices display a straight line segment by plotting discrete points
between the twoendpoints.
 Discrete coordinate positions along the line path are calculated from the
equation of theline.
 For a raster video display, the line intensity is loaded in frame
buffer at the corresponding pixel positions.
 Reading from the frame buffer, the video controller then plots the screenpixels.
 Screen locations are referenced with integer values, so plotted positions
may only approximate actual line positions between two
specifiedendpoints.
 For example line position of (12.36, 23.87) would be converted to pixel position
(12,24).
 Thisroundingofcoordinatevaluestointegerscauseslinestobedisplayed

DDA Algorithm
Digital Differential Analyzer DDA. DDA algorithm is the simple line generation algorithm
which is explained step by step here.
Step 1 − Get the input of two end points (X0,Y0)(X0,Y0) and (X1,Y1)(X1,Y1).
Step 2 − Calculate the difference between two end points.
dx = X1 - X0
dy = Y1 - Y0
Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps
to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
if (absolute(dx) > absolute(dy))
Steps = absolute(dx);
else
Steps = absolute(dy);
Step 4 − Calculate the increment in x coordinate and y coordinate.
Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;
Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and
complete the drawing of the line.
for(int v=0; v < Steps; v++)
{
x = x + Xincrement;
y = y + Yincrement;
putpixel(Round(x), Round(y));
}
Bresenham’s Line Generation Algorithm
The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage
of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit
intervals and at each step choose between two different y coordinates.
For example, as shown in the following illustration, from position 2,32,3 you need to choose
between 3,33,3 and 3,43,4. You would like the point that is closer to the original line.

At sample position Xk+1,Xk+1, the vertical separations from the mathematical line are labelled
as dupperdupper and dlowerdlower.
From the above illustration, the y coordinate on the mathematical line at Xk+1is −
Y = m$Xk$+1$Xk$+1 + b
So, dupperdupper and dlowerdlower are given as follows −
dlower=y−ykdlower=y−yk
=m(Xk+1)+b−Yk=m(Xk+1)+b−Yk
and
dupper=(yk+1)−ydupper=(yk+1)−y
=Yk+1−m(Xk+1)−b=Yk+1−m(Xk+1)−b
You can use these to make a simple decision about which pixel is closer to the mathematical
line. This simple decision is based on the difference between the two pixel positions.
dlower−dupper=2m(xk+1)−2yk+2b−1dlower−dupper=2m(xk+1)−2yk+2b−1
Let us substitute m with dy/dx where dx and dy are the differences between the end-points.
dx(dlower−dupper)=dx(2dydx(xk+1)−2yk+2b−1)dx(dlower−dupper)=dx(2dydx(xk+1)−2yk+2b−1)
=2dy.xk−2dx.yk+2dy+2dx(2b−1)=2dy. xk −2dx. yk +2dy+2dx(2b−1)
=2dy. xk −2dx. yk +C=2dy. xk −2dx.yk+C
So, a decision parameter Pk for the kth step along a line is given by −
Pk=dx(dlower−dupper) Pk =dx(dlower−dupper)
=2dy. xk −2dx.yk+C=2dy.xk−2dx.yk+C
The sign of the decision parameter Pk is the same as that of dlower−dupper’
If pk is negative, then choose the lower pixel, otherwise choose the upper pixel.
Remember, the coordinate changes occur along the x axis in unit steps, so you can do
everything with integer calculations. At step k+1, the decision parameter is given as −
pk+1=2dy.xk+1−2dx.yk+1+Cpk+1=2dy.xk+1−2dx.yk+1+C
Subtracting pk from this we get −
Pk+1=2dy(x k+1−xk)− 2dx.(yk+1−yk)pk+1−pk=2dy(xk+1− xk)−2dx(yk+1−yk)
But, xk+1xk+1 is the same as (xk)+1(xk)+1. So −
Pk+1=pk+2dy−2dx(yk+1−yk)pk+1=pk+2dy−2dx(yk+1 −yk)
Where, yk+1−yk is either 0 or 1 depending on the sign of pk.
The first decision parameter p0p0 is evaluated at (x0,y0)(x0,y0) is given as −
P0=2dy−dxp0=2dy−dx
Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm
for slope m < 1 −
Step 1 − Input the two end-points of line, storing the left end-point in (x0,y0)(x0,y0).
Step 2 − Plot the point (x0,y0)(x0,y0).
Step 3 − Calculate the constants dx, dy, 2dy, and 2dy–2dx2dy–2dx and get the first value for
the decision parameter as −
p0=2dy−dxp0=2dy−dx
Step 4 − At each XkXk along the line, starting at k = 0, perform the following test −
If pk < 0, the next point to plot is (xk+1,yk) and
pk+1 = pk +2dy pk+1 = pk +2dy
Otherwise, s
pk+1 = pk +2dy−2dx pk+1 =pk+2dy−2dx
Step 5 − Repeat step 4 dx–1dx–1 times.
For m > 1, find out whether you need to increment x while incrementing y each time.
After solving, the equation for decision parameter PkPk will be very similar, just the x and y in
the equation gets interchanged.
Properties of a Circle
Defining a Circle:
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 P 1(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.
There are two standards methods of mathematically defining a circle centered at the origin.
1. Defining a circle using Polynomial Method
2. Defining a circle using Polar Co-ordinates

Circle Drawing algorithm


Drawing a circle on the screen is a little complex than drawing a line. There are two popular
algorithms for generating a circle − Bresenham’s Algorithm and Midpoint Circle Algorithm.
These algorithms are based on the idea of determining the subsequent points required to draw
the circle. Let us discuss the algorithms in detail −
The equation of circle is X2+Y2=r2,X2+Y2=r2, where r is radius.
Bresenham’s Algorithm
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,YX,Y location and
now need to decide where to put the next pixel − at N X+1,YX+1,Y or at S X+1,Y−1X+1,Y−1.

This can be decided by the decision parameter d.


 If d <= 0, then NX+1,YX+1,Y is to be chosen as next pixel.
 If d > 0, then SX+1,Y−1X+1,Y−1 is to be chosen as the next pixel.
Algorithm
Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y, and R
respectively. Set P=0 and Q=R.
Step 2 − Set decision parameter D = 3 – 2R.
Step 3 − Repeat through step-8 while P ≤ Q.
Step 4 − Call Draw Circle X,Y,P,QX,Y,P,Q.
Step 5 − Increment the value of P.
Step 6 − If D < 0 then D = D + 4P + 6.
Step 7 − Else Set R = R - 1, D = D + 4P−QP−Q + 10.
Step 8 − Call Draw Circle X,Y,P,QX,Y,P,Q.
Draw Circle Method(X, Y, P, Q).

Call Putpixel (X + P, Y + Q).


Call Putpixel (X - P, Y + Q).
Call Putpixel (X + P, Y - Q).
Call Putpixel (X - P, Y - Q).
Call Putpixel (X + Q, Y + P).
Call Putpixel (X - Q, Y + P).
Call Putpixel (X + Q, Y - P).
Call Putpixel (X - Q, Y - P).

Mid Point Circle Algorithm


Step 1 − Input radius r and circle center (xc,yc)(xc,yc) and obtain the first point on the
circumference of the circle centered on the origin as
(x0, y0) = (0, r)
Step 2 − Calculate the initial value of decision parameter as
P0P0 = 5/4 –
r Seethefollowingdescriptionforsimplificationofthisequation.Seethefollowingdescriptionforsimp
lificationofthisequation.
f(x, y) = x2 + y2 - r2 = 0

f(xi - 1/2 + e, yi + 1)
= (xi - 1/2 + e)2 + (yi + 1)2 - r2
= (xi- 1/2)2 + (yi + 1)2 - r2 + 2(xi - 1/2)e + e2
= f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0
Let di = f(xi - 1/2, yi + 1) = -2(xi - 1/2)e - e2
Thus,

If e < 0 then di > 0 so choose point S = (xi - 1, yi + 1).


di+1 = f(xi - 1 - 1/2, yi + 1 + 1) = ((xi - 1/2) - 1)2 + ((yi + 1) + 1)2 - r2
= di - 2(xi - 1) + 2(yi + 1) + 1
= di + 2(yi + 1 - xi + 1) + 1

If e >= 0 then di <= 0 so choose point T = (xi, yi + 1)


di+1 = f(xi - 1/2, yi + 1 + 1)
= di + 2yi+1 + 1

The initial value of di is


d0 = f(r - 1/2, 0 + 1) = (r - 1/2)2 + 12 - r2
= 5/4 - r {1-r can be used if r is an integer}

When point S = (xi - 1, yi + 1) is chosen then


di+1 = di + -2xi+1 + 2yi+1 + 1

When point T = (xi, yi + 1) is chosen then


di+1 = di + 2yi+1 + 1
Step 3 − At each XKXK position starting at K=0, perform the following test −
If PK < 0 then next point on circle (0,0) is (XK+1,YK) and
PK+1 = PK + 2XK+1 + 1
Else
PK+1 = PK + 2XK+1 + 1 – 2YK+1

Where, 2XK+1 = 2XK+2 and 2YK+1 = 2YK-2.


Step 4 − Determine the symmetry points in other seven octants.
Step 5 − Move each calculate pixel position X,YX,Y onto the circular path centered
on (XC,YC)(XC,YC) and plot the coordinate values.
X = X + XC, Y = Y + YC
Step 6 − Repeat step-3 through 5 until X >= Y.

Filled Area primitives

Filled Area Primitives: Area filling is a method or process that helps us to fill an object, area, or
image. We can easily fill the polygon. The polygon filling is defined as filling or highlighting all
the pixels. The pixels appear inside the polygon shape with any color other than the background
color.
There are two algorithms or methods used to fill the polygon.
 Seed Fill Algorithm
 Scan Line Algorithm
Seed Fill Algorithm
In this method, we will select a seed or starting point inside the boundary. We can further divide
the seed fill into two parts.

1. Flood-fill Algorithm
2. Boundary-fill Algorithm
Flood-fill Algorithm
Flood-fill algorithm helps to define a region in the boundary, attached to a point in the multi-
dimensional array. It is similar to the bucket tool used in the paint program. The stack-based
recursive function is used to implement the algorithm. In flood -fill algorithm, we replace all the
associated pixels of the selected color with a fill color. We also check the pixels for a particular
interior color, not for boundary color.
Algorithm of Flood-fill
Procedure flood_fill (p, q, fill_color, Old_color: Integer)
Var
Current: Integer
Current = getpixel (p, q)
If
(Current = Old_color)
Then
Start
setpixel (p, q, fill_color);
flood_fill (p, q+1, fill_color, Old_color);
flood_fill (p, q-1, fill_color, Old_color);
flood_fill (p+1, q, fill_color, Old_color);
flood_fill (p-1, q, fill_color, Old_color);
End;
Note- Getpixel () defines the color of specified pixel.
Setpixel () set the pixel with the specified color.

Advantages of Flood-fill algorithm


 It provides an easy way to fill color in graphics.
 The Flood-fill algorithm colors the whole area through interconnected pixels by a single
color.
 The algorithm fills the same color inside the boundary.
Disadvantages of Flood-fill Algorithm
 It is a more time-consuming algorithm.
 Sometimes it does not work on large polygons.
Boundary-fill Algorithm
It is also known as the “Edge-fill algorithm.” The boundary fill algorithm is used for area
filling. We can perform boundary fill where we want to create an attractive painting. In this, we
can easily select the interior points. If the object has a particular boundary in a single color, then
the algorithm travels each pixel until it reaches the boundary.
In the Boundary-fill algorithm, we use the 4-connected and 8-connected methods. By the use of
a 4-connected or 8-connected method, we can set the new position of the pixels until all the
interior points have been filled.

Algorithm of Boundary-fill
Procedure boundary fill (p, q, fill color, boundary)
Step 1: Initialize the boundary of the region.
Step 2: Get the interior pixel (p, q). Now, define an Integer called current pixel and assign it to
(p, q).
Current = getpixel (p, q)
Step 3: If
(current pixel != boundary) and (current pixel != fill)
Then
Setpixel(p, q, fill);
Boundary fill (p+1, q, fill, boundary);
Boundary fill (p-1, q, fill, boundary);
Boundary fill (p, q+1, fill, boundary);
Boundary fill (p, q-1, fill, boundary);
Step 4: End;
Problems with Boundary-fill algorithm
 Sometimes it may not fill all the regions.
 In the 4-connected method, it does not fill corner pixels. Because it only checks the
adjacent position of the pixel.
Scan-Line Algorithm
The Scan-Line Algorithm is an area filling algorithm. In this algorithm, we can fill the polygons
through horizontal lines or scan lines. The scan-line intersects the edges of the polygon, and the
polygon is filled between pairs of the intersection. The main purpose of this algorithm is to fill
color in the interior pixel
s of the polygon.
Special Cases of Polygon Vertices
There are two special cases of polygon vertices which are given below:
1. If both lines intersecting at the vertex lies on the same side of the scan line, then we will
consider it as two points.
2. If both lines intersecting at the vertex lies on the other side of the scan line, then we will
consider it as a single point only.
Algorithm of Scan line polygon-fill
Step 1: Find the intersection points of the scan line that have edges.
Step 2: Now sort the intersection points by increasing the x coordinate from left to right.
Step 3: Now, we perform the pairing of the intersection points and fill the color inside the pixel
pairs.

You might also like