CG Unit-2
CG Unit-2
Output Primitives :-
Points
Lines
Circles
Line Drawing Algorithms :-
The Cartesian slope-intercept equation for a straight line is
y = mx + b ----- (1)
where x, y are co-ordinate points, m is the slope of line, and b is known as y intercept.
The two endpoints of a line segment are specified at positions (x1, y1) and (x2, y2), as shown
in Fig. 1, we can determine values for the slope m and y intercept b with the following
calculations:
m = (y2-y1)/(x2-x1) ----- (2)
From eq.(1), value of
b = y1 - mx1
For any given x interval ∆x along a line, we can compute the corresponding y interval ∆y
from eq. (2) as
∆y = m ∆x ----- (3)
Similarly, we can obtain the x interval ∆x corresponding to a specified ∆y as
∆x = ∆y / m ----- (4)
These equations form the basis for determining deflection voltages in analog devices.
On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical
directions are constrained by pixel separations.
That is, we must "sample" a line at discrete positions and determine the nearest pixel to the
line at each sampled position.
This scan conversion process for straight lines is illustrated in Fig. 3.4, for a near horizontal
line with discrete sample positions along the x axis.
Page 1 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Fig.1 : Line path between endpoint positions (x1, y1) and (x2, y2)
DDA Algorithm :-
The Digital Differential Analyzer (DDA) is a scan-conversion line algorithm based on
calculating either ∆y or ∆x, using eq - (3) or eq - (4).
We sample the line at unit intervals in one coordinate and determine corresponding integer
values nearest the line path for the other coordinate.
The line to be drawn may have the slope as positive or negative.
Positive slope means that values of x and y are increasing.
Line with positive slope :-
If the value of slope is less than or equal to 1, we sample at unit x intervals (∆x = 1) and
compute each successive y value as
yk+1 = yk + m ---(1)
Here, k takes integer values starting from 1, for the first point, and increases by 1 until the
final endpoint is reached. Since m can be any real number between 0 and 1, the calculated y
values must be rounded to the nearest integer.
If the value of slope is greater than 1, we sample at unit y intervals (∆y = 1) and calculate
each successive x value as
xk+1 = xk + (1/m) ---(2)
Equations (1) and (2) are based on the assumption that lines are to be processed from the left
endpoint to the right endpoint (Fig-1).
If this processing is reversed, so that the starting endpoint is at the right, then either we have
∆x = -1 and
yk+1 = yk - m ---(3)
Or, when the slope is greater than 1, we have ∆y = -1 and
xk+1 = xk - (1/m) ---(4)
Equations 1, 2, 3 and 4 can also be used to calculate pixel positions along a line with
negative slope.
If the absolute value of the slope is less than 1 and the start endpoint is at the left, we set ∆x
= 1 and calculate y values with eq - (1).
When the start endpoint is at the right (for the same slope), we set ∆x = -1 and obtain y
positions from eq - (3).
Similarly, when the absolute value of a negative slope is greater than 1, we use ∆y = -1 and
eq- (4) or we use ∆y = 1 and eq - (2).
This algorithm is summarized in the following procedure, which accepts as input the two
endpoint pixel positions.
Page 2 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
#include “device.h”
#define ROUND(a) ((int) (a+0.5))
void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb - xa, dy = yb - ya, steps, k;
float xIcrement, yIncrement, x = xa, y = ya;
if (abs(dx) > abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xIcrement = dx / (float) steps;
yIcrement = dy / (float) steps;
setPixel (ROUND(x), ROUND(y));
for (k=0; k<steps; k++)
{
x += xIcrement;
y += yIcrement;
setPixel (ROUND(x), ROUND(y));
}
}
The DDA algorithm is a faster method for calculating pixel positions than the direct use of
line equation.
It eliminates the multiplication in line equation by making use of raster characteristics, so
that appropriate increments are applied in the x or y direction to step to pixel positions along
the line path.
The accumulation of roundoff error in successive additions of the floating-point increment,
can cause the calculated pixel positions to drift away from the true line path for long line
segments.
The rounding operations and floating-point arithmetic in procedure line DDA are still time-
consuming.
We can improve the performance of the DDA algorithm by separating the increments m and
l/m into integer and fractional parts so that all calculations are reduced to integer operations.
Bresenham's Line Algorithm :-
An accurate and efficient raster line-generating algorithm, developed by Bresenham, scan
converts lines using only incremental integer calculations that can be adapted to display
circles and other curves.
Following figures show sections of a display screen where straight line segments are to be
drawn.
Page 3 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
The vertical axes show scan-line positions, and the horizontal axes identify pixel columns.
Sampling at unit x intervals in these examples, we need to decide which of two possible
pixel positions 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 x intervals.
Starting from the left endpoint (x0,y0) of a given line, we step to each successive column (x
position) and plot the pixel whose scan-line y value is closest to the line path.
Figure 3.7 shows the kth step in this process.
Assuming we have determined that the pixel at (xk, yk) is to be displayed, we next need to
decide which pixel to plot in column xk+1.
Our choices are the pixels at positions (xk+1, yk) and (xk+1, yk+1).
At sampling position xk+1, we label vertical pixel separations from the mathematical line
path as d1 and d2 (Fig. 3-8).
They coordinate on the mathematical line at pixel column position xk+1 is calculated as
y = m(xk+1) + b ---(1)
Then
d1 = y - yk
= m(xk+1) + b – yk
d2 = (yk+1) - y
= (yk+1) – (m(xk+1) + b)
Page 4 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Another way to eliminate the unequal spacing is to calculate points along the circular
boundary using polar coordinates r and θ.
Expressing the circle equation in parametric polar form yields the pair of equations
x = xc + r cosθ
y = yc + r sinθ ---- (3)
Page 6 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
When a display is generated with these equations using a fixed angular step size, a circle is
plotted with equally spaced points along the circumference.
The step size chosen for θ depends on the application and the display device.
Larger angular separations along the circumference can be connected with straight line
segments to approximate the circular path.
Computation can be reduced by considering the symmetry of circles. The shape of the circle
is similar in each quadrant.
Determining pixel positions along a circle circumference using either eq. (1) or eq. (3) still
requires a good deal of computation time.
Bresenham's line algorithm for raster displays is adapted to circle generation by setting up
decision parameters for finding the closest pixel to the circumference at each sampling step.
A method for direct distance comparison is to test the halfway position between two pixels
to determine if this midpoint is inside or outside the circle boundary.
Midpoint Circle Algorithm :-
Assume that the origin of circle is (0,0).
We obtain a recursive expression for the next decision parameter by evaluating the circle
function at sampling position xk+1 + 1= xk + 2. (Replace k as k+1 in eq – (6))
pk+1= (xk+1 + 1)2 + (yk+1 – 1/2)2 – r2
pk+1= (xk + 2)2 + (yk+1 – 1/2)2 – r2 ----(7)
Now,
pk+1 - pk= [(xk + 2)2 + (yk+1 – 1/2)2 – r2] – [(xk + 1)2 + (yk – 1/2)2 – r2]
pk+1 = pk + 2(xk + 1) + (y2k+1 – y2k) – (yk+1 – yk) + 1 ----(8)
where yk+1 is either yk or yk-1
If pk < 0, then midpoint is inside the circle and the pixel on scan line yk is closer to the circle
boundary. So select upper pixel i.e. yk.
Then from eq – (8)
pk+1 = pk + 2(xk + 1) + (y2k+1 – y2k) – (yk+1 – yk) + 1
pk+1 = pk + 2(xk + 1) + (y2k – y2k) – (yk – yk) + 1
= pk + 2(xk + 1) + 1
pk+1 = pk + 2xk + 3
If pk >= 0, then midpoint is on the circle boundary or outside the circle boundary. So select
lower pixel i.e. yk-1.
Then from eq – (8)
pk+1 = pk + 2(xk + 1) + (y2k+1 – y2k) – (yk+1 – yk) + 1
pk+1 = pk + 2(xk + 1) +((yk – 1)2 – y2k) – (yk – 1 – yk) + 1
= pk + 2(xk - yk) + 5
The initial decision parameter is obtained by evaluating the circle function at the start
position (x0, y0) = (0, r).
First decision parameter coordinate at (0,r)
p0 = fcircle(1, r – 1/2)
p0 = (0 + 1)2 + (r – 1/2)2 – r2
= 5/4 – r
If the radius r is specified as an integer, we can simply round p0 to
p0 = 1 – r ----(9) (for r an integer)
Midpoint Circle Algorithm :-
1. Input radius r and circle center (xc, yc), and obtain the first point on the circumference of
a circle centered on the origin as
(x0, y0) = (0, r)
2. Calculate the initial value of the decision parameter as
p0 = 5/4 – r
3. At each xk position, starting at k=0, perform the following test:
If pk < 0, the next point along the circle centered on (0,0) is (xk+1, yk) and
pk+1 = pk + 2xk+1 + 1
Otherwise, the next point along the circle is (xk +1, yk -1) and
pk+1 = pk + 2xk+1 + 1 - 2yk+1
Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk - 2
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (x, y) onto the circular path centered on (xc, yc) and
plot the coordinate values:
x = x + xc , y = y + yc
Page 8 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
A scan line passing through a vertex intersects two edges at that position, adding two points
to the list of intersections for the scan line.
Following figure shows two scan lines at positions y and y' that intersect edge endpoints.
Scan line y intersects five polygon edges. Scan line y’ intersects an even number of edges
although it also passes through a vertex.
Intersection points along scan line y' correctly identify the interior pixel spans.
But with scan line y, we need to do some additional processing to determine the correct
interior points.
For scan line y, the two intersecting edges sharing a vertex are on opposite sides of the scan
line.
But for scan line y', the two intersecting edges are both above the scan line.
Page 9 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Thus, the vertices that require additional processing are those that have connecting edges on
opposite sides of the scan line.
We can identify these vertices by tracing around the polygon boundary either in clockwise
or counter clockwise order and observing the relative changes in vertex y coordinates as we
move from one edge to the next.
If the endpoint y values of two consecutive edges monotonically increase or decrease, we
need to count the middle vertex as a single intersection point for any scan line passing
through that vertex.
Otherwise, the shared vertex represents a local extremum (minimum or maximum) on the
polygon boundary, and the two edge intersections with the scan line passing through that
vertex can be added to the intersection list.
Inside-Outside Tests :-
Area-filling algorithms and other graphics processes often need to identify interior regions
of objects.
In elementary geometry, a polygon is usually defined as having no self-intersections.
Examples of standard polygons include triangles, rectangles, octagons, and decagons.
Page 10 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
The component edges of these objects are joined only at the vertices, and otherwise the
edges have no common points in the plane.
Identifying the interior regions of standard polygons is generally a straightforward process.
But in most graphics applications, we can specify any sequence for the vertices of a fill area,
including sequences that produce intersecting edges, as in following figure.
Odd-Even Rule :-
It is also called the odd parity rule or the even-odd rule.
Rules :
1. Draw a line from any position P to a distant point, which is outside the polygon co-
ordinates.
2. If the number of polygon edges crossed by this line is odd, then P is an interior point.
Otherwise, P is an exterior point.
To obtain an accurate edge count, we must be sure that the line path we choose does not
intersect any polygon vertices.
The scan-line polygon fill is example of odd-even parity rule.
Non-zero winding number rule :-
Another method for defining interior regions is the nonzero winding number rule, which
counts the number of times the polygon edges wind around a particular point in the counter
clockwise direction.
This count is called the winding number.
The point whose winding number is non-zero is considered as interior point, and otherwise,
it is exterior.
1. Take one counter point, initialize it zero.
2. Draw a line from any position P to a distant point. (Line must not pass through any
vertices).
3. Process all edges that across the line in each direction.
If direction is from right left then +1
If direction is from left right then -1
4. The final value of the winding number, after all edge crossings have been counted,
determines the relative position of P.
Boundary Fill Algorithm :-
Another approach to area filling is to start at a point inside a region and paint the interior
outward toward the boundary.
If the boundary is specified in a single color, the fill algorithm proceeds outward pixel by
pixel until the boundary color is encountered.
This method, called the boundary-fill algorithm, is particularly useful in interactive painting
packages, where interior points are easily selected.
To display a solid color region (with no border), the designer can choose the fill color to be
the same as the boundary color.
A boundary-fill procedure accepts as input the coordinates of an interior point (x, y), a fill
color, and a boundary color.
Starting from (x, y), the procedure tests neighboring positions to determine whether they are
of the boundary color.
If not, they are painted with the fill color, and their neighbors are tested.
Page 11 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
This process continues until all pixels up to the boundary color for the area have been tested.
Both inner and outer boundaries can be set up to specify an area, and some examples of
defining regions for boundary fill are shown in Fig. 3-42.
Figure 3-43 shows two methods for proceeding to neighboring pixels from the current test
position.
In Fig. 3-43(a), four neighboring points are tested. These are the pixel positions that are
right, left, above, and below the current pixel. Areas filled by this method are called 4-
connected.
The second method, shown in Fig. 3-43(b), is used to fill more complex figures. Here the set
of neighboring positions to be tested includes the four diagonal pixels. Fill methods using
this approach are called 8-connected.
Procedure :
void boundaryFill4(int x, int y, int fill, int boundary)
{ int current;
current = getPixel(x,y);
if((current != boundary) && (current != fill))
{ setColor (fill);
setPixel (x, y);
boundaryFill4 (x+1, y, fill, boundary);
boundaryFill4 (x-1, y, fill, boundary);
boundaryFill4 (x, y+1, fill, boundary);
boundaryFill4 (x, y-1, fill, boundary);
}
}
Page 12 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
We start from a specified interior point (x, y) and reassign all pixel values that are currently
set to a given interior color with the desired fill color.
If the area we want to paint has more than one interior color, we can first reassign pixel
values so that all interior points have the same color.
Using either a 4-connected or 8-connected approach, we then step through pixel positions
until all interior points have been repainted.
Procedure :
void floodFill4 ( int x, int y, int fillColor, int oldColor)
{
if (getPixel (x, y) == oldColor)
{
setColor (fillColor);
setPixel (x, y);
floodFill4 (x+1, y, fillColor, oldColor);
floodFill4 (x-1, y, fillColor, oldColor);
floodFill4 (x, y+1, fillColor, oldColor);
floodFill4 (x, y-1, fillColor, oldColor);
}
}
Character Generation :-
Letters, numbers, and other characters can be displayed in a variety of sizes and styles.
The overall design style for a set (or family) of characters is called a typeface. Today, there
are hundreds of typefaces available for computer applications. They are also referred to as
fonts.
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.
Typefaces (or fonts) can be divided into two broad groups: Serif and Sans serif.
Serif type has small lines or accents at the ends of the main character strokes, while sans-
serif type does not have accents.
Page 13 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Serif type is generally more readable; that is, it is easier to read in longer blocks of text. On
the other hand, the individual characters in sans-serif type are easier to recognize.
The character can be represented in two ways:
1. Bit-mapped font
2. Outline font
Bitmap font uses the frame buffer to store the value for point to be plotted as 1, and others
as 0.
It is the simple method for representing the character shapes in a particular font.
It uses rectangular grid patterns to represent the character shape.
Bitmap fonts are the simplest to define and display: The character grid only needs to be
mapped to a frame-buffer position.
Bitmap fonts require more space, because each variation (size and format) must be stored in
a font cache.
It is possible to generate different sizes and other variations, such as bold and italic, from
one set, but this usually does not produce good results.
Outline font :It is more flexible scheme to describe character shapes using straight-line and
curve sections.
The interior of the character outline must be filled using the scan-line fill procedure.
Outline fonts require less storage since each variation does not require a distinct font cache.
We can produce boldface, italic, or different sizes by manipulating the curve definitions for
the character outlines.
But it does take more time to process the outline fonts, because they must be scan converted
into the frame buffer.
There are two basic PHIGS functions used for the creation of the text:
1. text (wcPoint, string) : Parameter string is assigned a character sequence, which is then
displayed at coordinate position wcPoint = (x, y).
2. polymarker (n, wcPoints) : It places the current marker symbol to all the n number of
points, whose coordinates are given in wcPoints. For example, if marker is * and there
are 6 points specified in the wcPoints table.
Page 14 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Page 15 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Plotting dashes with a fixed number of pixels results in unequal-length dashes for different
line orientations.
Both dashes are plotted with four pixels, but the diagonal dash is longer by a factor of square
root of 2.
For precision drawings, dash lengths should remain approximately constant for any line
orientation.
To accomplish this, we can adjust the pixel counts for the solid spans and interspan spacing
according to the line slope.
Another method for maintaining dash length is to treat dashes as individual line segments.
Endpoint coordinates for each dash are located and passed to the line routine, which then
calculates pixel positions along the dash path.
2. Line width :-
The implementation of line- width options depends on the capabilities of the output device.
A line-width command is used to set the current line-width value in the attribute list. This
value 15 then used by line-drawing algorithms to control the thickness of lines.
We set the line-width attribute with the command:
SetLinewidthScaleFactor(lw) : Line-width parameter ‘lw’ is assigned a positive number to
indicate the relative width of the line to be displayed.
If a value of ‘lw’ is 1, line is of standard-width line.
If value is 0.5, the width is half of the standard line. If value is greater than 1, it produce
lines thicker than the standard.
For raster implementation, a standard-width line is generated with single pixels at each
sample position.
In raster scan, the lines of width greater than 1 are drawn by plotting the additional pixel
which are adjacent to the line.
If the width is 2, the line with (x, y) values is drawn with one more line with (x, y+1) values.
If line width is greater than 2, we select alternatively, the lines to right and left of the
standard line.
Problems :
o The horizontal and vertical lines can be perfectly drawn, but the diagonal lines will
be drawn thinner.
o Another problem is that the shapes of line at the ends are horizontal or vertical
regardless of the slope of the line.
Solution :
o We can adjust the shape of line ends by using the line caps.
Line caps : There are 3 types of line caps.
Page 16 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
1. Butt cap
2. Round cap
3. Projecting square cap
1. Butt cap : Butt cap is obtained by adjusting the end positions of the component parallel
lines, so that the thick line is displayed with square ends that are perpendicular to the line
path.
2. Round cap : Round cap is obtained by adding a filled semicircle to each butt cap. The
circular arcs are centered on the line endpoints and have a diameter equal to the line
thickness.
3. Projecting square cap : Projecting square cap is obtained by extending the line and
adding butt caps that are positioned one-half of the line width beyond the specified
endpoints.
Displaying thick lines using horizontal and vertical pixel spans, leaves pixel gaps at the
boundaries between lines of different slopes where there is a shift from horizontal spans to
vertical spans.
When two thick lines are intersecting, then also we may want to set the join into required
shape. The three types of joins are as below :
1. Miter join
2. Round join
3. Bevel join
1. Miter join : A miter join is accomplished by extending the outer boundaries of each of
the two lines until they meet.
2. Round join : A round join is produced by capping the connection between the two
segments with a circular boundary whose diameter is equal to the line width.
3. Bevel join : Bevel join is generated by displaying the line segments with butt caps and
filling in the triangular gap where the segments meet.
Pen and Brush Options : With some packages, lines can be displayed with pen or brush
selections. Options in this category include shape, size, and pattern.
Page 17 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
These shapes can be stored in a pixel mask that identifies the array of pixel positions that are
to be set along the line path.
3. Line color :-
The number of color choices depends on the number of bits available per pixel in the frame
buffer.
We set the line color value in PHlGS with the function
o SetPloylineColourIndex(lc) :The line drawn after using this function contains the line
color as lc. Nonnegative integer values, corresponding to allowed color choices, are
assigned to the line color parameter lc.
o Polyline(n, wcpoints) : This function is used to draw a polyline (more than 1 lines), where
n is the total number of lines, and the array wcpoints contains positions of end points of
those pixels.
2. Color and Grayscale Level Attribute :-
Color Level Attribute :
Various color and intensity-level options can be provided to a user, depending on the
capabilities and design objectives of a particular system.
Raster-scan systems provide a wide range of colors, while random-scan monitors typically
offer only a few color choices. Color options are numerically coded with values ranging
from 0 through the positive integers.
In a color raster system, the number of color choices available depends on the amount of
storage provided per pixel in the frame buffer.
We can store color codes directly in the frame buffer, or we can put the color codes in a
separate table and use pixel values as an index into this table.
With the direct storage scheme, whenever a particular color code is specified in an
application program, the corresponding binary value is placed in the frame buffer for each
component pixel in the output primitives to be displayed in that color.
A minimum number of colors can be provided in this scheme with 3 bits of storage per
pixel, each of which represents the presence of R,G and B, a frame buffer of which is as
shown in table.
The 8 color codes for a 3-bit per pixel frame buffer
Color Code Stored color values in frame buffer Displayed color
Red Green Blue
0 0 0 0 Black
1 0 0 1 Blue
2 0 1 0 Green
Page 18 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
3 0 1 1 Cyan
4 1 0 0 Red
5 1 0 1 Magenta
6 1 1 0 Yellow
7 1 1 1 White
Adding more bits per pixel to the frame buffer increases the number of color choices.
With a resolution of 1024 by 1024, a full-color (24-bit per pixel) RGB system needs 3
megabytes of storage for the frame buffer.
The solution to this is that we can use the color look-up table (video look-up table).
Also, the storage requirement for frame buffer is reduced by 1 MB.
The value of (x,y) is 196, and look-up table points to 2081, where the color information is
stored with the 8 bits for each color, and accordingly, intensity of 3 colors will be set.
The PHIGS function to set the color table entries is given as:
setColourRepresentation (ws, ci, colorptr)
where ws is workstation output device, ci is the color index and colorptr points to the values
of RGB ranging from 0 to 1.
Systems employing this particular lookup table would allow a user to select any 256 colors
for simultaneous display from a palette of nearly 17 million colors.
Compared to a full-color system, this scheme reduces the number of simultaneous colors
that can be displayed, but it also reduces the frame buffer storage requirements to 1
megabyte.
Some graphics systems provide 9 bits per pixel in the frame buffer, permitting a user to
select 512 colors that could be used in each display.
Advantages of color lookup table :
1. It can provide a "reasonable" number of simultaneous colors without requiring large
frame buffers.
2. For most applications, 256 or 512 different colors are sufficient for a single picture.
3. Table entries can be changed at any time.
Page 19 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Intensity Codes Stored Intensity Values in the Frame Buffer Display Grayscale
(Binary Code)
0.0 0 (00) Black
0.33 1 (01) Dark gray
0.67 2 (10) Light gray
1.0 3 (11) White
Page 20 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
2. Pattern Fill :
1. We select fill patterns with
setInteriorStyleIndex (pi)
where pattern index parameter pi specifies a table position.
For example, the following set of statements would fill the area defined in the fillarea
command with the second pattern type stored in the pattern table:
setInteriorStyle (pattern)
setInteriorStyleIndex (2)
fillArea (n, points)
2. Table entries can be created on individual output devices with
setPatternRepresentation (ws, pi, nx, ny, cp)
Parameter pi sets the pattern index number for workstation (output device) code ws, and cp
is a two-dimensional array of color codes with nx columns and ny rows.
e.g. cp[1,1] := 4; cp[2,1] := 0;
cp[1,2] := 0; cp[2,2] := 4;
Thus, setPatternRepresentation (1, 1, 2, 2, cp) means that use device no. 1, create pattern
no. 1 whose pattern is in array cp with 2 rows and 2 columns, and this pattern will produce
alternate red and black pixels.
3. When a color array cp is to be applied to fill a region, we need to specify the size of the
area that is to be covered by each element of the array. We do this by setting the
rectangular coordinate extents of the pattern:
setPatternSize (dx, dy)
where parameters dx and dy give the coordinate width and height of the array mapping.
4. A reference position for starting a pattern fill is assigned with the statement
setPatternReferencePoint (position)
where parameter position is a pointer to coordinates (xp, yp) that fix the lower left corner
of the rectangular pattern.
From this starting position, the pattern is then replicated in the x and y directions until the
defined area is covered by non-overlapping copies of the pattern array. The process of filling
an area with a rectangular pattern is called tiling and rectangular fill patterns are sometimes
referred to as tiling patterns.
3. Soft Fill :
Modified boundary-fill and flood-fill procedures that are applied to repaint areas so that the
fill color is combined with the background colors are referred to as soft-fill or tint-fill
algorithms.
One use for these fill methods is to soften the fill colors at object borders that have been
blurred to the edges.
Another is to allow repainting of a color area that was originally filled with a
semitransparent brush, where the current color is then a mixture of the brush color and the
background colors behind the area.
The linear soft-fill algorithm repaints an area that was originally painted by merging a
foreground color F with a single background color B, where F = B.
Assuming we know the values for F and B, we can determine how these colors were
originally combined by checking the current color contents of the frame buffer.
Page 21 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
The current RGB color P of each pixel within the area to be refilled is some linear
combination of F and B:
P = tF + (1 – t)B ----(1)
where the "transparency" factor t has a value between 0 and 1 for each pixel.
e. g. for t=0.2, the new color is combination of 20% of F + 80% of B.
For values of t less than 0.5, the background color contributes more to the interior color of
the region than does the fill color.
Vector Equation (1) holds for each RGB component of the colors, with
P = (PR, PG, PB), F = (FR, FG, FB), B = (BR, BG, BB) ---(2)
We can thus calculate the value of parameter t using one of the RGB color components as
Pk - Bk
t = ---------
Fk - Bk
where k = R, G, or B; and Fk = Bk.
Similar soft-fill procedures can be applied to an area whose foreground color is to be merged
with multiple background color areas, such as a checkerboard pattern.
When two background colors B1, and B2, are mixed with foreground color F, the resulting
pixel color P is
P = t0F + t1B1 + (1 – t0 – t1)B2
where the sum of the coefficients t0, t1, and (1 – t0 – t1) on the color terms must equal 1.
Pk – B1k Pk – B2k
t0 = --------- t1 = ---------
Fk – B1k Fk – B2k
4. Character Attributes :-
The appearance of displayed characters is controlled by attributes such as font, size, color,
and orientation.
Attributes can be set both for entire character strings (text) and for individual characters
defined as marker symbols.
There are two classes of attributes:
1. Text Attributes
2. Marker Attributes
1. Text Attributes :-
There are a great many text options that can be made available to graphics programmers.
There is the choice of font (or typeface). The characters in a selected font can also be
displayed with assorted underlining styles, in boldface, in italics, and in outline or shadow
styles.
1. A particular font and associated style is selected in a PHIGS program by setting an integer
code for the text font parameter tf in the function
setTextFont (tf)
2. Control of text color (or intensity) is managed from an application program with
setTextColourIndex (tc)
where text color parameter tc specifies an allowable color code.
3. We can adjust text size by scaling the overall dimensions (height and width) of characters or
by scaling only the character width.
Page 22 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
setCharacterHeight (ch)
Character Body : The distance between the bottomline and the topline of the character
body is the same for all characters in a particular size and typeface, but the body width may
vary.
Character Height : Character height is defined as the distance between the baseline and the
capline of characters.
Kerned character : Kerned characters, such as f and j typically extend beyond the
character-body limits, and letters with descenders (g, j, p, q, y) extend below the baseline.
4. The width only of text can be set with the function
setCharacterExpansionFactor (cw)
where the character-width parameter cw is set to positive real value that scales the body
width of characters.
Text height is unaffected by this attribute setting.
5. Spacing between characters is controlled separately with
setCharacterSpacing (cs)
where the character-spacing parameter cs can he assigned any real value.
e.g. Spacing0 S p a c i n g 0 . 5 S p a c i n g 1
6. The orientation for a displayed character string is set according to the direction of the
character up vector:
setCharacterUpVector (upvect)
where parameter upvect in this function is assigned two values that specify the x and y
vector components.
Text is then displayed so that the orientation of characters from baseline to capline is in the
direction of the up vector.
For example, with upvect = (1, 1), the direction of the up vector is 450.
7. An attribute parameter is set to arrange character strings vertically or horizontally with the
statement
setTextPath (tp)
where the text-path parameter tp can be assigned the value: right, left, up, or down.
Character strings can also be oriented using a combination of up-vector and text-path
specifications to produce text.
8. Alignment attribute specifies how text is to be positioned with respect to the start
coordinates. Alignment attributes are set with
setTextAligment (h, v)
Page 23 of 24
BCA SEM–V – US05DBCA21 UNIT-2 Computer Graphics
Page 24 of 24