/* * $Id: Kaleido.java,v 1.75 2007/02/09 20:05:07 rl Exp $ ********************************************************** * kaleido * * Kaleidoscopic construction of uniform polyhedra * Copyright © 1991-2007 Dr. Zvi Har’El * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * “This product includes software developed by * Dr. Zvi Har’El (http://www.math.technion.ac.il/~rl/).” * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * This software is provided ‘as-is’, without any express or implied * warranty. In no event will the author be held liable for any * damages arising from the use of this software. * * Author: * Dr. Zvi Har’El, * Deptartment of Mathematics, * Technion, Israel Institue of Technology, * Haifa 32000, Israel. * E-Mail: rl@math.technion.ac.il ********************************************************** */ package kaleido; import java.applet.AppletContext; import java.applet.AppletStub; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.URL; import java.text.DecimalFormat; import java.util.StringTokenizer; /** * Class Kaleido * @author Zvi Har’El * @version $Id: Kaleido.java,v 1.75 2007/02/09 20:05:07 rl Exp $ * @see Class source code */ public class Kaleido extends Frame implements AppletStub { Kaleido() { super("Kaleido"); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(640, 480); Scope applet = new Scope(); add("Center", applet); applet.setStub(this); applet.init(); applet.start(); show(); } public static void main(String[] argv) { /* * Process command line options */ String message[] = { Scope.version, Scope.copyright, "Usage: java kaleido.Kaleido [options] [symbols], " + "where the options are:", "-s: display polyhedra in the Standard list.", "-i: display polyhedra in an Input list (one per line).", "-l: List polyhedron names, symbols and reference figures.", "-v: print Vertex and face coordinates.", "-w: Write polyhedra as virtual reality models.", "-d digits: number of significant Digits.", "-a degrees: rotation axis Azimouth.", "-e degrees: rotation axis Elevation.", "-[pP] prefix: Prefix for file names.", "-g: display polyhedron on a Graphics monitor", "-n: display Numerical data in addition to graphical.", "-L: use a Light background.", "-[RGB]: display colors: Red, Green, Blue, or combinations.", "Unless the -s or -i options are selected, " + "the command line may contain", "polyhedron symbols: Wythoff symbols (3 fractions and a |) ", "or indices (# and an integer in the range 1 through " + Uniform.list.length + ")." }; if (argv.length == 0) usage(message); boolean justList = false, numeric = false, needCoordinates = false, needVrml = false, graphics = false; int digits = 6; int input = 0; Object in = null; String prefix = null, Prefix = null; String symbols = null; String colors = ""; for (int i = 0; i < argv.length; i++) { if (argv[i].charAt(0) == '-') { for (String s = argv[i].substring(1); s != null && s.length() != 0 ;) { char c = s.charAt(0); s = s.substring(1); switch (c) { case 'd': digits = Integer.parseInt(s); s = null; break; case 'a': System.setProperty("azimuth", s); s = null; break; case 'e': System.setProperty("elevation", s); s = null; break; case 'p': prefix = s; s = null; break; case 'P': Prefix = s; s = null; break; case 'l': justList = true; break; case 's': input = 1; break; case 'i': input = -1; break; case 'v': needCoordinates = true; numeric = true; break; case 'w': needVrml = true; needCoordinates = true; break; case 'g': graphics = true; break; case 'n': numeric = true; break; case 'R': colors += "r"; break; case 'G': colors += "g"; break; case 'B': colors += "b"; break; case 'L': colors += "l"; break; default: System.err.println("illegal option: -" + c); usage(message); } } } else if (symbols == null) symbols = argv[i]; else symbols += ";" + argv[i]; } /* * Set defaults */ if (graphics) { if (symbols != null) System.setProperty("input", symbols); if (colors != "") System.setProperty("color", colors); new Kaleido(); return; } if (symbols == null) symbols = System.getProperty("input"); if (input == 0 && symbols == null) return; if (prefix == null && Prefix == null) { Prefix = prefix = "kaleido"; } else if (prefix == null) prefix = Prefix; else if (Prefix == null) Prefix = prefix; if (!needVrml) numeric = true; if (input == 0) in = new StringTokenizer(symbols.toString(),".,;:"); else if (input < 0) in = new BufferedReader(new InputStreamReader(System.in)); int i = 0; while (true) { String sym; if (in instanceof StringTokenizer) { try { sym = (String) ((StringTokenizer) in).nextToken(); } catch (Exception e) { break; } } else if (in instanceof BufferedReader) { try { sym = ((BufferedReader) in).readLine(); if (sym == null) break; } catch (Exception e) { break; } } else if (i < Uniform.list.length) { sym = "#" + ++i; } else break; Output poly = new Output(sym); if (numeric) poly.print(justList, needCoordinates, digits); if (needVrml) { poly.write(prefix, true, digits); poly.write(Prefix, false, digits); } } } private static void usage(String[] message) { for (int i = 0; i < message.length; i++) System.err.println(message[i]); System.exit (1); } public String getParameter(String name) { return System.getProperty(name.toLowerCase()); } public void appletResize(int width, int height) {} public AppletContext getAppletContext() {return null; } public URL getCodeBase() { return null; } public URL getDocumentBase() { return null; } public boolean isActive() { return true; } }