import java.util.*;
import java.io.*;
import java.awt.*;
/*
* Class PlotSolution may be used to visualize the steady-
* state solution of Laplace's equation.
*
* Usage: java PlotSolution
*
* The input file contains the value of n followed by the
* (n+2)^2 cell values.
*
* Compilation: javac PlotSolution.java StdDraw.java
*
* Author: Keld Helsgaun, April 2010.
*/
public class PlotSolution {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java PlotSolution \n");
System.exit(0);
}
Locale.setDefault(Locale.ENGLISH);
Scanner scan = null;
try {
scan = new Scanner(new File(args[0]));
} catch (IOException e) {
System.out.println("No such file: " + args[0]);
System.exit(0);
}
int n = scan.nextInt();
double[][] value = new double[n + 2][n + 2];
for (int i = 0; i <= n + 1; i++)
for(int j = 0; j <= n + 1; j++)
value[i][j] = scan.nextDouble();
StdDraw.show(0);
StdDraw.setXscale(0, n + 1);
StdDraw.setYscale(0, n + 1);
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
StdDraw.setPenColor(color(value[i][j]));
StdDraw.filledSquare(i, n + 1 - j, 0.5);
}
}
StdDraw.show(0);
}
static Color color(double v) {
double H = (1 - v) * 0.5; // Hue
double S = 0.9; // Saturation
double B = 0.9; // Brightness
return Color.getHSBColor((float) H, (float) S, (float) B);
}
}