1 / 11

Lecture 2: 19/4/1435 Graphical algorithms

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 :-

jmullens
Download Presentation

Lecture 2: 19/4/1435 Graphical algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS- 375 Graphics and Human Computer Interaction Lecture 2: 19/4/1435Graphical algorithms Lecturer/ Kawther Abas k.albasheir@sau.edu.sa

  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 . dupper dlower

  7. 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

  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. • 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

  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. Outline font

More Related