Download presentation
Presentation is loading. Please wait.
Published byKelley Pope Modified over 8 years ago
1
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas k.albasheir@sau.edu.sa CS- 375 Graphics and Human Computer Interaction
2
How does computer draw line? Screen made of pixels High-level language specifies line System must color pixels
3
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.
4
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
5
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
6
Bresenham’s Algorithm Uses only integer calculations Uses distance between ideal y- coordinate and the upper and lower pixel. d upper d lower
7
Bresenham’s Algorithm 1.Input the two line endpoints and store left endpoint as (x0,y0) 2.Pre-calculate the values dx, dy, 2dy and 2dy - 2dx 3.Color pixel (x0,y0) 4.Let p 0 = 2dy – dx 5.At each x k along the line, starting with k=0: 6.Repeat Step-4 dx times If p k <0, then the next point to plot is (x k + 1,y k ), and p k+1 = p k + 2dy Otherwise, the next point to plot is (x k + 1, y k + 1), and p k+1 = pk + 2dy – 2dx
8
Bitmap font Bitmap font : A simple method for representing the character shapes in a particular typeface is to use rectangular grid pattern.
9
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. Bold Italic 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.
10
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.
11
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.