0% found this document useful (0 votes)
13 views19 pages

Computer Graphics Unit-1

Uploaded by

tanishaanmol5519
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
13 views19 pages

Computer Graphics Unit-1

Uploaded by

tanishaanmol5519
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 19

RENAISSANCE UNIVERSITY, INDORE

School of Computer Science

BCA/ BSc V Sem

Subject: Computer Graphics

Unit-1

Introduction to Computer Graphics


It is the use of computers to create and manipulate pictures on a display device. It uses
software techniques to create, store, modify, and represent pictures. It transforms and
presents information in a visual form. In today's life, computer graphics has now become a
common element in user interfaces, T.V. commercial motion pictures.
Computer Graphics is the creation of pictures with the help of a computer. The end product
of computer graphics is a picture; it may be a business graph, drawing, and engineering. In
computer graphics, two or three-dimensional pictures can be created that are used for
research. Many hardware devices algorithms have been developed for improving the speed
of picture generation with time. It includes the creation, storage of models and image of
objects. These models for various fields like engineering, mathematical and so on.

Application of Computer Graphics


1. Education and Training: Computer-generated model of the physical, financial and
economic system is often used as educational aids. Model of physical systems, physiological
system, population trends or equipment can help trainees to understand the operation of
the system. For some training applications, particular systems are designed. For example
Flight Simulator.
Flight Simulator: It helps in giving training to the pilots of airplanes. These pilots spend
much of their training not in a real aircraft but on the ground at the controls of a Flight
Simulator.
Advantages:
1. Fuel Saving
2. Safety
3. Ability to familiarize the training with a large number of the world's airports.

2. Use in Biology: Molecular biologist can display a picture of molecules and gain insight

3. Computer-Generated Maps: Town planners and transportation engineers can use


computer-generated maps which display data useful to them in their planning work.

4. Architect: Architect can explore an alternative solution to design problems at an


interactive graphics terminal. In this way, they can test many more solutions that would
not be possible without the computer.

5. Presentation Graphics: Example of presentation Graphics are bar charts, line graphs,
pie charts and other displays showing relationships between multiple parameters.
Presentation Graphics is commonly used to summarize:
o Financial Reports
o Statistical Reports
o Mathematical Reports
o Scientific Reports
o Economic Data for research reports
o Managerial Reports

6. Computer Art: Computer Graphics are also used in the field of commercial arts. It is
used to generate television and advertising commercial.

7. Entertainment: Computer Graphics are now commonly used in making motion pictures,
music videos and television shows.

8. Visualization: It is used for visualization of scientists, engineers, medical personnel,


business analysts for the study of a large amount of information.

9. Educational Software: Computer Graphics is used in the development of educational


software for making computer-aided instruction.

10. Printing Technology: Computer Graphics is used for printing technology and textile
design.

Example of Computer Graphics Packages:


1. LOGO
2. COREL DRAW
3. AUTO CAD
4. 3D STUDIO
5. CORE
6. GKS (Graphics Kernel System)
7. PHIGS
8. CAM (Computer Graphics Metafile)
9. CGI (Computer Graphics Interface)

Interactive Computer Graphics: Interactive Computer Graphics involves a two way


communication between computer and user. Here the observer is given some control over
the image by providing him with an input device for example the video game controller of
the ping pong game. This helps him to signal his request to the computer.
The computer on receiving signals from the input device can modify the displayed picture
appropriately. To the user it appears that the picture is changing instantaneously in
response to his commands. He can give a series of commands, each one generating a
graphical response from the computer. In this way he maintains a conversation, or
dialogue, with the computer.
Non Interactive Computer Graphics: In non interactive computer graphics otherwise
known as passive computer graphics. it is the computer graphics in which user does not
have any kind of control over the image. Image is merely the product of static stored
program and will work according to the instructions given in the program linearly. The
image is totally under the control of program instructions not under the user. Example:
screen savers.
Cathode Ray Tube (CRT)
CRT stands for Cathode Ray Tube. CRT is a technology used in traditional computer
monitors and televisions. The image on CRT display is created by firing electrons from the
back of the tube of phosphorus located towards the front of the screen.

Once the electron heats the phosphorus, they light up, and they are projected on a screen.
The color you view on the screen is produced by a blend of red, blue and green light.

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

