110 likes | 118 Views
CS- 375 Graphics and Human Computer Interaction. Lecture 2: 19/4/1435 Graphical algorithms. Lecturer/ Kawther Abas k.albasheir@sau.edu.sa. How does computer draw line?. Screen made of pixels High-level language specifies line System must color pixels. line drawing. definition :-
E N D
CS- 375 Graphics and Human Computer Interaction Lecture 2: 19/4/1435Graphical algorithms Lecturer/ Kawther Abas k.albasheir@sau.edu.sa
How does computer draw line? • Screen made of pixels • High-level language specifies line • System must color pixels
line drawing • definition :- • Given two points P and Q in the plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to make a picture of a unit-width line segment starting from P and ending at Q.
Equation for a straight line • Equation for a straight line is y= m. x + b m is the slope of the line and b is the y intercept. Given the endpoints of a line segment. m = y2-y1 / x2-x1 b= y1-m.x1
DDA Algorithm • Start with starting and ending coordinates of the line: (x0, y0) and (x1, y1) • Color first pixel (round to nearest integer) • Suppose x1-x0 > y1-y0 (gentle slope) • There will be x1-x0 steps (# pixels to be colored) • Set x=x0, y=y0 • At each step, • increment x by (x1-x0)/numsteps, and • increment y by (y1-y0)/numsteps • For each step, round off x and y to nearest integer, and color pixel
Bresenham’s Algorithm • Uses only integer calculations • Uses distance between ideal y-coordinate and the upper and lower pixel . dupper dlower
Bresenham’s Algorithm • Input the two line endpoints and store left endpoint as (x0,y0) • Pre-calculate the values dx, dy, 2dy and 2dy - 2dx • Color pixel (x0,y0) • Let p0 = 2dy – dx • At each xk along the line, starting with k=0: • Repeat Step-4 dx times If pk<0, then the next point to plot is (xk + 1,yk), and pk+1 = pk + 2dy Otherwise, the next point to plot is (xk + 1, yk + 1), and pk+1 = pk + 2dy – 2dx
Bitmap font • Bitmap font : • A simple method for representing the character shapes in a particular typeface is to use rectangular grid pattern.
Bitmap font • The character grid only need to be mapped to a frame buffer position. • Bitmap fonts required more space, because each variation (size and format) must be stored in a font cash. • The character grid only need to be mapped to a frame buffer position. • Bitmap fonts required more space, because each variation (size and format) must be stored in a font cash. Italic Bold
Outline Font • Graphic primitives such as lines and arcs are used to define the outline of each character. • Require less storage since variation does not require a distinct font cash.
Outline Font • We can produce boldface, italic, or different size by manipulating the curve definition for the character outlines. • It does take more time to process the outline fonts, because they must be scan converted into frame buffer. Outline font