Unit-1 CG
Unit-1 CG
Introduction
Computer is information processing machine. User needs to communicate with computer and the
computer graphics is one of the most effective and commonly used ways of communication with the
user.
It displays the information in the form of graphical objects such as pictures, charts, diagram and graphs.
Graphical objects convey more information in less time and easily understandable formats for example
statically graph shown in stock exchange.
In computer graphics picture or graphics objects are presented as a collection of discrete pixels.
We can control intensity and color of pixel which decide how picture look like.
The special procedure determines which pixel will provide the best approximation to the desired picture
or graphics object this process is known as Rasterization.
The process of representing continuous picture or graphics object as a collection of discrete pixels is
called Scan Conversion.
Display devices
Display devices are also known as output devices.
Most commonly used output device in a graphics system is a video monitor.
Cathode-ray-tubes
CPU
I/O Port
Display
buffer (Interaction (Display
memory data) command)
Keyboard Mouse
Vector scan display directly traces out only the desired lines on CRT.
If we want line between point p1 & p2 then we directly drive the beam deflection circuitry which focus
beam directly from point p1 to p2.
If we do not want to display line from p1 to p2 and just move then we can blank the beam as we move it.
To move the beam across the CRT, the information about both magnitude and direction is required. This
information is generated with the help of vector graphics generator.
Fig. 1.2 shows architecture of vector display. It consists of display controller, CPU, display buffer memory
and CRT.
Display controller is connected as an I/O peripheral to the CPU.
Display buffer stores computer produced display list or display program.
The Program contains point & line plotting commands with end point co-ordinates as well as character
plotting commands.
Display controller interprets command and sends digital and point co-ordinates to a vector generator.
Vector generator then converts the digital co-ordinate value to analog voltages for beam deflection
circuits that displace an electron beam which points on the CRT’s screen.
In this technique beam is deflected from end point to end point hence this techniques is also called
random scan.
We know as beam strikes phosphors coated screen it emits light but that light decays after few
milliseconds and therefore it is necessary to repeat through the display list to refresh the screen at least
30 times per second to avoid flicker.
As display buffer is used to store display list and used to refreshing, it is also called refresh buffer.
CPU
I/O Port
(Interaction (Display
data) command
)
Keyboard
Display controller
Mouse
00000000000000000
00000111111100000 CRT
00000000100000000 Video controller
T
00000000100000000
00000000100000000
Refresh buffer
Fig. 1.3 shows the architecture of Raster display. It consists of display controller, CPU, video controller,
refresh buffer, keyboard, mouse and CRT.
The display image is stored in the form of 1’s and 0’s in the refresh buffer.
The video controller reads this refresh buffer and produces the actual image on screen.
It will scan one line at a time from top to bottom & then back to the top.
Horizontal
Vertical OFF ON Retrace
Retrace
In this method the horizontal and vertical deflection signals are generated to move the beam all over the
screen in a pattern shown in fig. 1.4.
Here beam is swept back & forth from left to the right.
When beam is moved from left to right it is ON.
Electron Beam The electron beam is swept across the The electron beam is directed only to the
screen, one row at a time, from top to parts of screen where a picture is to be
bottom. drawn.
Resolution Its resolution is poor because raster Its resolution is good because this system
system in contrast produces zigzag produces smooth lines drawings because
lines that are plotted as discrete point CRT beam directly follows the line path.
sets.
Picture Definition Picture definition is stored as a set of Picture definition is stored as a set of line
intensity values for all screen points, drawing instructions in a display file.
called pixels in a refresh buffer area.
Realistic Display The capability of this system to store These systems are designed for line-
intensity values for pixel makes it well drawing and can’t display realistic shaded
suited for the realistic display of scenes scenes.
contain shadow and color pattern.
Draw an Image Screen points/pixels are used to draw Mathematical functions are used to draw
an image. an image.
Beam-penetration technique
Shadow-mask technique
Advantage of DVST
Refreshing of CRT is not required.
Very complex pictures can be displayed at very high resolution without flicker.
Flat screen.
Disadvantage of DVST
They do not display color and are available with single level of line intensity.
For erasing it is necessary to removal of charge on the storage grid so erasing and redrawing process
take several second.
Erasing selective part of the screen cannot be possible.
Cannot used for dynamic graphics application as on erasing it produce unpleasant flash over entire
screen.
It has poor contrast as a result of the comparatively low accelerating potential applied to the flood
electrons.
The performance of DVST is somewhat inferior to the refresh CRT.
It is similar to plasma panel display but region between the glass plates is filled with phosphors such as
zinksulphide doped with magnesium instead of gas.
When sufficient voltage is applied the phosphors becomes a conductor in area of intersection of the two
electrodes.
Electrical energy is then absorbed by the manganese atoms which then release the energy as a spot of
light similar to the glowing plasma effect in plasma panel.
It requires more power than plasma panel.
In this good color and gray scale difficult to achieve.
Fig. 1.10: - Light twisting shutter effect used in design of most LCD.
It is generally used in small system such as calculator and portable laptop.
This non emissive device produce picture by passing polarized light from the surrounding or from an
internal light source through liquid crystal material that can be aligned to either block or transmit the
light.
The liquid crystal refreshes to fact that these compounds have crystalline arrangement of molecules
then also flows like liquid.
It consists of two glass plates each with light polarizer at right angles to each other sandwich the liquid
crystal material between the plates.
Rows of horizontal transparent conductors are built into one glass plate, and column of vertical
conductors are put into the other plates.
The intersection of two conductors defines a pixel position.
In the ON state polarized light passing through material is twisted so that it will pass through the
opposite polarizer.
In the OFF state it will reflect back towards source.
We applied a voltage to the two intersecting conductor to align the molecules so that the light is not
twisted.
This type of flat panel device is referred to as a passive matrix LCD.
In active matrix LCD transistors are used at each (x, y) grid point.
CRT
Viewer
Vibrating mirror changes its focal length due to vibration which is synchronized with the display of an
object on CRT.
The each point on the object is reflected from the mirror into spatial position corresponding to distance
of that point from a viewing position.
Very good example of this system is GENISCO SPACE GRAPH system, which use vibrating mirror to
project 3D objects into a 25 cm by 25 cm by 25 cm volume. This system is also capable to show 2D cross
section at different depth.
Stereoscopic system
Stereoscopic views does not produce three dimensional images, but it produce 3D effects by presenting
different view to each eye of an observer so that it appears to have depth.
To obtain this we first need to obtain two views of object generated from viewing direction
corresponding to each eye.
We can construct the two views as computer generated scenes with different viewing positions or we
can use stereo camera pair to photograph some object or scene.
When we see simultaneously both the view as left view with left eye and right view with right eye then
two views is merge and produce image which appears to have depth.
One way to produce stereoscopic effect is to display each of the two views with raster system on
alternate refresh cycles.
The screen is viewed through glasses with each lance design such a way that it act as a rapidly
alternating shutter that is synchronized to block out one of the views.
Virtual-reality
Virtual reality is the system which produce images in such a way that we feel that our surrounding is
what we are set in display devices but in actually it does not.
In virtual reality user can step into a scene and interact with the environment.
System Bus
I/O Devices
Raster graphics systems having additional processing unit like video controller or display controller.
Here frame buffer can be anywhere in the system memory and video controller access this for refresh
the screen.
In addition to video controller more processors are used as co-processors to accelerate the system in
sophisticated raster system.
Raster graphics system with a fixed portion of the system memory reserved for
the frame buffer
System bus
I/O Devices
Fig. 1.15: - Architecture of a raster graphics system with a fixed portion of the system memory reserved for
the frame buffer.
X Y
register register
Frame Buffer
Two registers are used to store the coordinates of the screen pixels which are X and Y
Initially the X is set to 0 and Y is set to Ymax.
The value stored in frame buffer for this pixel is retrieved and used to set the intensity of the CRT beam.
After this X register is incremented by one.
This procedure is repeated till X becomes equals to Xmax.
Then X is set to 0 and Y is decremented by one pixel and repeat above procedure.
This whole procedure is repeated till Y is become equals to 0 and complete the one refresh cycle. Then
controller reset the register as top –left corner i.e. X=0 and Y=Ymax and refresh process start for next
refresh cycle.
Since screen must be refreshed at the rate of 60 frames per second the simple procedure illustrated in
figure cannot be accommodated by typical RAM chips.
To speed up pixel processing video controller retrieves multiple values at a time using more numbers of
registers and simultaneously refresh block of pixel.
Such a way it can speed up and accommodate refresh rate more than 60 frames per second.
System Bus
I/O Devices
System Bus
I/O Devices
An application program is input & stored in the system memory along with a graphics package.
Graphics commands in the application program are translated by the graphics package into a display file
stored in the system memory.
This display file is used by display processor to refresh the screen.
Display process goes through each command in display file. Once during every refresh cycle.
Sometimes the display processor in random scan system is also known as display processing unit or a
graphics controller.
In this system graphics platform are drawn on random scan system by directing the electron beam along
the component times of the picture.
Lines are defined by coordinate end points.
This input coordinate values are converts to X and Y deflection voltages.
A scene is then drawn one line at a time.
Keyboards
Keyboards are used as entering text strings. It is efficient devices for inputting such a non-graphics data
as picture label.
Cursor control key’s & function keys are common features on general purpose keyboards.
Many other application of key board which we are using daily used of computer graphics are
commanding & controlling through keyboard etc.
Mouse
Mouse is small size hand-held box used to position screen cursor.
Wheel or roller or optical sensor is directing pointer on the according to movement of mouse.
Three buttons are placed on the top of the mouse for signaling the execution of some operation.
Now a day’s more advance mouse is available which are very useful in graphics application for example Z
mouse.
Joysticks
A joy stick consists of small vertical lever mounted on a base that is used to steer the screen cursor
around.
Most joy sticks selects screen positioning according to actual movement of stick (lever).
Some joy sticks are works on pressure applied on sticks.
Sometimes joy stick mounted on keyboard or sometimes used alone.
Movement of the stick defines the movement of the cursor.
In pressure sensitive stick pressure applied on stick decides movement of the cursor. This pressure is
measured using strain gauge.
This pressure sensitive joy sticks also called as isometric joy sticks and they are non movable sticks.
Data glove
Data glove is used to grasp virtual objects.
The glow is constructed with series of sensors that detect hand and figure motions.
Electromagnetic coupling is used between transmitter and receiver antennas which used to provide
position and orientation of the hand.
Transmitter & receiver Antenna can be structured as a set of three mutually perpendicular coils forming
3D Cartesian coordinates system.
Input from the glove can be used to position or manipulate object in a virtual scene.
Digitizer
Digitizer is common device for drawing painting or interactively selecting coordinates position on an
object.
One type of digitizers is graphics tablet which input two dimensional coordinates by activating hand
cursor or stylus at selected position on a flat surface.
Stylus is flat pencil shaped device that is pointed at the position on the tablet.
Image Scanner
Image Scanner scan drawing, graph, color, & black and white photos or text and can stored for computer
processing by passing an optical scanning mechanism over the information to be stored.
Once we have internal representation of a picture we can apply transformation.
We can also apply various image processing methods to modify the picture.
For scanned text we can apply modification operation.
Touch Panels
As name suggest Touch Panels allow displaying objects or screen-position to be selected with the touch
or finger.
A typical application is selecting processing option shown in graphical icons.
Prof. Vijay M. Shekhat, CE Department | 2160703 – Computer Graphics 17
Unit-1 – Basics of Computer Graphics
Some system such as a plasma panel are designed with touch screen
Other system can be adapted for touch input by fitting transparent touch sensing mechanism over a
screen.
Touch input can be recorded with following methods.
1. Optical methods
2. Electrical methods
3. Acoustical methods
Optical method
Optical touch panel employ a line of infrared LEDs along one vertical and one horizontal edge.
The opposite edges of the edges containing LEDs are contain light detectors.
When we touch at a particular position the line of light path breaks and according to that breaking line
coordinate values are measured.
In case two line cuts it will take average of both pixel positions.
LEDs operate at infrared frequency so it cannot be visible to user.
Electrical method
An electrical touch panel is constructed with two transparent plates separated by small distance.
One is coated with conducting material and other is coated with resistive material.
When outer plate is touch it will come into contact with internal plate.
When both plates touch it creates voltage drop across the resistive plate that is converted into
coordinate values of the selected position.
Acoustical method
In acoustical touch panel high frequency sound waves are generated in horizontal and vertical direction
across a glass plates.
When we touch the screen the waves from that line are reflected from finger.
These reflected waves reach again at transmitter position and time difference between sending and
receiving is measure and converted into coordinate values.
Light pens
Light pens are pencil-shaped device used to select positions by detecting light coming from points on the
CRT screen.
Activated light pens pointed at a spot on the screen as the electron beam lights up that spot and
generate electronic pulse that causes the coordinate position of the electron beam to be recorded.
Voice systems
It is used to accept voice command in some graphics workstations.
It is used to initiate graphics operations.
It will match input against predefined directory of words and phrases.
Dictionary is setup for a particular operator by recording his voice.
Each word is speak several times and then analyze the word and establishes a frequency pattern for that
word along with corresponding function need to be performed.
When operator speaks command it will match with predefine dictionary and perform desired action.
A general programming package provides an extensive set of graphics function that can be used in high
level programming language such as C or FORTRAN.
It includes basic drawing element shape like line, curves, polygon, color of element transformation etc.
Example: - GL (Graphics Library).
Special-purpose application package are customize for particular application which implement required
facility and provides interface so that user need not to vory about how it will work (programming). User
can simply use it by interfacing with application.
Example: - CAD, medical and business systems.
Coordinate representations
Except few all other general packages are designed to be used with Cartesian coordinate specifications.
If coordinate values for a picture are specified is some other reference frame they must be converted to
Cartesian coordinate before giving input to graphics package.
Special-purpose package may allow use of other coordinates which suits application.
In general several different Cartesian reference frames are used to construct and display scene.
We can construct shape of object with separate coordinate system called modeling coordinates or
sometimes local coordinates or master coordinates.
Once individual object shapes have been specified we can place the objects into appropriate positions
called world coordinates.
Finally the World-coordinates description of the scene is transferred to one or more output device
reference frame for display. These display coordinates system are referred to as “Device Coordinates” or
“Screen Coordinates”.
Generally a graphic system first converts the world-coordinates position to normalized device
coordinates. In the range from 0 to 1 before final conversion to specific device coordinates.
An initial modeling coordinates position ( Xmc,Ymc) in this illustration is transferred to a device
coordinates position(Xdc,Ydc) with the sequence ( Xmc,Ymc) ( Xwc,Ywc) ( Xnc,Ync) ( Xdc,Ydc).
Graphic Function
A general purpose graphics package provides user with Varity of function for creating and manipulating
pictures.
The basic building blocks for pictures are referred to as output primitives. They includes character,
string, and geometry entities such as point, straight lines, curved lines, filled areas and shapes defined
with arrays of color points.
Input functions are used for control & process the various input device such as mouse, tablet, etc.
Control operations are used to controlling and housekeeping tasks such as clearing display screen etc.
All such inbuilt function which we can use for our purpose are known as graphics function
This system was adopted as a first graphics software standard by the international standard organization
(ISO) and various national standard organizations including ANSI.
GKS was originally designed as the two dimensional graphics package and then later extension was
developed for three dimensions.
PHIGS is extension of GKS. Increased capability for object modeling, color specifications, surface
rendering, and picture manipulation are provided in PHIGS.
Extension of PHIGS called “PHIGS+” was developed to provide three dimensional surface shading
capabilities not available in PHIGS.
Fig. 2.1: - Stair step effect produced when line is generated as a series of pixel positions.
The stair step shape is noticeable in low resolution system, and we can improve their appearance
somewhat by displaying them on high resolution system.
More effective techniques for smoothing raster lines are based on adjusting pixel intensities along the
line paths.
For raster graphics device-level algorithms discuss here, object positions are specified directly in integer
device coordinates.
Pixel position will referenced according to scan-line number and column number which is illustrated by
following figure.
6
5
4
3
2
1
0
0 1 2 3 4 5 6
Fig. 2.2: - Pixel positions referenced by scan-line number and column number.
To load the specified color into the frame buffer at a particular position, we will assume we have
available low-level procedure of the form 𝑠𝑒𝑡𝑝𝑖𝑥𝑒𝑙(𝑥, 𝑦).
Y2
y1
X1 X2
DDA Algorithm
Digital differential analyzer (DDA) is scan conversion line drawing algorithm based on calculating either
∆𝑦 or ∆𝑥 using above equation.
We sample the line at unit intervals in one coordinate and find corresponding integer values nearest the
line path for the other coordinate.
Consider first a line with positive slope and slope is less than or equal to 1:
We sample at unit x interval (∆𝑥 = 1) and calculate each successive y value as follow:
𝑦 = 𝑚 ∗ 𝑥 + 𝑏
𝑦𝑘 = 𝑚 ∗ (𝑥 + 1) + 𝑏
In general 𝑦𝑘 = 𝑚 ∗ (𝑥 + 𝑘) + 𝑏 , &
𝑦𝑘+1 = 𝑚 ∗ (𝑥 + 𝑘 + 1) + 𝑏
Now write this equation in form:
𝑦𝑘+1 − 𝑦𝑘 = (𝑚 ∗ (𝑥 + 𝑘 + 1) + 𝑏) – (𝑚 ∗ (𝑥 + 𝑘) + 𝑏)
𝑦𝑘+1 = 𝑦𝑘 + 𝑚
So that it is computed fast in computer as addition is fast compare to multiplication.
Specified
13 50
line path
Specified
12 49
line path
11 48
10 47
10 11 12 13 14 15 50 51 52 53 54 55
Fig. 2.4: - Section of a display screen where a Fig. 2.5: - Section of a display screen where a
straight line segment is to be plotted, starting negative slope line segment is to be plotted,
from the pixel at column 10 on scan line 11. starting from the pixel at column 50 on scan
line 50.
The vertical axes show scan-line positions and the horizontal axes identify pixel column.
Sampling at unit 𝑥 intervals in these examples, we need to decide which of two possible pixel position is
closer to the line path at each sample step.
To illustrate bresenham’s approach, we first consider the scan-conversion process for lines with positive
slope less than 1.
Pixel positions along a line path are then determined by sampling at unit 𝑥 intervals.
Starting from left endpoint (𝑥0 , 𝑦0 ) of a given line, we step to each successive column and plot the pixel
whose scan-line 𝑦 values is closest to the line path.
Assuming we have determined that the pixel at (𝑥𝑘 , 𝑦𝑘 ) is to be displayed, we next need to decide which
pixel to plot in column 𝑥𝑘 + 1.
Our choices are the pixels at positions (𝑥𝑘 + 1, 𝑦𝑘 ) and (𝑥𝑘 + 1, 𝑦𝑘 + 1).
Let’s see mathematical calculation used to decide which pixel position is light up.
We know that equation of line is:
𝑦 = 𝑚𝑥 + 𝑏
Now for position 𝑥𝑘 + 1.
𝑦 = 𝑚(𝑥𝑘 + 1) + 𝑏
Now calculate distance bet actual line’s 𝑦 value and lower pixel as 𝑑1 and distance bet actual line’s 𝑦
value and upper pixel as 𝑑2 .
𝑑1 = 𝑦 − 𝑦𝑘
Prof. Vijay M. Shekhat, CE Department | 2160703 – Computer Graphics 4
Unit-2 – Graphics Primitives
d1 = m(xk + 1) + b − yk ……………………………………………………………………………………………………………..……...(1)
𝑑2 = (𝑦𝑘 + 1) − 𝑦
𝑑2 = (𝑦𝑘 + 1) − 𝑚(𝑥𝑘 + 1) − 𝑏..…………………………………………………………………………………………………………(2)
Now calculate 𝑑1 − 𝑑2 from equation (1) and (2).
𝑑1 − 𝑑2 = (𝑦 – 𝑦𝑘 ) – ((𝑦𝑘 + 1) – 𝑦)
𝑑1 − 𝑑2 = {𝑚(𝑥𝑘 + 1) + 𝑏 − 𝑦𝑘 } − {(𝑦𝑘 + 1) − 𝑚(𝑥𝑘 + 1) − 𝑏}
𝑑1 − 𝑑2 = {𝑚𝑥𝑘 + 𝑚 + 𝑏 − 𝑦𝑘 } − {𝑦𝑘 + 1 − 𝑚𝑥𝑘 − 𝑚 − 𝑏}
𝑑1 − 𝑑2 = 2𝑚(𝑥𝑘 + 1) − 2𝑦𝑘 + 2𝑏 − 1……………………………………………………………………………….……………..(3)
Now substitute 𝑚 = ∆𝑦/∆𝑥 in equation (3)
∆𝑦
𝑑1 − 𝑑2 = 2 (∆𝑥 ) (𝑥𝑘 + 1) − 2𝑦𝑘 + 2𝑏 − 1 ….………………………………….………………………………………………….(4)
Now we have decision parameter 𝑝𝑘 for 𝑘 𝑡ℎ step in the line algorithm is given by:
𝑝𝑘 = ∆𝑥(𝑑1 − 𝑑2 )
𝑝𝑘 = ∆𝑥(2∆𝑦/∆𝑥(𝑥𝑘 + 1) – 2𝑦𝑘 + 2𝑏 – 1)
𝑝𝑘 = 2∆𝑦𝑥𝑘 + 2∆𝑦 − 2∆𝑥𝑦𝑘 + 2∆𝑥𝑏 − ∆𝑥
𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆𝑥 ……………………………………………………….………………………(5)
𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 𝐶 (𝑊ℎ𝑒𝑟𝑒 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝐶 = 2∆𝑦 + 2∆𝑥𝑏 − ∆𝑥)…………………….……………...(6)
The sign of 𝑝𝑘 is the same as the sign of 𝑑1 − 𝑑2 , since ∆𝑥 > 0 for our example.
Parameter 𝑐 is constant which is independent of pixel position and will eliminate in the recursive
calculation for 𝑝𝑘 .
Now if 𝑝𝑘 is negative then we plot the lower pixel otherwise we plot the upper pixel.
So successive decision parameters using incremental integer calculation as:
𝑝𝑘+1 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + C
Now Subtract 𝑝𝑘 from 𝑝𝑘+1
𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦(𝑥𝑘+1 − 𝑥𝑘 ) -2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + 𝐶 − 2∆𝑦𝑥𝑘 + 2∆𝑥𝑦𝑘 − 𝐶
But 𝑥𝑘+1 = 𝑥𝑘 + 1, so that (𝑥𝑘+1 − 𝑥𝑘 ) = 1
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘 )
Where the terms 𝑦𝑘+1 − 𝑦𝑘 is either 0 or 1, depends on the sign of parameter 𝑝𝑘 .
This recursive calculation of decision parameters is performed at each integer 𝑥 position starting at the
left coordinate endpoint of the line.
The first decision parameter 𝑝0 is calculated using equation (5) as first time we need to take constant
part into account so:
𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆𝑥
𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑏 − ∆𝑥
Now 𝑆𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑒 𝑏 = 𝑦0 – 𝑚𝑥0
𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥(𝑦0 − 𝑚𝑥0 ) − ∆𝑥
Now Substitute 𝑚 = ∆𝑦/𝛥𝑥
𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥(𝑦0 − (∆𝑦/∆𝑥)𝑥0 ) − ∆x
𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑦0 − 2∆𝑦𝑥0 − ∆𝑥
𝑝0 = 2∆𝑦 − ∆𝑥
Let’s see Bresenham’s line drawing algorithm for |𝑚| < 1
1. Input the two line endpoints and store the left endpoint in (𝑥0 , 𝑦0 ).
2. Load (𝑥0 , 𝑦0 ) into the frame buffer; that is, plot the first point.
3. Calculate constants ∆𝑥, ∆𝑦, 2∆𝑦, and 2∆𝑦 − 2∆𝑥, and obtain the starting value for the decision
parameter as
Y2
Δy
Y1
Δx
X1 X2
Fig. 2.6: - Bounding box for a line with coordinate extents ∆x and ∆y.
Another way to set up parallel algorithms on raster system is to assign each processor to a particular
group of screen pixels.
With sufficient number of processor we can assign each processor to one pixel within some screen
region.
This approach can be adapted to line display by assigning one processor to each of the pixels within the
limit of the bounding rectangle and calculating pixel distance from the line path.
The number of pixels within the bounding rectangle of a line is ∆𝑥 × ∆𝑦.
Perpendicular distance 𝑑 from line to a particular pixel is calculated by:
𝑑 = 𝐴𝑥 + 𝐵𝑦 + 𝐶
Where
𝐴 = −∆𝑦/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
𝐵 = −∆𝑥/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
𝐶 = (𝑥0 ∆𝑦 − 𝑦0 ∆𝑥)/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
With
𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ = √∆𝑥 2 + ∆𝑦 2
Once the constant 𝐴, 𝐵, and 𝐶 have been evaluated for the line each processors need to perform two
multiplications and two additions to compute the pixel distance 𝑑.
A pixel is plotted if d is less than a specified line thickness parameter.
Instead of partitioning the screen into single pixels, we can assign to each processor either a scan line or
a column a column of pixels depending on the line slope.
Circle
Yc
Xc
Properties of Circle
The distance relationship is expressed by the Pythagorean theorem in Cartesian coordinates as:
(𝑥 − 𝑥𝑐 )2 + (𝑦 − 𝑦𝑐 )2 = 𝑟 2
We could use this equation to calculate circular boundary points by incrementing 1 in 𝑥 direction in
every steps from 𝑥𝑐 – 𝑟 to 𝑥𝑐 + 𝑟 and calculate corresponding 𝑦 values at each position as:
(𝑥 − 𝑥𝑐 )2 + (𝑦 − 𝑦𝑐 )2 = 𝑟 2
(𝑦 − 𝑦𝑐 )2 = 𝑟 2 − (𝑥 − 𝑥𝑐 )2
𝑦 = 𝑦𝑐 ± √𝑟 2 − (𝑥𝑐 − 𝑥)2
But this is not best method for generating a circle because it requires more number of calculations which
take more time to execute.
And also spacing between the plotted pixel positions is not uniform as shown in figure below.
Fig. 2.8: - Positive half of circle showing non uniform spacing bet calculated pixel positions.
(-Y, X) (Y, X)
45O
(-X, Y)
(X, Y)
𝒙𝟐 + 𝒚𝟐 − 𝒓𝟐 = 𝟎
𝒚𝒌 Midpoint
𝒚𝒌 − 𝟏
𝒙𝒌 𝒙𝒌 + 𝟏 𝒙𝒌 + 𝟐
Fig. 2.10: - Midpoint between candidate pixel at sampling position 𝑥𝑘 + 1 along circle path.
Assuming we have just plotted the pixel at (𝑥𝑘 , 𝑦𝑘 ) and next we need to determine whether the pixel at
position ‘(𝑥𝑘 + 1, 𝑦𝑘 )’ or the one at position’ (𝑥𝑘 + 1, 𝑦𝑘 − 1)’ is closer to circle boundary.
So for finding which pixel is more closer using decision parameter evaluated at the midpoint between
two candidate pixels as below:
1
𝑝𝑘 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥𝑘 + 1, 𝑦𝑘 − 2)
1 2
𝑝𝑘 = (𝑥𝑘 + 1)2 + (𝑦𝑘 − 2) − 𝑟 2
If 𝑝𝑘 < 0 this midpoint is inside the circle and the pixel on the scan line 𝑦𝑘 is closer to circle boundary.
Otherwise the midpoint is outside or on the boundary and we select the scan line 𝑦𝑘 − 1.
Successive decision parameters are obtain using incremental calculations as follows:
Ellipse
Properties of Ellipse
If we labeled distance from two foci to any point on ellipse boundary as 𝑑1 and 𝑑2 then the general
equation of an ellipse can be written as follow.
𝑑1 + 𝑑2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
Expressing distance in terms of focal coordinates 𝑓1 = (𝑥1 , 𝑦1 ) and 𝑓2 = (𝑥2 , 𝑦2 ) we have
√(𝑥 − 𝑥1 )2 + (𝑦 − 𝑦1 )2 + √(𝑥 − 𝑥2 )2 + (𝑦 − 𝑦2 )2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
An interactive method for specifying an ellipse in an arbitrary orientation is to input two foci and a point
on the ellipse boundary.
With this three coordinates we can evaluate constant in equation:
√(𝑥 − 𝑥1 )2 + (𝑦 − 𝑦1 )2 + √(𝑥 − 𝑥2 )2 + (𝑦 − 𝑦2 )2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
We can also write this equation in the form
𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0
Where the coefficients 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, and 𝐹 are evaluated in terms of the focal coordinates and the
dimensions of the major and minor axes of the ellipse.
Major axis of an ellipse is straight line segment passing through both foci and extends up to boundary on
both sides.
The minor axis spans shortest dimension of ellipse, it bisect the major axis at right angle in two equal
half.
Then coefficient in 𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0 can be evaluated and used to generate pixels
along the elliptical path.
Ellipse equation are greatly simplified if we align major and minor axis with coordinate axes i.e. 𝑥 − 𝑎𝑥𝑖𝑠
and 𝑦 − 𝑎𝑥𝑖𝑠.
We can say ellipse is in standard position if their major and minor axes are parallel to 𝑥 − 𝑎𝑥𝑖𝑠 and 𝑦 −
𝑎𝑥𝑖𝑠 which is shown in below figure.
Fig. 2.12: - Ellipse centered at (𝑥𝑐 , 𝑦𝑐 ) with semi major axis 𝑟𝑥 and semi minor axis 𝑟𝑦 are parallel to
coordinate axis.
Equation of ellipse shown in figure 2.12 can be written in terms of the ellipse center coordinates and
parameters 𝑟𝑥 and 𝑟𝑦 as.
2
𝑥 − 𝑥𝑐 2 𝑦 − 𝑦𝑐
( ) +( ) =1
𝑟𝑥 𝑟𝑦
Using the polar coordinates 𝑟 and 𝜃, we can also describe the ellipse in standard position with the
parametric equations:
𝑥 = 𝑥𝑐 + 𝑟𝑥 cos θ
𝑦 = 𝑦𝑐 + 𝑟𝑦 sin θ
Symmetry considerations can be used to further reduced computations.
An ellipse in standard position is symmetric between quadrants but unlike a circle it is not symmetric
between octant.
Thus we must calculate boundary point for one quadrant and then other three quadrants point can be
obtained by symmetry as shown in figure below.
(−𝑥, 𝑦) (𝑥, 𝑦)
𝑟𝑦
𝑟𝑥
(𝑥𝑐 , 𝑦𝑐 )
(−𝑥, − 𝑦) (𝑥, − 𝑦)
Fig. 2.14: - Ellipse processing regions. Over the region 1 the magnitude of ellipse slope is < 1 and over
the region 2 the magnitude of ellipse slope > 1.
We take unit step in 𝑥 direction if magnitude of slope is less than 1 in that region otherwise we take unit
step in 𝑦 direction.
Boundary divides region at 𝑠𝑙𝑜𝑝𝑒 = −1.
With 𝑟𝑥 < 𝑟𝑦 we process this quadrant by taking unit steps in 𝑥 direction in region 1 and unit steps in 𝑦
direction in region 2.
Region 1 and 2 can be processed in various ways.
We can start from (0, 𝑟𝑦 ) and step clockwise along the elliptical path in the first quadrant shifting from
unit step in 𝑥 to unit step in 𝑦 when slope becomes less than -1.
Alternatively, we could start at (𝑟𝑥 , 0) and select points in a counterclockwise order, shifting from unit
steps in 𝑦 to unit steps in 𝑥 when the slope becomes greater than -1.
With parallel processors, we could calculate pixel positions in the two regions simultaneously.
Here we consider sequential implementation of midpoint algorithm. We take the start position at (0, 𝑟𝑦 )
and steps along the elliptical path in clockwise order through the first quadrant.
We define ellipse function for center of ellipse at (0, 0) as follows.
𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) = 𝑟𝑦 2 𝑥 2 + 𝑟𝑥 2 𝑦 2 − 𝑟𝑦 2 𝑟𝑥 2
Which has the following properties:
< 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥, 𝑦) {= 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
Thus the ellipse function serves as the decision parameter in the midpoint ellipse algorithm.
At each sampling position we select the next pixel from two candidate pixel.
𝒓𝒚 𝟐 𝒙𝟐 + 𝒓𝒙 𝟐 𝒚𝟐 − 𝒓𝒙 𝟐 𝒓𝒚 𝟐 = 𝟎
𝒚𝒌 Midpoint
𝒚𝒌 − 𝟏
𝒙𝒌 𝒙𝒌 + 𝟏 𝒙𝒌 + 𝟐
Fig. 2.15: - Midpoint between candidate pixels at sampling position 𝑥𝑘 + 1 along an elliptical path.
Assume we are at (𝑥𝑘 , 𝑦𝑘 ) position and we determine the next position along the ellipse path by
evaluating decision parameter at midpoint between two candidate pixels.
1
𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘 + 1, 𝑦𝑘 − )
2
1 2
𝑝1𝑘 = 𝑟𝑦 2 (𝑥𝑘 + 1)2 + 𝑟𝑥 2 (𝑦𝑘 − ) − 𝑟𝑥 2 𝑟𝑦 2
2
If 𝑝1𝑘 < 0, the midpoint is inside the ellipse and the pixel on scan line 𝑦𝑘 is closer to ellipse boundary
otherwise the midpoint is outside or on the ellipse boundary and we select the pixel 𝑦𝑘 − 1.
At the next sampling position decision parameter for region 1 is evaluated as.
1
𝑝1𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘+1 + 1, 𝑦𝑘+1 − )
2
1 2
𝑝1𝑘+1 = 𝑟𝑦 2 [(𝑥𝑘 + 1) + 1]2 + 𝑟𝑥 2 (𝑦𝑘+1 − ) − 𝑟𝑥 2 𝑟𝑦 2
2
Now subtract 𝑝1𝑘 from 𝑝1𝑘+1
1 2 1 2
𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 2 [(𝑥𝑘 + 1) + 1]2 + 𝑟𝑥 2 (𝑦𝑘+1 − ) − 𝑟𝑥 2 𝑟𝑦 2 − 𝑟𝑦 2 (𝑥𝑘 + 1)2 − 𝑟𝑥 2 (𝑦𝑘 − )
2 2
+ 𝑟𝑥 2 𝑟𝑦 2
1 2 1 2
𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 2 [(𝑥𝑘 + 1) + 1]2 + 𝑟𝑥 2 (𝑦𝑘+1 − ) − 𝑟𝑦 2 (𝑥𝑘 + 1)2 − 𝑟𝑥 2 (𝑦𝑘 − )
2 2
2
1 1 2
𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 2 (𝑥𝑘 + 1)2 + 2𝑟𝑦 2 (𝑥𝑘 + 1) + 𝑟𝑦 2 + 𝑟𝑥 2 (𝑦𝑘+1 − ) − 𝑟𝑦 2 (𝑥𝑘 + 1)2 − 𝑟𝑥 2 (𝑦𝑘 − )
2 2
2 2
1 1
𝑝1𝑘+1 − 𝑝1𝑘 = 2𝑟𝑦 2 (𝑥𝑘 + 1) + 𝑟𝑦 2 + 𝑟𝑥 2 [(𝑦𝑘+1 − ) − (𝑦𝑘 − ) ]
2 2
Now making 𝑝1𝑘+1 as subject.
𝒓𝒚 𝟐 𝒙𝟐 + 𝒓𝒙 𝟐 𝒚𝟐 − 𝒓𝒙 𝟐 𝒓𝒚 𝟐 = 𝟎
𝒚𝒌 Midpoint
𝒚𝒌 − 𝟏
𝒙𝒌 𝒙𝒌 + 𝟏 𝒙𝒌 + 𝟐
Fig. 2.16: - Midpoint between candidate pixels at sampling position 𝑦𝑘 − 1 along an elliptical path.
For this region, the decision parameter is evaluated as follows.
1
𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘 + , 𝑦𝑘 − 1)
2
2
1
𝑝2𝑘 = 𝑟𝑦 2 (𝑥𝑘 + ) + 𝑟𝑥 2 (𝑦𝑘 − 1)2 − 𝑟𝑥 2 𝑟𝑦 2
2
If 𝑝2𝑘 > 0 the midpoint is outside the ellipse boundary, and we select the pixel at 𝑥𝑘 .
If 𝑝2𝑘 ≤ 0 the midpoint is inside or on the ellipse boundary and we select 𝑥𝑘 + 1.
At the next sampling position decision parameter for region 2 is evaluated as.
1
𝑝2𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥𝑘+1 + , 𝑦𝑘+1 − 1)
2
2
1
𝑝2𝑘+1 = 𝑟𝑦 2 (𝑥𝑘+1 + ) + 𝑟𝑥 2 [(𝑦𝑘 − 1) − 1]2 − 𝑟𝑥 2 𝑟𝑦 2
2
Now subtract 𝑝2𝑘 from 𝑝2𝑘+1
1 2 1 2
𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 2 (𝑥𝑘+1 + ) + 𝑟𝑥 2 [(𝑦𝑘 − 1) − 1]2 − 𝑟𝑥 2 𝑟𝑦 2 − 𝑟𝑦 2 (𝑥𝑘 + ) − 𝑟𝑥 2 (𝑦𝑘 − 1)2
2 2
2 2
+ 𝑟𝑥 𝑟𝑦
1 2 1 2
𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 2 (𝑥𝑘+1 + ) + 𝑟𝑥 2 (𝑦𝑘 − 1)2 − 2𝑟𝑥 2 (𝑦𝑘 − 1) + 𝑟𝑥 2 − 𝑟𝑦 2 (𝑥𝑘 + ) − 𝑟𝑥 2 (𝑦𝑘 − 1)2
2 2
2 2
1 1
𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 2 (𝑥𝑘+1 + ) − 2𝑟𝑥 2 (𝑦𝑘 − 1) + 𝑟𝑥 2 − 𝑟𝑦 2 (𝑥𝑘 + )
2 2
2
2 (𝑦 2 2
1 1 2
𝑝2𝑘+1 − 𝑝2𝑘 = −2𝑟𝑥 𝑘 − 1) + 𝑟𝑥 + 𝑟𝑦 [(𝑥𝑘+1 + ) − (𝑥𝑘 + ) ]
2 2
Now making 𝑝2𝑘+1 as subject.
1 2 1 2
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 (𝑦𝑘 − 1) + 𝑟𝑥 2 + 𝑟𝑦 2 [(𝑥𝑘+1 + ) − (𝑥𝑘 + ) ]
2 2
Prof. Vijay M. Shekhat, CE Department | 2160703 – Computer Graphics 16
Unit-2 – Graphics Primitives
Here 𝑥𝑘+1 is either 𝑥𝑘 or 𝑥𝑘 + 1, depends on the sign of 𝑝2𝑘 .
In region 2 initial position is selected which is last position of region one and the initial decision
parameter is calculated as follows.
1
𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 (𝑥0 + , 𝑦0 − 1)
2
2
1
𝑝20 = 𝑟𝑦 2 (𝑥0 + ) + 𝑟𝑥 2 (𝑦0 − 1)2 − 𝑟𝑥 2 𝑟𝑦 2
2
For simplify calculation of 𝑝20 we could select pixel position in counterclockwise order starting at (𝑟𝑥 , 0).
In above case we take unit step in the positive 𝑦 direction up to the last point selected in region 1.
If 𝑝1𝑘 < 0, the next point along the ellipse centered on (0, 0) is (𝑥𝑘+1 , 𝑦𝑘 ) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2
If 𝑝2𝑘 > 0, the next point along the ellipse centered on (0, 0) is (𝑥𝑘 , 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2
Otherwise, the next point along the ellipse is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2 + 2𝑟𝑦 2 𝑥𝑘+1
Using the same incremental calculations for 𝑥 and 𝑦 as in region 1.
6. Determine symmetry points in the other three quadrants.
7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on (𝑥𝑐 , 𝑦𝑐 ) and plot the
coordinate values:
𝑥 = 𝑥 + 𝑥𝑐
𝑦 = 𝑦 + 𝑦𝑐
Repeat the steps for region 2 until 𝑦𝑘 ≥ 0.
Filled-Area Primitives
In practical we often use polygon which are filled with some color or pattern inside it.
Prof. Vijay M. Shekhat, CE Department | 2160703 – Computer Graphics 17
Unit-2 – Graphics Primitives
There are two basic approaches to area filling on raster systems.
One way to fill an area is to determine the overlap intervals for scan line that cross the area.
Another method is to fill the area is to start from a given interior position and paint out wards from this
point until we encounter boundary.
Fig. 2.17: - Interior pixels along a scan line passing through a polygon area.
For each scan-line crossing a polygon, the algorithm locates the intersection points are of scan line with
the polygon edges.
This intersection points are stored from left to right.
Frame buffer positions between each pair of intersection point are set to specified fill color.
Some scan line intersects at vertex position they are required special handling.
For vertex we must look at the other endpoints of the two line segments of the polygon which meet at
this vertex.
If these points lie on the same (up or down) side of the scan line, then that point is counts as two
intersection points.
If they lie on opposite sides of the scan line, then the point is counted as single intersection.
This is illustrated in figure below
Fig. 2.18: - Intersection points along the scan line that intersect polygon vertices.
As shown in the Fig. 2.18, each scan line intersects the vertex or vertices of the polygon. For scan line 1,
the other end points (B and D) of the two line segments of the polygon lie on the same side of the scan
Decerement 0
4
Decerement 1
\
5
6
Decerement 2
6
3
Y0 0 Y0
X0 X0
∆𝑥
Fig. 2.19: - line with slope 7/3 and its integer calculation using equation 𝑥𝑘+1 = 𝑥𝑘 + .
∆𝑦
Steps for above procedure
1. Suppose m = 7/3
2. Initially, set counter to 0, and increment to 3 (which is 𝛥𝑥).
3. When move to next scan line, increment counter by adding ∆𝑥
4. When counter is equal or greater than 7 (which is 𝛥𝑦), increment the x-intercept (in other words, the 𝑥-
intercept for this scan line is one more than the previous scan line), and decrement counter by 7(which
is ∆𝑦).
To efficiently perform a polygon fill, we can first store the polygon boundary in a sorted edge table that
contains all the information necessary to process the scan lines efficiently.
We use bucket sort to store the edge sorted on the smallest 𝑦 value of each edge in the correct scan line
positions.
Only the non-horizontal edges are entered into the sorted edge table.
Figure below shows one example of storing edge table.
Yc Yb Xc 1/mcb
B
Yd Yc Xd 1/mdb Ye Xd 1/mde
C Scan Line Yc
Ya Yb Xc 1/mcb Yb Xa 1/mab
C’ E
.
Scan Line Yd .
.
1
Scan Line Ya D
0
A
Inside-Outside Tests
In area filling and other graphics operation often required to find particular point is inside or outside the
polygon.
For finding which region is inside or which region is outside most graphics package use either odd even
rule or the nonzero winding number rule.
Fig. 2.21: - Identifying interior and exterior region for a self-intersecting polygon.
Seed
2
(a)
1
2
(b)
1
3
5 6
6
4
(c) 5
1
4
1
4
(d) 5
1
4
Fig. 2.24: - Boundary fill across pixel spans for a 4-connected area.
Flood-Fill Algorithm
Sometimes it is required to fill in an area that is not defined within a single color boundary.
In such cases we can fill areas by replacing a specified interior color instead of searching for a boundary
color.
This approach is called a flood-fill algorithm. Like boundary fill algorithm, here we start with some seed
and examine the neighbouring pixels.
However, here pixels are checked for a specified interior color instead of boundary color and they are
replaced by new color.
Using either a 4-connected or 8-connected approach, we can step through pixel positions until all
interior point have been filled.
The following procedure illustrates the recursive method for filling 4-connected region using flood-fill
algorithm.
Procedure :
flood-fill4(x, y, new-color, old-color)
{
if(getpixel (x,y) = = old-color)
{
putpixel (x, y, new-color)
flood-fill4 (x + 1, y, new-color, old -color);
flood-fill4 (x, y + 1, new -color, old -color);
flood-fill4 (x - 1, y, new -color, old -color);
flood-fill4 (x, y - l, new -color, old-color);
}
}
Note: 'getpixel' function gives the color of .specified pixel and 'putpixel' function draws the pixel with
specified color.
Character Generation
We can display letters and numbers in variety of size and style.
The overall design style for the set of character is called typeface.
Today large numbers of typefaces are available for computer application for example Helvetica, New
York platino etc.
Originally, the term font referred to a set of cast metal character forms in a particular size and format,
such as 10-point Courier Italic or 12- point Palatino Bold. Now, the terms font and typeface are often
used interchangeably, since printing is no longer done with cast metal forms.
Two different representations are used for storing computer fonts.
Outline Font
In this method character is generated using curve section and straight line as combine assembly.
Figure below shows how it is generated.