Spectrum.java


This is the syntax highlighted version of Spectrum.java from 3.1 Using Data Types of
Introduction to Computer Science by Robert Sedgewick and Kevin Wayne.


/*************************************************************************
 *  Compilation:  javac Spectrum.java
 *  Execution:    java Spectrum N
 *  Dependencies: Picture.java
 *
 *  Plots an N-by-N spectrum of colors using raster graphics.
 *
 *************************************************************************/

import java.awt.Color;

public class Spectrum { 

    public static void main(String[] args) { 
        int N = Integer.parseInt(args[0]);
        Picture pic = new Picture(N, N);
        for (int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                int r = (i * 256) / N;
                int g = 128;
                int b = (j * 256) / N;
                Color c = new Color(r, g, b);
                pic.setColor(i, j, c);
            }
        }
//        pic.show();
        pic.save("temp.png");
    }

}


Last updated: Fri Jul 16 15:45:57 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.