This assignment expands on the shapes hierarchy and the VectorCanvas assignments.
Storing information about a vector canvas in a file
A VectorCanvas can store its information in a file. However, we will need to define a "file format" for that file. The following shows the contents of a file that represents the contents of a specific VectorCanvas:
20,20,.
l,2,2,7,7,W
r,7,7,12,10,X
l,5,2,10,7,Y
c,13,12,5,Z
Each line in the file contains several values separated by commas (,). The lines in the file are interpreted as follows:
- The first line in the file represents the canvas itself. In the file above, the canvas is 20 by 20 and has a default background made up of periods (.).
- Every other line in the file represents a specific object on the canvas. The first item on each line represents the type of the object. For example, the 2nd line in the file represents a line drawn from the point 2,2 to the point 7,7.
- The 3rd line represents a rectangle whose upper left hand corner is at the point 7,7, the width of the rectangle is 12, its height is 10 and it is drawn using X's.
- The 4th line in the file represents another line drawn from the point 5,2 to the point 10,7. The line is drawn using Y's.
- The last line in the file above represents a circle centered at the point 13,12 with a radius of 5 and drawn using the letter Z
Storing information about a vector canvas in a file
Write a new program that reads the information from a file that is formatted as shown above. The program should display in ENGLISH what is represented in the file. For example, given the file above, the program should display the messages shown below. NOTE: to do this assignment you do NOT need to modify or use any of the classes from the earlier assignments. We will be incorporating this functionality into the VectorCanvas class in a subsequent assignment.
Canvas
dimensions: 20 by 20
background: .
Line
first point: 2,2
2nd point: 7,7
color: W
Rectangle:
upper left hand corner at: 7,7
width: 12
height: 10
color: X
Line
first point: 5,2
2nd point: 10,7
color: Y
Circle
center point: 13,12
radius: 5
color: Z