Random Scan Display


Random Scan System uses an electron beam which operates like a pencil to create a line
image on the CRT screen. The picture is constructed out of a sequence of straight-line
segments. Each line segment is drawn on the screen by directing the beam to move from
one point on the screen to the next, where its x & y coordinates define each point. After
drawing the picture. The system cycles back to the first line and design all the lines of the
image 30 to 60 time each second. The process is shown in fig:
Random-scan monitors are also known as vector displays or stroke-writing displays or
calligraphic displays.
Advantages:
1. A CRT has the electron beam directed only to the parts of the screen where an image
is to be drawn.
2. Produce smooth line drawings.
3. High Resolution
Disadvantages:
1. Random-Scan monitors cannot display realistic shades scenes.

Raster Scan Display


A Raster Scan Display is based on intensity control of pixels in the form of a rectangular box
called Raster on the screen. Information of on and off pixels is stored in refresh buffer or
Frame buffer. Televisions in our house are based on Raster Scan Method. The raster scan
system can store information of each pixel position, so it is suitable for realistic display of
objects. Raster Scan provides a refresh rate of 60 to 80 frames per second.

Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are called
picture elements or pixels. Beam refreshing is of two types. First is horizontal retracing and
second is vertical retracing. When the beam starts from the top left corner and reaches the
bottom right scale, it will again return to the top left side called at vertical retrace. Then it
will again more horizontally from top to bottom call as horizontal retracing shown in fig:

Types of Scanning or travelling of beam in Raster Scan


1. Interlaced Scanning
2. Non-Interlaced Scanning
In Interlaced scanning, each horizontal line of the screen is traced from top to bottom. Due
to which fading of display of object may occur. This problem can be solved by Non-
Interlaced scanning. In this first of all odd numbered lines are traced or visited by an
electron beam, then in the next circle, even number of lines are located.
For non-interlaced display refresh rate of 30 frames per second used. But it gives flickers.
For interlaced display refresh rate of 60 frames per second is used.
Advantages:
1. Realistic image
2. Million Different colors to be generated
3. Shadow Scenes are possible.
Disadvantages:
1. Low Resolution
2. Expensive

Differentiate between Random and Raster Scan Display:

Random Scan Raster Scan


1. It has high Resolution 1. Its resolution is low.
2. It is more expensive 2. It is less expensive
3. Any modification if needed is easy 3.Modification is tough
4. Solid pattern is tough to fill 4.Solid pattern is easy to fill
5. Refresh rate depends or resolution 5. Refresh rate does not depend on the picture.
6. Only screen with view on an area is displayed. 6. Whole screen is scanned.
7. Beam Penetration technology come under it. 7. Shadow mark technology came under this.
8. It does not use interlacing method. 8. It uses interlacing
9. It is restricted to line drawing applications 9. It is suitable for realistic display.

Point-
A Point in two-dimensional geometry is defined as a location in 2D space that is
uniquely defined by coordinates (x, y) where x, y are the distances of the point from the X-
axis,and Y-axis, respectively

Straight Line-
A straight line may be defined by two endpoints & an equation. In fig the two endpoints are
described by (x1,y1) and (x2,y2). The equation of the line is used to determine the x, y
coordinates of all the points that lie between these two endpoints.
Using the equation of a straight line, y = mx + b where

m= and
b = the y interrupt,
we can find values of y by incrementing x from x =x1, to x = x2. By scan-converting these
calculated x, y values, we represent the line as a sequence of pixels.

Properties of Good Line Drawing Algorithm:


1. Line should appear Straight: We must appropriate the line by choosing addressable
points close to it. If we choose well, the line will appear straight, if not, we shall produce
crossed lines.

The lines must be generated parallel or at 45° to the x and y-axes. Other lines cause a
problem: a line segment through it starts and finishes at addressable points, may happen to
pass through no another addressable points in between.

2. Lines should terminate accurately: Unless lines are plotted accurately, they may
terminate at the wrong place.

3. Lines should have constant density: Line density is proportional to the no. of dots
displayed divided by the length of the line.

To maintain constant density, dots should be equally spaced.


