Professional Documents
Culture Documents
Fill
Color tables
Anti aliasing of primitives and area
Line attributes
Thick
Multiple lines (covering adjacent pixels) drawn
This can be done by plotting pixels on the line and
additional pixels
Dash
n pixels on the line plotted and next n pixels not plotted
and so on
First and last pixel should be plotted
Dotted
Plot alternate pixels. Cover last point
Draw short stretches of dash
Circle/Ellipse attributes
Thick
Two concentric circles can be drawn and area in
between can be filled
As you plot pixels on the circle some adjacent pixels
can be plotted too
Dash
n pixels on the plotted and next n pixels not plotted
Arc
Beginning and ending angles of the arc specified and
polar coordinates are used to plot points on the arc
Fill attributes
Fill styles
Hollow
Solid
Pattern
Hatch
Plot (12, 24), (12, 25), find but not plot (11,
26), (10, 27), plot (10, 28), (9, 29), (8, 30)
Line attributes
dashline(xa, ya, xb, yb, c, d)
dx=abs(xb-xa), dy=abs(yb-ya)
d1=2*dy, d2=2*dy-2*dx, p= 2*dy-dx
If xa < xb, xinc=1 endif If xa=xb, xinc=0 endif If xa > xb, xinc=-1 endif
If ya < yb yinc=1 endif If ya=yb, yinc=0 endif If ya > yb, yinc=-1 endif
x=xa, y=ya, setpixel(x, y, c)
ctr1=1, ctr2=0
For i=1 to dx-1 in steps of 1
x=x+xinc
If p>=0 then y= y+yinc, p=p+d2
Else p=p+d1 Endif
If ctr1 0 then
setpixel(x, y, c), ctr1=ctr1+1
Else ctr2=ctr2+1 Endif
If ctr1=d+1 then ctr1=0, ctr2=1
If ctr2=d+1 then ctr2=0, ctr1=1
End for
setpixel(x,y,c)
setpixel(xb, yb, c)
End dashline
Line attributes
thickline(xa, ya, xb, yb, c, 3) //abs m <1
dx=abs(xb-xa), dy=abs(yb-ya)
d1=2*dy, d2=2*dy-2*dx, p= 2*dy-dx
If xa < xb, xinc=1 endif If xa=xb, xinc=0 endif If xa > xb, xinc=-1
endif
If ya < yb yinc=1 endif If ya=yb, yinc=0 endif If ya > yb, yinc=-1
endif
x=xa, y=ya, setpixel(x, y, c), setpixel(x,y-1,c), setpixel(x, y+1, c)
For i=1 to dx in steps of 1
x=x+xinc
If p>=0 then y= y+yinc, p=p+d2
Else p=p+d1 Endif
setpixel(x, y, c), setpixel(x,y-1,c), setpixel(x, y+1, c)
End for
End thickline
Circle attributes
Thick circle
1/8 of the circle is generated from (0,r). Here x
varies more than y. If (x1, y1) is a plotted by
algorithm also plot (x1, y1-1) and (x1, y1+1).
However for the symmetrical point (y1, x1) plot
additional two points (y1-1, x1) and (y1+1, x1).
Note that (y1, x1) is in the region where y
varies more than x. Do similar additional point
plots for other parts of the circle.
Circle attributes
thickcircle (h,k,c,3)
x=0, y=r, p=1-r
setpixel(x+h, y+k, c), setpixel(x+h, y+k-1,c), setpixel(x+h, y+k+1)
setpixel(x+h, -y+k, c), setpixel(x+h, -y+k-1,c), setpixel(x+h, -y+k+1)
setpixel(y+h, x+k, c), setpixel(y+h-1, x+k, c), setpixel(y+h+1, x+k, c)
setpixel(-y+h, x+k, c), setpixel(-y+h-1, x+k, c), setpixel(-y+h+1, x+k, c)
while (x<=y)
x=x+1
if p>=0 then y=y-1, p=p+2x-2y+1,
else p=p+2x+1
endif
setpixel(x+h, y+k,c ), setpixel(x+h, y+k-1,c ), setpixel(x+h, y+k+1,c)
setpixel(y+h, x+k,c), setpixel(y+h-1, x+k,c), setpixel(y+h+1, x+k,c)
setpixel(x+h, -y+k,c), setpixel(x+h, -y+k-1,c), setpixel(x+h, -y+k+1,c)
setpixel(y+h, -x+k, c), setpixel(y+h-1, -x+k, c), setpixel(y+h+1, -x+k, c)
setpixel(-x+h, -y+k,c), setpixel(-x+h, -y+k-1,c), setpixel(-x+h, -y+k+1,c)
setpixel –y+h, -x+k, c), setpixel –y+h-1, -x+k, c), setpixel –y+h+1, -x+k, c)
setpixel(-x+h, y+k,c), setpixel(-x+h, y+k-1,c), setpixel(-x+h, y+k+1,c)
setpixel (-y+h, x+k, c), setpixel (-y+h-1, x+k, c), setpixel (-y+h+1, x+k, c)
endwhile
Circle attributes
Arc
Is portion of a circle. Difficult to specify end
points on the arc
Assuming that angles are measured from
positive x axis in anti clock wise direction,
user inputs the beginning and ending angle
of the arc
Points on the arcs are generated using polar
coordinates of circle
Circle attributes
arc(h, k, r, c, a1, a2)
for phi=a1 to a2 in steps of
x=round(r*cos(phi)), y=round(r*sin(phi))
setpixel(x+h, y+k, c)
endfor
end arc
Color table
Frame buffers have RGB values of each pixel or codes of colors
corresponding to pixels
The table of codes is called color lookup table or video lookup
table
Suppose for a graphics system each color has one bit, (frame
buffer has three bits per pixel) the color lookup table for such
system is given here
Here there is no reduction in frame buffer size even with codes
Code 0 1 2 3 4 5 6 7
RGB 000 001 010 011 100 101 110 111
Color black blue green cyan red magenta yellow white
Color table
In the example of 7 colors, first bit controls red gun, middle
bit controls green gun and right bit controls blue gun
Adding more bits per pixel will increase the number of color
choices
With 6 bits per pixel 2 bits are allotted for each color
component, giving 4 intensity settings (4 shades on display
device) to each color
Total of 64 colors are available to each pixel
For a full color system (24 bits- one byte per color
component) a screen resolution of 1024 x 1024 requires 3
megabytes for frame buffer
Color tables provide extended color capabilities without
large size frame buffer
Color table
Display device
Color table
0
1
196
255
Color table
Systems using this particular color table would allow user to select any of
256 colors in the table for simaltaneous display
Whereas the full color system has 17 million colors
17 million to 256 colors is not a serious restriction, since not more than
256 are used at a time on the display device
There is advantage in using table like this since it reduces size of frame
buffer
Some graphics system uses 9 bits per pixel in the frame buffer allowing
512 colors for display at a time
For most applications 256 to 512 colors at a time is sufficient
Pattern
setInteriorStyleIndex(pi)
pi specifies a table position
setInteriorStyle(pattern)
setInteriorStyle Index(1)
fillArea(n, points)
Fill attributes
Fill style patters for individual workstations can be created
using
setPatternRepresentation(ws, pi, nx, ny, cp)
Methods to improve look of the object on the display are called antialiasing methods
Instead of calculating y at every integral x, y may be calculated for more x (atleast twice the
pixel
In this method not all positions on the line will have same intensity
Super sampling straight lines for gray scale display- find sub pixels along the lie path.