Sections 0101, 0102, 0103 and Honors, Fall 1995
Tuesday October 24, 1995
Assigned Reading: 7.2 - 7.4
Handouts (available on-line): none
- Discussed the notion of interfaces.
- We explored the functions in the graphics library.
First, we wrote a simple program
that drew an "X" on the screen. See output.
- We wrote a program that
drew many concentric circles on the screen.
- We can also use DrawArc to draw parts of circles.
We wrote a program that
drew arcs starting a 0 degrees with increasing sweep.
See output. We also
tried a program that
always drew 90 degree arcs, but at different starting point.
This required us to use the sin and cos functions
from the math library. See output.
- This graphics package makes it particularly easy to draw
rectangles with rounded corners.
See program and
- We can also write a program
that draws more complicated objects. In this case, we drew a
pumpkin. We cleaned up
the code and wrote a program
that did not use so many magic numbers.
- We can also turn the main program of the previous version
into a function. Then, we can write a
program that calls this function
several times to draw many pumpkins.
- We can modify the program to
draw pumpkins of different sizes.
We can also modify the program
to draw pumpkins of
- Finally, we commented on this graphics package. We pointed
out that it is device independent and could be used to
generate output for the laser
printer. (Viewing this file requires a postscript previewer,
such as ghostscript on UNIX.) Another issue in
interface design is stability. If an interface keeps changing,
then programs written for previous versions of the library will
not work. For example, the DrawArc function for a previous
version of the graphics libary assumed that the pen will be at
the center of the arc rather than the arc itself. So, programs
written for this previous version will not work with the current
version of the graphics library. The old pumpkin drawing programs
produces strange output when
they are compiled with the new library.
Tue Oct 24 14:18:27 EDT 1995
Richard Chang, email@example.com