4. Line density should be independent of line length and angle: This can be done by
computing an approximating line-length estimate and to use a line-generation algorithm
that keeps line density constant to within the accuracy of this estimate.
5. Line should be drawn rapidly: This computation should be performed by special-
purpose hardware.

Algorithms for line Drawing:


1. DDA (Digital Differential Analyzer)
2. Bresenham's Algorithm

1. DDA Algorithm-
DDA Algorithm is the simplest line drawing algorithm. In this, given the starting and
ending coordinates of a line,
DDA Algorithm attempts to generate the points between the starting and ending
coordinates.
Procedure-
Given-
● Starting coordinates = (X , Y ) 0 0

● Ending coordinates = (X , Y )
n n

The points generation using DDA Algorithm involves the following steps-

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

Step-02:
Find the number of steps or points in between the starting and ending coordinates.

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


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

Step-03:
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Find the next point by following the below three cases-
Step-04:
Keep repeating Step-03 until the end point is reached or the number of generated new
points (including the starting and ending points) equals to the steps count.

Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).

Solution- Given-
● Starting coordinates = (X0, Y0) = (5, 6)
● Ending coordinates = (Xn, Yn) = (8, 12)

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

Step-02:
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6

Step-03:
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
7.5 11 (8, 11)
8 12 (8, 12)
The advantages of DDA Algorithm are-
● It is a simple algorithm.
● It is easy to implement.
● It avoids using the multiplication operation which is costly in terms of time
complexity.
Disadvantages of DDA Algorithm-
● There is an extra overhead of using round off( ) function.
● Using round off( ) function increases time complexity of the algorithm.
● Resulted lines are not smooth because of round off( ) function.
● The points generated by this algorithm are not accurate.

2.Bresenham Line Drawing Algorithm-


Given the starting and ending coordinates of a line, Bresenham Line Drawing Algorithm
attempts to generate the points between the starting and ending coordinates.

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

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

Step-01:
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-

ΔX = Xn – X0
ΔY =Yn – Y0

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

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

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

Problem-01:
Calculate the points between the starting coordinates (9, 18) and ending coordinates (14,
22).
Solution- Given-
● Starting coordinates = (X , Y ) = (9, 18) 0 0

● Ending coordinates = (X , Y ) = (14, 22) n n

Step-01:
Calculate ΔX and ΔY from the given input.
● ΔX = X – X = 14 – 9 = 5 n 0

● ΔY =Y – Y = 22 – 18 = 4
n 0

Step-02:
Calculate the decision parameter.
P = 2ΔY – ΔX
k

=2x4–5
=3
So, decision parameter P = 3 k

Step-03:
As P >= 0, so case-02 is satisfied.
k

Thus,
● P = P + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
k+1 k

● X = X + 1 = 9 + 1 = 10
k+1 k

● Y = Y + 1 = 18 + 1 = 19
k+1 k

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

9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22

Advantages of Bresenham Line Drawing Algorithm-


● It is easy to implement.
● It is fast and incremental.
● It executes fast but less faster than DDA Algorithm.
● The points generated by this algorithm are more accurate than DDA Algorithm.
● It uses fixed points only.

Disadvantages of Bresenham Line Drawing Algorithm-


● Though it improves the accuracy of generated points but still the resulted line is not
smooth.
● This algorithm is for the basic line drawing.
● It cannot handle diminishing jaggies.

Mid Point Circle Drawing Algorithm-


Given the centre point and radius of circle,
Mid Point Circle Drawing Algorithm attempts to generate the points of one octant.
The points for other octacts are generated using the eight symmetry property.
Procedure-
Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R
The points generation using Mid Point Circle Drawing Algorithm involves the following
steps-
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R

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

Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).

Find the next point of the first octant depending on the value of decision parameter Pk.
Follow the below two cases-

Step-04:
If the given centre point (X , Y ) is not (0, 0), then do the following and plot the point-
0 0

● X =X +X
plot c 0

● Y =Y +Y
plot c 0

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


c c

Step-05:
Keep repeating Step-03 and Step-04 until X >= Y .
plot plot

Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
This is depicted by the following figure-

Problem-01:
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to form a
circle.
Solution- Given:

Centre Coordinates of Circle (X , Y ) = (0, 0)


● 0 0

Radius of Circle = 10

Step-01:
Assign the starting point coordinates (X , Y ) as- 0 0

