Lab: Graphics
Source: Katrin Becker, 1999
-
- Some problems lend themselves very nicely to description in terms of objects. This is one of them. This is also an example of how quickly a simple class can become large and inefficient.
-
- Approach:
- Step 1: list all properties and actions required to implement the library (pretty much done in the Assignment specification and below)
-
- Step 2: identify those things that are objects in this problem.
- Each object has:
- - responsibilities:
- - consists of .. (is/ has)
- - keeps track of...
- - behaviour:
- - what it can do
- - what it does for others
- - reports on...
-
- Step 3: identify the relationships and/or hierarchy between the classes
-
- Step 4: examine the set for message passing requirements
- - which classes need to transfer information between each other?
- - which direction is the transfer (into, out of, both ways)?
-
- Vector Graphics
- <graphics> (Sometimes called "object-oriented" graphics, though it's nothing to do with object-oriented programming). A drawing program which deals with separate shapes such as lines, polygons and text and groups of such objects as opposed to a painting program which stores only bitmaps. The advantage is that it is possible to change any element of the picture at any time since each part is stored as an independent object whereas once something in a bitmap has been overwritten it cannot in general be retrieved.
- (Source: http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?vector+graphics)
-
- The display for this assignment will be implemented as an n x m array of ASCII characters where each character represents one pixel. (Suggestion: use '*'). For the basic requirements pixels need only be "black" ('*') or "white" (' ').
-
-
- The Window:
- Typically, a screen's origin is considered to be the upper left-hand corner, and it's coordinates are (0,0).
- The X-axis increases as we move right and the Y-axis increases as we move left. Remember that a typical 2-dimensional array has the first index increase as we move down the rows and the second increasing as we move across the columns.Your program will have to compensate for this.
-
- Points:
- Points on the "screen" are addressed using (x,y) coordinates (Cartesian). Generally, Cartesian coordinates cover four quadrants:

- Shapes:
- When a Shape requires more than one Point to describe it, the other Points are given as relative to the origin ( down the screen = plus; up = minus; right = plus; left = minus ).
- When a Line is created it is specified by 2 Points in the Window (the first will be the origin).
- Suppose p1 = (10,10) and p2 = (15,5)
- The specified Points are locations in the Window. Internally, the Line's origin is (as always) (0,0) and it's endpoint could be calculated from the original specification as (5,-5). If the Line is then moved to (3,7) it's endpoint for the Window will change to (8,2) but it's internal endpoint remains unchanged.
- The following would create a new Rectangle and "position" it in the window at the given location. If W.current() were (10,10), then internally, the Rectangle would have an origin of (0,0) and it's internal (untranslated) upper right corner would be (10,-10). With this information it is possible to reposition the rectangle and figure out how to draw it.
- Rectangle ( W.current(), Point(20, 0))
- General:
- This 'system' does not need to be implemented as an interactive program, nor should it be animated in any way. It is not intended as a user application; rather it should be designed as a 'library system'. Programmers can link to this library and use its classes. Users of this utility must find a way to keep track of objects (i.e. which ones there are) themselves.
- Notes:
- It should be possible to replace the Window Class with real graphics without affecting or needing to know anything about Shapes.
-
- Minimal Requirements: for a maximum grade of C or B
- - Window, Point, Shape (abstract) classes
- - Window can be displayed
- - Implements: Dot, Line, Rectangle
- - can draw() and erase()
- - can resize()
- - can move()
- - need only work for one Window (i.e. a Shape exists in only one Window)
-
- Additional Requirements: for a maximum grade of A
- - have the Window be able to plot line segments as well as individual pixels
- - implement Circle
-
- HINTS: (for how to attack this problem)
- - design and implement the PointClass
- - design the WindowClass
- - implement it
- - TEST it
- - start the makefile for this assignment here,
- to be added to as more classes are finished
- - design the abstract ShapeClass
- - design and implement the DotClass
- - TEST it using the PointClass and WindowClass
- - using the .cc and .h files from the DotClass as a 'template'
- (in other words, copy these and edit them as appropriate)
- - design and implement the LineClass
- - TEST it as above
- - can try draw1, draw3, draw6
- - using the .cc and .h files from the LineClass as a 'template'
- - design and implement the RectangleClass
- - TEST it as above
- - can try draw2, draw5
- - using the .cc and .h files from the LineClass as a 'template'
- - design and implement the CircleClass
- - TEST it as above
- - try draw4