Graphics Reference
In-Depth Information
Draw (point or rectangle,
(attribute is typically a color but could be
attribute)
something more general)
DrawLine (point, point)
(draws raster version of line segment from first
point to second in “current” color and mode)
Write (string, point)
(write a string into the raster at pixel location
point)
Note that erasing a point or rectangle is really the same as drawing it in the “back-
ground” color. We list the “Erase” procedure separately only for conceptual reasons.
Also, drawing a rectangle or a line segment could be implemented with the “Draw
(point)” procedure, but all current graphics APIs have efficient procedures for drawing
rectangles and line segments directly and that is why we list that procedure separately.
We shall show how the DrawLine procedure is implemented in terms of “Draw
(point)” in Chapter 2. Of course, drawing lines is a very basic operation that typically
is called many times. It is a place where optimization really pays off and is best imple-
mented in assembly language, or better yet, in hardware. Therefore, when coding pro-
grams one should use the line drawing procedure that comes with the software.
The primitives above can easily be implemented using any given API. We believe,
however, that they will make our abstract code more readable. In any case, whatever
system the reader is working on, it is assumed that he/she can implement these pro-
cedures. These primitives are all that we shall need to describe all of the algorithms
in this topic.
1.7
E XERCISES
Section 1.5
1.5.1
Find the equations for the following transformations:
(a)
T: [-1,3] Æ [5,6]
(b)
T: [2,7] Æ [3,1]
(c)
T: [-1,2] ¥ [3,5] Æ [5,7] ¥ [-3,-4]
(d)
T: [7,-2] ¥ [1,2] Æ [3,2] ¥ [0,3]
1.8
P ROGRAMMING P ROJECTS
Section 1.5
In these programming assignments assume that the user's world is the plane. We also assume
the reader has a basic windowing program with an easily extensible menu system. The GM
program is one such and the user interface in the projects below fits naturally into that program.
Furthermore, the term “screen” in the projects below will mean the window on the real screen
in which the program is running. All projects after the first one (Project 1.5.1) assume that a
window-to-viewport transformation has been implemented.
1.5.1
A window-to-viewport transformation
The goal of this first project is simply to write and test the window-to-viewport transformation.
The main menu should add another item to the list:
Search WWH ::




Custom Search