/**** * * StringArt * * draws figures like those you get by wrapping colored string around nails * set in a cirle. * ****/ import java.awt.*; import jpb.*; class StringArt { // The various dimensions and what-not. private final static int WINDOW_SIZE = 400; private final static String WINDOW_TITLE = "String Art"; // This should be prime. private final static int NPOINTS = 31; // Arrays of (x,y) coordinates. private static double[] x = new double[NPOINTS+1]; private static double[] y = new double[NPOINTS+1]; private final static double X_MAX = 1.1; private final static double X_MIN = -1.1; private final static double Y_MAX = 1.1; private final static double Y_MIN = -1.1; // These two variables are used by all the various subroutines. // Make sure they're initialized (in main()) before doing anything else. private static DrawableFrame df; private static Graphics g; // Convert from (x,y) coordinates to pixels in the horizontal direction. private static int xToPix(double x){ return (int)( ( x - X_MIN ) / ( X_MAX - X_MIN ) * WINDOW_SIZE); } // Convert from (x,y) coordinates to pixels in the vertical direction. private static int yToPix(double y){ return (int)( ( Y_MAX - y ) / ( Y_MAX - Y_MIN ) * WINDOW_SIZE); } private static void myLine(double x1, double y1, double x2, double y2){ g.drawLine( xToPix(x1), yToPix(y1), xToPix(x2), yToPix(y2) ); } // Evenly spaced points around a circle. private static void initArrays(){ for (int i=0; i