diff --git a/bin/MapProjections.class b/bin/MapProjections.class index 8affc70..6278d4d 100644 Binary files a/bin/MapProjections.class and b/bin/MapProjections.class differ diff --git a/output/myMap.jpg b/output/myMap.jpg index 33df4c5..db2d709 100644 Binary files a/output/myMap.jpg and b/output/myMap.jpg differ diff --git a/src/MapProjections.java b/src/MapProjections.java index 52b5142..c848963 100644 --- a/src/MapProjections.java +++ b/src/MapProjections.java @@ -44,91 +44,123 @@ public class MapProjections { - public static void main(String[] args) throws IOException { + public static void main(String[] args) { Scanner in = new Scanner(System.in); String response; System.out.println("Welcome to the map configurer. You will be asked for a seiries of values. Leaving the field blank at any time will set values to default."); - BufferedImage input; + BufferedImage input, output; int w; double x2y; double latD, lonD, thtD; int projection; - System.out.println("First, enter a file name, or choose a preset map style:"); - for (int i = 0; i < FILE.length; i ++) - System.out.println(MAP_TYPES.charAt(i)+" --- "+FILE[i]); - response = in.nextLine(); - if (response.length() == 0) - response = "s"; - final int index = MAP_TYPES.indexOf(response); // checks for presets - if (index >= 0) // reads equirectangular from file - input = ImageIO.read(new File("input/"+FILE[index]+".jpg")); - else if (response.indexOf(".") >= 0) - input = ImageIO.read(new File("input/"+response)); - else - input = ImageIO.read(new File("input/"+response+".jpg")); - - System.out.println("And what aspect ratio would you like? (Please enter as a decimal)"); - response = in.nextLine(); - if (response.length() == 0) - response = "1"; - x2y = Double.parseDouble(response); - System.out.println("Pixel width?"); - response = in.nextLine(); - if (response.length() == 0) - response = "800"; - w = Integer.parseInt(response); - BufferedImage output = new BufferedImage(w,(int)(w/x2y),BufferedImage.TYPE_INT_RGB); - - System.out.println("Would you like to use a preset axis, or custom?"); - for (int i = 0; i < AXIS_NAMES.length; i ++) - System.out.println(AXES.charAt(i)+" --- "+AXIS_NAMES[i]); - response = in.nextLine(); - if (response.length() == 0) - response = "s"; - int i = AXES.indexOf(response); - if (i > 0) { // if it is a preset - latD = lats[i-1]; - lonD = lons[i-1]; - thtD = thts[i-1]; - } - else { - System.out.println("What is the latitude of your desired axis? [-90, 90]"); - response = in.nextLine(); - if (response.length() == 0) - response = "90"; - latD = Double.parseDouble(response); - System.out.println("Longitude? [-180, 180]"); - response = in.nextLine(); - if (response.length() == 0) - response = "0"; - lonD = Double.parseDouble(response); - System.out.println("What about your orientation? [-180, 180]"); - response = in.nextLine(); - if (response.length() == 0) - response = "0"; - thtD = Double.parseDouble(response); + while (true) { + try { + System.out.println("First, enter a file name, or choose a preset map style:"); + for (int i = 0; i < FILE.length; i ++) + System.out.println(MAP_TYPES.charAt(i)+" --- "+FILE[i]); + response = in.nextLine(); + if (response.length() == 0) + response = "s"; + final int index = MAP_TYPES.indexOf(response); // checks for presets + if (index >= 0) // reads equirectangular from file + input = ImageIO.read(new File("input/"+FILE[index]+".jpg")); + else if (response.indexOf(".") >= 0) + input = ImageIO.read(new File("input/"+response)); + else + input = ImageIO.read(new File("input/"+response+".jpg")); + + break; + } catch (IOException e) { + System.out.println("I don't like that response. Enter something else."); + } } - System.out.println("Finally, pick a projection:"); - System.out.println(EQUIRECTANGULAR+" --- Equirectangular"); - System.out.println(MERCATOR +" --- Mercator"); - System.out.println(GALL +" --- Gall Stereographic"); - System.out.println(EA_CYLINDER +" --- Cylindrical Equal-Area"); - System.out.println(POLAR +" --- Polar"); - System.out.println(STEREOGRAPHIC +" --- Stereographic"); - System.out.println(EA_AZIMUTH +" --- Azimuthal Equal-Area"); - System.out.println(ORTHOGONAL +" --- Orthogonal"); - System.out.println(CONICAL +" --- Lambert Conic"); - System.out.println(QUINCUNCIAL +" --- Peirce Quincuncial"); - System.out.println(SINUSOIDAL +" --- Sinusoidal"); - System.out.println(LEMONS +" --- BURN LIFE'S HOUSE DOWN"); + while (true) { + try { + System.out.println("And what aspect ratio would you like? (Please enter as a decimal)"); + response = in.nextLine(); + if (response.length() == 0) + response = "1"; + x2y = Double.parseDouble(response); + System.out.println("Pixel width? I strongly recommend at least 400."); + response = in.nextLine(); + if (response.length() == 0) + response = "800"; + w = Integer.parseInt(response); + output = new BufferedImage(w,(int)(w/x2y),BufferedImage.TYPE_INT_RGB); + + break; + } catch (Error e) { + System.out.println("I don't like that response. Enter something else."); + } + } - response = in.nextLine(); - if (response.length() == 0) - response = Integer.toString(QUINCUNCIAL); - projection = Integer.parseInt(response); + while (true) { + try { + System.out.println("Would you like to use a preset axis, or custom?"); + for (int i = 0; i < AXIS_NAMES.length; i ++) + System.out.println(AXES.charAt(i)+" --- "+AXIS_NAMES[i]); + response = in.nextLine(); + if (response.length() == 0) + response = "s"; + int i = AXES.indexOf(response); + if (i > 0) { // if it is a preset + latD = lats[i-1]; + lonD = lons[i-1]; + thtD = thts[i-1]; + } + else { + System.out.println("What is the latitude of your desired axis? [-90, 90]"); + response = in.nextLine(); + if (response.length() == 0) + response = "90"; + latD = Double.parseDouble(response); + System.out.println("Longitude? [-180, 180]"); + response = in.nextLine(); + if (response.length() == 0) + response = "0"; + lonD = Double.parseDouble(response); + System.out.println("What about your orientation? [-180, 180]"); + response = in.nextLine(); + if (response.length() == 0) + response = "0"; + thtD = Double.parseDouble(response); + } + + break; + } catch (Error e) { + System.out.println("I don't like that. Enter something else."); + } + } + + while (true) { + try { + System.out.println("Finally, pick a projection:"); + System.out.println(EQUIRECTANGULAR+" --- Equirectangular"); + System.out.println(MERCATOR +" --- Mercator"); + System.out.println(GALL +" --- Gall Stereographic"); + System.out.println(EA_CYLINDER +" --- Cylindrical Equal-Area"); + System.out.println(POLAR +" --- Polar"); + System.out.println(STEREOGRAPHIC +" --- Stereographic"); + System.out.println(EA_AZIMUTH +" --- Azimuthal Equal-Area"); + System.out.println(ORTHOGONAL +" --- Orthogonal"); + System.out.println(CONICAL +" --- Lambert Conic"); + System.out.println(QUINCUNCIAL +" --- Peirce Quincuncial"); + System.out.println(SINUSOIDAL +" --- Sinusoidal"); + System.out.println(LEMONS +" --- BURN LIFE'S HOUSE DOWN"); + + response = in.nextLine(); + if (response.length() == 0) + response = Integer.toString(QUINCUNCIAL); + projection = Integer.parseInt(response); + + break; + } catch (Error e) { + System.out.println("I don't like that response. Enter something else."); + } + } System.out.println("Wait..."); map(input,output,projection,latD,lonD,thtD); @@ -228,7 +260,9 @@ public class MapProjections { public static int lemons(final double lat0, final double lon0, final double orientation, final int width, final int height, int x, int y, BufferedImage ref) { // a simple map that is shaped like lemons - int lemWdt = width/12; // the pixel width of each lemon + int lemWdt; + if (width > 12) lemWdt= width/12; // the pixel width of each lemon + else lemWdt = width; if (Math.abs(x%lemWdt-lemWdt/2.0) < Math.sin(Math.PI*y/height)*lemWdt/2.0) // if it is inside a sin curve return getColor(lat0,lon0,orientation, y*Math.PI/height - Math.PI/2, diff --git a/src/Vector.java~ b/src/Vector.java~ deleted file mode 100644 index c66d1ad..0000000 --- a/src/Vector.java~ +++ /dev/null @@ -1,153 +0,0 @@ -public final class Vector { - public static final Vector I = new Vector(1,0,0,true); - public static final Vector J = new Vector(0,1,0,true); - public static final Vector K = new Vector(0,0,1,true); - - - private double r; // magnitude - private double a; // altitude from horizontal - private double b; // bearing - - - - public Vector(double newX, double newY, double newZ, boolean cartesian) { // constructs a new vector given horizontal, vertical, and depthual lengths - r = Math.sqrt(newX*newX + newY*newY + newZ*newZ); - a = Math.asin(newZ/r); // Z is the positive direction - b = Math.atan2(newY,newX); - } - - - public Vector(double newR, double newAlpha, double newBeta) { // constructs a new vector given magnitude, altitude, and bearing - r = newR; - a = newAlpha; - b = newBeta; - } - - - - public final void setR(double newR) { - r = newR; - } - - - public final void setA(double newAlpha) { - a = newAlpha; - } - - - public final void setB(double newBeta) { - b = newBeta; - } - - - public final double getX() { // magnitude of the width component - return r*Math.cos(a)*Math.cos(b); - } - - - public final double getY() { // magnitude of the depth component - return r*Math.cos(a)*Math.sin(b); - } - - - public final double getZ() { // magnitude of the height component - return r*Math.sin(a); - } - - - public final double getR() { // magnitude - return r; - } - - - public final double getA() { // altitude - return a; - } - - - public final double getB() { // bearing - return b; - } - - - public final Vector negative() { // computes the opposite - return new Vector(r, -a, (2*Math.PI+b)%(2*Math.PI)); - } - - - public final Vector plus(Vector that) { // computes sum with that - return new Vector(this.getX()+that.getX(), this.getY()+that.getY(), this.getZ()+that.getZ(), true); - } - - - public final Vector minus(Vector that) { // computes difference with that - return new Vector(this.getX()-that.getX(), this.getY()-that.getY(), this.getZ()-that.getZ(), true); - } - - - public final Vector times(double c) { // computes product with c - return new Vector(c*r, a, b); - } - - - public final double dot(Vector that) { // computes dot product with that - return this.getX()*that.getX() + this.getY()*that.getY() + this.getZ()*that.getZ(); - } - - - public final Vector cross(Vector that) { // computes cross product with that - return new Vector(this.getY()*that.getZ() - this.getZ()*that.getY(), - this.getZ()*that.getX() - this.getX()*that.getZ(), - this.getX()*that.getY() - this.getY()*that.getX(), true); - } - - - public final Vector hat() { // makes the magnitude 1 - return new Vector(1, getA(), getB()); - } - - - public final void negate() { // negates - a = -a; - b = (2*Math.PI+b)%(2*Math.PI); - } - - - public final void plusEquals(Vector that) { // adds that - Vector sum = this.plus(that); - r = sum.getR(); - a = sum.getA(); - b = sum.getB(); - } - - - public final void minusEquals(Vector that) { // subtracts that - Vector dif = this.minus(that); - r = dif.getR(); - a = dif.getA(); - b = dif.getB(); - } - - - public final void timesEquals(double c) { // multiplies by c - r *= c; - } - - - public final void crossEquals(Vector that) { // becomes cross product with that - Vector txt = this.cross(that); - r = txt.getR(); - a = txt.getA(); - b = txt.getB(); - } - - - public final String toString() { - return "<"+getX()+", "+getY()+", "+getZ()+">"; - } - - - public final String toStringPolar() { - return "("+getR()+", "+getA()+", "+getB()+")"; - } -} \ No newline at end of file