CGR Map W22
CGR Map W22
CGR Map W22
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2022 EXAMINATION
Subject Name: Computer Graphics Model Answer Subject Code: 22318
Important Instructions to examiners: XXXXX
1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures
drawn by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and
there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on
candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual (English +
Marathi) medium is introduced at first year of AICTE diploma Programme from academic year 2021-2022. Hence
if the students in first year (first and second semesters) write answers in Marathi or bilingual language (English
+Marathi), the Examiner shall consider the same and assess the answer based on matching of concepts with model
answer.
Ans Pixel: Pixel or Pel is defined as "The smallest addressable screen element". 1 M for
OR Pixel and 1
A pixel may be defined as the smallest size object or color spot that can be displayed and M for
addressed on a monitor. Resolution
Resolution: Resolution is the number of rows that appear from top to bottom of a screen
and in turn the number of pixels or pixel elements that appear from left to right on each
scanline.
b) Explain basic graphic pipeline. 2M
Ans A graphics pipeline can be divided into three main parts: Application, Geometry and Explanation-
Rasterization. 2M
The Application step is executed by the software on the main processor (CPU), it cannot be
divided into individual steps, which are executed in a pipelined manner.
Page No: 1 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The Geometry step (with Geometry pipeline), which is responsible for the majority of the
operations with polygons and their vertices (with Vertex pipeline), can be divided into the
following five tasks.
The Rasterization step is the task of taking an image described in a vector graphics format
(shapes) and converting it into a raster image (pixels or dots) for output on a video display or
printer, or for storage in a bitmap file format.
c) State different line drawing algorithms. 2M
Ans Scaling: Scaling is a process used for altering the size of objects. It changes the coordinate 1 M Scaling,
point of the original object. Modifying the object’s size with the help of the object’s
dimension is dependent on the scaling factor(S). 1M
Reflection
Reflection: Reflection is a transformation which produces a mirror image of an object. The
mirror image can be either about x-axis or y-axis. The object is rotated by180°.
f) Enlist different methods of line clipping. 2M
Ans Fractals are very complex pictures generated by a computer from a single formula. They are Correct
created using iterations. This means one formula is repeated with slightly different values definition 2
over and over again, taking into account the results from the previous iteration. M
Ans 1) Cathode-Ray Tube (CRT): Here, CRT stands for Cathode ray tube. It is a technology Any Two
which is used in traditional computer monitor and television. devices-2 M
each
Cathode ray tube is a particular type of vacuum tube that displays images when an electron
beam collides on the radiant surface.
Page No: 2 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
OR
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:
2) 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:
Page No: 3 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
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.
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.
5) 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.
6) 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)
Page No: 5 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
7) 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.
8) 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.
9) 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.
Page No: 6 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
b) Explain and write steps for DDA line drawing algorithm. 4M
Ans This algorithm generates a line from differential equations of line and hence the name DDA. Explanation-
DDA algorithm is an incremental scan conversion method. 1 M,
A DDA is hardware or software used for linear interpolation of variables over an interval
between start and end point. Algorithm-
DDAs are used for rasterization of lines, triangles and polygons.
3M
DDA method is referred by this name because this method is very similar to the numerical
differential equations. The DDA is a mechanical device that solves differential equations by
numerical methods.
Algorithm:
Steps 1: Read the end points of line (x1, y1) and (x2, y2).
Steps 2: Δx = abs (x2 – x1) and
Δy = abs (y2 – y1)
Step 3: if Δx >= Δy then
length = Δx
else
length = Δy
end if
Step 4: Δx = (x2 – x1)/length
Step 5: Δy = (y2 – y1)/length
Step 6: x=x1 + 0.5 * sign (Δx)
y=y1 + 0.5 * sign (Δy)
Step 7: i = 1
while (i >= length)
{
plot (integer (x), integer (y))
x = x + Δx
y = y + Δy
i=i+1
}
Step 8: End
c) Consider the square A(2, 0), B(0, 0), C(0, 2), D(2, 2). Rotate the square ABCD by 4M
45° anticlockwise about point D(2, 2).
Page No: 7 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Matrix
formation-2
M;
Matrix
calculation-
2M
Page No: 8 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Page No: 9 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
{
putpixel(x,y,new_color);
Note: give
flood_fill(x+1,y,old_color, new_color); marks for
flood_fill(x-1,y,old_color, new_color); both 4 way
flood_fill(x,y+1,old_color, new_color); or 8 way
flood_fill(x,y-1,old_color, new_color); symmetry
flood_fill(x+1,y+1,old_color, new_color);
flood_fill(x-1,y-1,old_color, new_color);
flood_fill(x+1,y-1,old_color, new_color);
flood_fill(x-1,y+1,old_color, new_color);
}
}
b) Apply the shearing transformation to rectangle with A(0, 0), B(2, 0), C(2, 2), D(0,2) as 4M
i) Shear parameter value of 1.5 relative to line yref = -1.
ii) Shear parameter value of 1.5 relative to line xref = -1.
Ans i) 2 M
ii) 2 M
Page No: 10 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Page No: 11 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Step 1: Scan two end points for the line P1(x1, y1) and P2(x2, y2). Proper
Step 2: Scan corners for the window as (Wx1, Wy1) and (Wx2, Wy2). algorithm 4
Step 3: Assign the region codes for endpoints P1 and P2 by initializing code with M
0000.
Bit 1 - if (x < Wx1)
Bit 2 - if (x > Wx2)
Bit 3 - if (y < Wy1)
Bit 4 - if (y > Wy2)
Step 4: Check for visibility of line P1, P2.
• If region codes for both end points are zero then the line is visible, draw it and jump to step
6.
• If region codes for end points are not zero and the logical Anding operation of them is also
not zero then the line is invisible, reject it and jump to step 6.
• If region codes for end points does not satisfies the condition in 4 (i) and 4 (ii) then line is
partly visible.
Step5: Find midpoint of line and divide it into two equal line segments and repeat
Page No: 12 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
steps 3 through 5 for both subdivided line segments until you get completely
visible and completely invisible line segments.
Step 6: Exit.
d) Explain curve generation using interpolation technique. 4M
Ans Specify a spline curve by giving a set of coordinate positions, called control points, which Description-
indicates the general shape of the curve These, control points are then fitted with piecewise 2 M;
continuous parametric polynomial functions in one of two ways. When polynomial sections are
fitted so that the curve passes through each control point, the resulting curve is said to interpolate Example/
the set of control points. On the other hand, when the polynomials are fitted to the general control
-point path without necessarily passing through any control point, the resulting curve is said to Diagram 2
approximate the set of control points interpolation curves are commonly used to digitize M
drawings or to specify animation paths. Approximation curves are primarily used as design tools
to structure object surfaces an approximation spline surface credited for a design application.
Straight lines connect the control -point positions above the surface.
Ans Virtual Reality (VR) is the use of computer technology to create a simulated Proper
environment. Instead of viewing a screen in front of them, users are immersed and able to Explanation
interact with3D worlds. 4M
Advantages:
• Virtual reality creates a realistic world
• Through Virtual Reality user can experiment with an artificial environment.
• Virtual Reality make the education more easily and comfort.
• It enables user to explore places.
• Virtual Reality has made watching more enjoyable than reading. Virtual reality widely used
in video games, engineering, entertainment, education, design, films, media, medicine and
many more.
b) Write down the steps in Bresenham's circle drawing algorithm. 4M
Page No: 13 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 1) Read the radius (r) of the circle. Correct
2) D=3-2r algorithm 4
3) x=0 y=r M
4) do
{
plot(x,y)
if(d<0) then
{
d=d+4x+6
}
else
{
d=d+4(x-y)+10
y=y-1
}
x=x+1
}
while(x<y)
5) stop
Page No: 14 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Y' = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also
be represented using the column vectors.
P = [X] [Y] p'=[X] [Y] T = [tx] [ty]
We can write it as,
P' = P + T
Rotation:
Rotation as the name suggests is to rotate a point about an axis. The axis can be any
of the co-ordinates or simply any other specified line also.
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the
following figure, we can see that the point P(X, Y) is located at angle φ from the
horizontal X coordinate with distance r from the origin.
Let us, suppose you want to rotate it at the angle θ. After rotating it to a new location,
you will get a new point P' (X', Y').
Using standard trigonometric the original coordinate of point P(X, Y) can be represented as:
X = r cos ф (1)
Y = r sin ф (2)
Same way we can represent the point P' (X', Y') as:
x′ = r cos (ф + θ) = r cos ф cos θ − r sin ф sin θ (3)
y′ = r sin (ф + θ) = r cos ф sin θ + r sin ф cos θ (4)
Substituting equation (1) and (2) in (3) and (4) respectively, we will get
x′ = x cos θ − y sin θ
y′ = x sin θ + y cos θ
Representing the above equation in matrix form,
Where, R is the rotation matrix
The rotation angle can be positive and negative.
d) Explain Sutherland - Hodgeman polygon clipping algorithm. 4M
Page No: 15 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
This will give the curve which starts and ends at same place as the original segment but is
built of 4 equal length segments, with each 1/3rd of the original length. So the new curve has
4/3 the length of original segments. Repeat same process for each of the 4 segment which
will give curve more wiggles and its length become 16/9 times the original. Suppose
repeating the replacements indefinitely, since each repetition increases the length by a factor
of 4/3, the length of the curve will be infinite but it is folded in lots of tiny wiggles.
(ii) Starbust method: In this method a fix pattern of line segments are used to generate
characters. Out of these 24 line segments, segments required to display for particular
character are highlighted. This method of character generation is called starbust method
because of its characteristic appearance.
The starbust patterns for characters A and M. the patterns for particular characters are stored
in the form of 24 bit code, each bit representing one line segment. The bit is set to one to
highlight the line segment; otherwise it is set to zero. For example, 24-bit code for Character
A is 0011 0000 0011 1100 1110 0001 and for character M is 0000 0011 0000 1100 1111
0011.
This method of character generation has some disadvantages. They are
1. The 24-bits are required to represent a character. Hence more memory is required
2. Requires code conversion software to display character from its 24-bit code
3. Character quality is poor. It is worst for curve shaped characters.
The third method for character generation is the bitmap method. It is also called dot matrix
because in this method characters are represented by an array of dots in the matrix form. It is
a two dimensional array having columns and rows. An 5x7 array is commonly used to
represent characters. However 7x9 and 9x13 arrays are also used. Higher resolution devices
such as inkjet printer or laser printer may use character arrays that are over 100x100.
Page No: 17 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Each dot in the matrix is a pixel. The character is placed on the screen by copying pixel
values from the character array into some portion of the screen’s frame buffer. The value of
the pixel controls the intensity of the pixel.
for each
projection
description
with its
types-2 M
i)Perspective Projection:
A perspective projection is the one produced by straight lines radiating from a common point
Page No: 18 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
and passing through point on the sphere to the plane of projection.
Perspective projection is a geometric technique used to produce a three dimensional graphic
image on a plane, corresponding to what person sees.
Any set of parallel lines of object that are not parallel to the projection plane are projected
into converging lines. A different set of parallel lines will have a separate vanishing point.
Coordinate positions are transferred to the view plane along lines that converge to a point
called projection reference point. The distance and angles are not preserved and parallel lines
do not remain parallel. Instead, they all converge at a single point called center of projection
there are 3 types of perspective projections. Two characteristic of perspective are vanishing
point and perspective force shortening. Due to fore shortening objects and lengths appear
smaller from the center of projections. The projections are not parallel and we specify a
center of projection cop.
Two point perspective projections: Exactly 2 principals have vanishing points. Perspective
projection gives better impression of depth.
Three point perspective projections: All the three principal axes have finite vanishing point.
Perspective projection is most difficult to draw.
ii)Parallel Projection: A parallel projection is formed by extending parallel lines from each
vertex of object until they intersect plane of screen. Parallel projection transforms object to
the view plane along parallel lines. A projection is said to be parallel, if center of projection
is at an infinite distance from the projected plane. A parallel projection preserves relative
proportion of objects, accurate views of the various sides of an object are obtained with a
parallel projection. The projection lines are parallel to each other and extended from the
object and intersect the view plane. It preserves relative propositions of objects, and it is used
in drafting to produce scale drawings of 3D objects. This is not a realistic representation, the
point of intersection is the projection of the vertex.
Parallel projection is divided into two parts and these two parts sub divided into many.
Page No: 19 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Isometric Projections: Orthographic projections that show more than one side of an object
are called axonometric orthographic projections. The most common axonometric projection
is an isometric projection. In this projection parallelism of lines are preserved but angles are
not preserved.
Oblique Projections: Oblique projections are obtained by projectors along parallel lines that
are not perpendicular to the projection plane. An oblique projection shows the front and top
surfaces that include the three dimensions of height, width and depth. The front or principal
surface of an object is parallel to the plane of projection. Effective in pictorial representation.
Types:
Cavalier Projections: All lines perpendicular to the projection plane are projected with no
change in length. If the projected line making an angle 45 degrees with the projected plane,
as a result the line of the object length will not change.
Cabinet Projections: All lines perpendicular to the projection plane are projected to one half
of their length. These gives a realistic appearance of object. It makes 63.4 degrees angle with
the projection plane. Here lines perpendicular to the viewing surface are projected at half
their actual length.
Ans Window to viewport transformation: The window defines what is to be viewed; the 2 M-
viewport defines where it is to be displayed. Explanation,
Page No: 20 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The picture is stored in the computer memory using any convenient Cartesian co-ordinate
system, referred to as World Co-Ordinate System (WCS). However, when picture is
displayed on the display device it is measured in Physical Device Co-Ordinate System
(PDCS) corresponding to the display device.
The viewing transformation which maps picture co-ordinates in the WCS to display co-
ordinates in PDCS is performed by the following transformations.
• Converting world co-ordinates to viewing co-ordinates.
• Normalizing viewing co-ordinates.
• Converting normalized viewing co-ordinates to device co-ordinates.
1. Construct the scene in world co-ordinate using the output primitives and attributes.
2. Obtain a particular orientation for the window by setting a two-dimensional viewing co-
ordinate system in the world co-ordinate plane and define a window in the viewing co-
ordinate system.
3. Use viewing co-ordinates reference frame to provide a method for setting up arbitrary
orientations for rectangular windows.
4. Once the viewing reference frame is established, transform descriptions in world co-
ordinates to viewing co-ordinates.
5. Define a view port in normalized co-ordinates and map the viewing co-ordinates
description of the scene to normalized co-ordinates.
6. Clip all the parts of the picture which lie outside the viewport.
Ans One way to fill polygon is to start from given “seed”, point known to be inside the polygon 2 M- for
and highlight outward from this point i.e. neighbouring pixels until we encounter the either flood
boundary pixels. This approach is called seed fill. Seed fill algorithm further classified as fill or
flood fill and boundary fill algorithm. Algorithms the fill interior defined regions are flood boundary
fill algorithms, those that fill boundary defined regions are called boundary fill algorithm. fill
Page No: 21 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Flood Fill Algorithm description,
• Flood fill colors an entire area in an enclosed figure through interconnected pixels using a
single color. It is an easy way to fill color in the graphics. One just takes the shape and starts 4 M for
flood fill. The algorithm works in a manner so as to give all the pixels inside the boundary Procedure
the same color leaving the boundary and the pixels outside.
• Flood fill algorithm is used for filling the interior of a polygon.
• Used when an area defined with multiple color boundaries.
• Start at a point inside a region− Replace a specified interior color (old color) with fill color
• Fill the 4−connected or 8−connected region until all interior points being replaced.
4−Connected Regions : From a given pixel, the region that you can get to by a series of 4
way moves (north, south, east, west)
Or
8−Connected Regions : From a given pixel, the region that you can get to by a series of 8-
way moves (north, south, east, west, NE, NW, SE, SW)
OR
Page No: 22 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Boundary Fill Algorithm
Start at a point inside the figure and paint with a particular color. Filling continues until a
boundary color is encountered.
• In boundary fill algorithm Recursive method is used to fill the whole boundary.
• Start at a point inside a region.
• Paint the interior outward toward the boundary.
• The boundary is specified in a single color.
Or
8-connected boundary fill Algorithm:
Page No: 23 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
2 M-
Correct
Result
Page No: 24 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans /* 1 M-Header
Hilbert's Curve files,
*/
#include <stdio.h> 1 M-move
#include <stdlib.h> function
#include <graphics.h> body,
#include <math.h>
2 M-hilbert
#include <conio.h> function
#include <dos.h>
body,
2 M-main
void move(int j,int h,int &x,int &y) function
{ body
if(j==1)
Page No: 25 | 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
y-=h;
else if(j==2)
x+=h;
else if(j==3)
y+=h;
else if(j==4)
x-=h;
lineto(x,y);
}
void hilbert(int r,int d,int l,int u,int i,int h,int &x,int &y)
{
if(i>0)
{
i--;
hilbert(d,r,u,l,i,h,x,y);
move(r,h,x,y);
delay(100);
hilbert(r,d,l,u,i,h,x,y);
move(d,h,x,y);
delay(100);
hilbert(r,d,l,u,i,h,x,y);
move(l,h,x,y);
delay(100);
hilbert(u,l,d,r,i,h,x,y);
}
}
void main()
{
int n,x1,y1;
int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
clrscr();
int gm,gd=DETECT;
initgraph(&gd,&gm,"C:\\Turboc3\\bgi");
printf("\n Give the value of n: ");
scanf("%d",&n);
x=x0;
y=y0;
moveto(x,y);
hilbert(r,d,l,u,n,h,x,y);
delay(100);
getch();
closegraph();
}
Page No: 26 | 26