Input/Output: Graph Paper

Screen Shot 2015-02-23 at 12.19.21 AM

Classwork:
Write a program, MyGraphPaper_YI.java similar to CheckerBoard.java from below but to draw 2 different kinds of graph paper. Think of what graph paper you would use in a math class.

Study program CheckerBoard.java that takes a command-line argument N and plots an N-by-N checkerboard with red and black squares. It colors the lower left square red.

[spoiler title=’Checkerboard.java’]
Below is the syntax highlighted version of Checkerboard.java from §1.5 Input and Output.

/******************************************************************************
 *  Compilation:  javac Checkerboard.java 
 *  Execution:    java Checkerboard n
 *  Dependencies: StdDraw.java
 *
 *  Plots an n-by-n checkerboard.
 *
 ******************************************************************************/

public class Checkerboard { 

    public static void main(String[] args) { 
        int n = Integer.parseInt(args[0]);
        StdDraw.setXscale(0, n);
        StdDraw.setYscale(0, n);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if ((i + j) % 2 != 0) StdDraw.setPenColor(StdDraw.BLACK);
                else                  StdDraw.setPenColor(StdDraw.RED);
                StdDraw.filledSquare(i + 0.5, j + 0.5, 0.5);
            }
        }
    }

}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne. 
Last updated: Fri Oct 20 14:12:12 EDT 2017.

[/spoiler]


RandomBlock_YI.java Animation
Use the tools from the BouncingBall program to implement RandomBlock_YI.java. This program re-uses the program from the graph paper assignment and randomly select squares on the grid that will become a solid color or “alive” and then randomly it will become back to white or “dead” again.