● X =0 0

● Y = R = 10 0

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

P =1–R
0

P = 1 – 10
0

P = -9
0

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

Thus,
● X =X +1=0+1=1 k+1 k

● Y = Y = 10 k+1 k

● P = P + 2 x X + 1 = -9 + (2 x 1) + 1 = -6
k+1 k k+1

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

Step-05:
Step-03 is executed similarly until X >= Y as follows- k+1 k+1

P k P (X , Y ) k+1 k+1 k+1

(0, 10)
-9 -6 (1, 10)
-6 -1 (2, 10)
-1 6 (3, 10)
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y
coordinates.
Octant-1 Points Octant-2 Points
(0, 10) (8, 6)
(1, 10) (9, 5)
(2, 10) (9, 4)
(3, 10) (10, 3)
(4, 9) (10, 2)
(5, 9) (10, 1)
(6, 8) (10, 0)
These are all points for Quadrant-1.
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y)
(0, 10) (0, 10) (0, -10) (0, -10)
(1, 10) (-1, 10) (-1, -10) (1, -10)
(2, 10) (-2, 10) (-2, -10) (2, -10)
(3, 10) (-3, 10) (-3, -10) (3, -10)
(4, 9) (-4, 9) (-4, -9) (4, -9)
(5, 9) (-5, 9) (-5, -9) (5, -9)
(6, 8) (-6, 8) (-6, -8) (6, -8)
(8, 6) (-8, 6) (-8, -6) (8, -6)
(9, 5) (-9, 5) (-9, -5) (9, -5)
(9, 4) (-9, 4) (-9, -4) (9, -4)
(10, 3) (-10, 3) (-10, -3) (10, -3)
(10, 2) (-10, 2) (-10, -2) (10, -2)
(10, 1) (-10, 1) (-10, -1) (10, -1)
(10, 0) (-10, 0) (-10, 0) (10, 0)
These are all points of the Circle.

Advantages of Mid Point Circle Drawing Algorithm-


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

Disadvantages of Mid Point Circle Drawing Algorithm-


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

Filled Area Primitives


Region filling is the process of filling image or region. Filling can be of boundary or interior
region as shown in fig. Boundary Fill algorithms are used to fill the boundary and flood-fill
algorithm are used to fill the interior.

Boundary Fill Algorithm


The boundary fill algorithm works as its name. This algorithm picks a point inside an object
and starts to fill until it hits the boundary of the object. The color of the boundary and the
color that we fill should be different for this algorithm to work.
In this algorithm, we assume that color of the boundary is same for the entire object. The
boundary fill algorithm can be implemented by 4-connected pixels or 8-connected pixels.

Four connected approaches is more suitable than the eight connected approaches.

1. Four connected approaches: In this approach, left, right, above, below pixels are tested.

2. Eight connected approaches: In this approach, left, right, above, below and four
diagonals are selected.
Boundary can be checked by seeing pixels from left and right first. Then pixels are checked
by seeing pixels from top to bottom. The algorithm takes time and memory because some
recursive calls are needed.

Algorithm:
1. Take the position of the starting point and the boundary color.
2. Decide wether you want to go in 4 directions (N, S, W, E) or 8 directions (N, S, W, E,
NW, NE, SW, SE).
3. Choose a fill color.
4. Travel in those directions.
5. If the pixel you land on is not the fill color or the boundary color , replace it with the
fill color.
6. Repeat 4 and 5 until you’ve been everywhere within the boundaries.

Problem with recursive boundary fill algorithm


It may not fill regions sometimes correctly when some interior pixel is already filled with
color. The algorithm will check this boundary pixel for filling and will found already filled
so recursive process will terminate. This may vary because of another interior pixel
unfilled.

So check all pixels color before applying the algorithm.

Polygon Filling Algorithm


Polygon is an ordered list of vertices as shown in the following figure. For filling polygons
with particular colors, you need to determine the pixels falling on the border of the polygon
and those which fall inside the polygon. In this chapter, we will see how we can fill
polygons using different techniques.

Scan Line Algorithm


