Graphics Reference
In-Depth Information
Figure 1.8.
A sample function graph.
Because the values of a function may change substantially from one domain to the next
one it is important that one choose the window well; otherwise, the graph may look very tiny
or not show up at all. A simple scheme would scale the x-direction to be not much bigger than
the domain of the function and the y-direction to cover only that range of values needed for
the graph. To do the latter one should first evaluate all the points, find the maximum and
minimum of the y-value, and then adjust the y-dimension of the window to those values. Such
a scheme does have the disadvantage, however, that the window will keep changing if one
changes the domain. To avoid this one could leave it to the user to decide on the window or
pick some fixed default window that only changes if the graph moves outside it. To test whether
a graph lies entirely in the window check that all the points on it lie in the window.
Finally, to make the graph more readable it would help to show the coordinate axes with
ticks for some representative values.
1.5.3 Turtle graphics
This is another project to try out line drawing commands. Assume that a “turtle” is crawling
around in the plane ( R 2 ). A turtle is an object that is defined by a position and a direction (in
which it is looking). The standard basic commands that a turtle understands are
Forward (dist)
MoveTo (x,y)
Turn (q)
TurnTo (q)
Right (q)
The “ Forward ” procedure draws a line from the current position of the turtle to the new one,
which is a distance “dist” from the old one in the direction in which the turtle is looking. The
MoveTo ” procedure does not, but simply repositions the turtle to the real point (x,y). The
Turn ” procedure turns the turtle by the angle q specified relative to the current direction it
is looking. The “ TurnTo ” procedure is the absolute version of “ Turn .” It turns the turtle to
look in the direction that makes an angle q with the x-axis. You will be surprised at what
interesting figures can be created by a turtle. For lots more on turtle geometry and interesting
graphics that can be generated with it see [AbeD81].
Add an item to the main menu so that it now looks like:
Search WWH ::




Custom Search