] > Assignment 7: Programing SVG Pictures for the WEB (Due: Th, Nov 20)

Assignment 7: Programing SVG Pictures for the WEB (Due: Th, Nov 20)

Provide the missing definitions to the following program.

<..Paint.java..>
 import java.io.FileWriter;
 import java.io.PrintWriter;
 
 class Paint{
    public static void main(String [] args)throws Exception{
        FileWriter fileWriter = new FileWriter( args[0] );
        out = new PrintWriter( fileWriter );
        int dimen = Integer.parseInt( args[1] );
        Paint paint = new Paint();
        paint.open(dimen,dimen);
        dimen /= 2;
        int originX = dimen, originY = dimen;
        for(; dimen > 0; dimen -= 3){
           String red = random255();
           String green = random255();
           String blue = random255();
           paint.setColor( "#" + red + green + blue );
           paint.rect(originX-dimen,originY-dimen,dimen*2,dimen*2);
        }
        paint.close();
        out.close();
 }  }
-_-_-

An execution of the program with the command ‘java Paint fig.svg 300’ should produce an outcome similar to the following one (with possibly other randomly chosen colors).

Background information. SVG is a standard defined at http://www.w3.org/TR/SVG11/ for placing pictures on the web. The following example demonstrates the SVG features required for the assignment.

Notes.

Suggestion. Build your program incrementally in the following manner.

  1. For a start, add the missing fields and methods so that the program will compile and execute flawlesly, disregarding the kind of output it generates.
  2. Provide to one method at a time the needed implementation of the body. In particular,

    • The open(...) method may contribute the front part of the SVG file until, but not including, the <rect> elements.
    • The close() method may the back part </g></svg> of the file.
    • The rect(...) method may contribute a <rect> element to the output.