This algorithm works by intersecting scanline with polygon edges and fills the polygon
between pairs of intersections. The following steps depict how this algorithm works.
Step 1 − Find out the Ymin and Ymax from the given polygon.

Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1,
p2, p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate
i.e. p0,p1,p1,p2 and p2,p3.
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate
pairs.

4-Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We are putting the
pixels above, below, to the right, and to the left side of the current pixels and this process
will continue until we find a boundary with different color.

Algorithm:
Step 1 − Initialize the value of seed point seedx,seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till
the boundary pixels reached.
If getpixel(x, y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below where we tried
to fill the entire region. Here, the image is filled only partially. In such cases, 4-connected
pixels technique cannot be used.
8-Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We are putting pixels
above, below, right and left side of the current pixels as we were doing in 4-connected
technique.
In addition to this, we are also putting pixels in diagonals so that entire area of the current
pixel is covered. This process will continue until we find a boundary with different color.

Algorithm:
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till
the boundary pixels reached
If getpixel(x,y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighbourhood points
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)
Step 6 − Exit

Flood Fill Algorithm


Sometimes we come across an object where we want to fill the area and its boundary with
different colors. We can paint such objects with a specified interior color instead of
searching for particular boundary color as in boundary filling algorithm.
Instead of relying on the boundary of the object, it relies on the fill color. In other words, it
replaces the interior color of the object with the fill color. When no more pixels of the
original interior color exist, the algorithm is completed.
Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in
the pixels. But instead of looking for the boundary color, it is looking for all adjacent pixels
that are a part of the interior.
Algorithm:
1. Take the position of the starting point.

2. Decide whether you want to go in 4 directions ( N, S, W, E ) or 8 directions ( N, S, W,


E, NW, NE, SW, SE ).

3. Choose a replacement color and a target color.

4. Travel in those directions.

5. If the tile you land on is a target, replace it with the chosen color.

6. Repeat 4 and 5 until you've been everywhere within the boundaries.

Curve Generation
In computer graphics, we often need to draw different types of objects onto the screen.
Objects are not flat all the time and we need to draw curves many times to draw an object.
A curve is an infinitely large set of points. Each point has two neighbors except endpoints.

Types of Curves
Curves can be broadly classified into three categories − explicit, implicit, and parametric
curves.

Implicit Curves: Implicit curves are defined by an equation of the form f(x,y)=0, where f(x,y)
is a function of the coordinates x and y in a plane. Implicit curves describe all the points
that satisfy a certain relationship between x and y.
A common example is the circle, whose implicit representation is
x2 + y2 - R2 = 0

Explicit Curves: A mathematical function y = f(x) can be plotted as a curve. Such a function is
the explicit representation of the curve. The explicit representation is not general, since it
cannot represent vertical lines and is also single-valued. For each value of x, only a single
value of y is normally computed by the function.

An explicit curve is expressed as y=f(x), where y is directly dependent on x. This means for
any given x-value, you can directly compute the corresponding y-value using the function
f(x).

Example, y=ax2+bx+c, which is a quadratic equation defining a parabolic shape


Parametric Curves: Parametric curves describe a curve using a set of parametric equations,
where both coordinates x and y (or more, in higher dimensions) are expressed as functions
of an independent parameter, usually denoted as t. This approach offers great flexibility in
representing curves that cannot be easily expressed in explicit or implicit forms, such as
circles, ellipses, or more complex curves like spirals or loops.

A parametric curve in two dimensions is described by two functions, x(t) and y(t), where t
is the parameter that typically varies over an interval [t0,t1]:

x=f(t), y=g(t)

As the parameter t changes, it traces out a curve in the plane.

Bezier Curves: Bezier curve is discovered by the French engineer Pierre Bézier. These are
parametric curves widely used in computer graphics, animation, and modeling for creating
smooth and scalable shapes. Bézier curves are used in vector graphics (like SVG), font
design, and even animation paths. They are defined by a set of control points, and the
curve's shape is determined by these points. The Bezier curve can be represented
mathematically as –

Where,

B-Spline Curves: These are generalizations of Bézier curves that offer more flexibility and
control over the curve’s shape, particularly for complex shapes. Like Bézier curves, B-splines are
widely used in computer-aided design (CAD), animation, and modeling, but they are more
versatile when it comes to handling large numbers of control points. The B-Spline curve can be
represented mathematically as –

Where,

You might also like