package net.perdue.setisim; /** * COPYRIGHT 2002 TIM PERDUE * RELEASED UNDER GPL (GNU General Public License) * * PLEASE CONTRIBUTE YOUR CHANGES TO tim@perdue.net * * Creation date: (9/15/2002 4:00:47 PM) * @author: Tim Perdue */ import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.*; public class Plotter extends Applet implements Runnable { private Galaxy galaxy; private int iterations = 1000; Thread runner; Font f = new Font("Courier",Font.BOLD,18); /** * Plotter constructor comment. */ public Plotter() { //super("Galaxy Plot"); //Set the size for the frame. setSize(800,600); setVisible(true); /*addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {dispose(); System.exit(0);} });*/ } /** * Insert the method's description here. * Creation date: (9/15/2002 9:15:32 PM) * @return int * @param civ net.perdue.setisim.Civilization */ private int convertX(Civilization civ) { int x = (int)( (double)civ.getBaseX() / (double)(civ.getGalaxy().getRadius() / (getSize().width /2)) ); /*if (x > getSize().width) { System.out.println("Warning Out of Bounds: X=" + x); }*/ return x; } /** * Insert the method's description here. * Creation date: (9/15/2002 9:15:32 PM) * @return int * @param civ net.perdue.setisim.Civilization */ private int convertY(Civilization civ) { int y = (int)( (double)civ.getBaseY() / (double)(civ.getGalaxy().getRadius() / (getSize().height /2)) ); /*if (y > getSize().height) { System.out.println("Warning Out of Bounds: Y=" + y); }*/ return y; } /** * Insert the method's description here. * Creation date: (9/15/2002 8:58:28 PM) * @return int * @param civ net.perdue.setisim.Civilization */ public int getCircleSize(Civilization civ) { double circleWidth = (double)civ.getRadius() / (double)(civ.getGalaxy().getRadius() / (getSize().width /2)); //System.out.println("divWidth: " + getScaleFactor(civ)); //System.out.println("circleWidth: " + (int)circleWidth); if (circleWidth < 1) { return 2; } else { return (int)circleWidth; } } /** * Insert the method's description here. * Creation date: (9/15/2002 8:59:05 PM) * @return Galaxy */ public Galaxy getGalaxy() { return galaxy; } /** * Insert the method's description here. * Creation date: (9/16/2002 3:31:15 PM) * @return int */ public int getIterations() { return iterations; } /** * Insert the method's description here. * Creation date: (9/16/2002 12:28:09 PM) */ public void init() { Galaxy gal = new Galaxy(); setGalaxy(gal); gal.setR(Integer.parseInt(getParameter("R"))); gal.setFs(new Double(getParameter("fs")).doubleValue()); gal.setFp(new Double(getParameter("fp")).doubleValue()); gal.setNe(Integer.parseInt(getParameter("ne"))); gal.setFl(new Double(getParameter("fl")).doubleValue()); gal.setFi(new Double(getParameter("fi")).doubleValue()); gal.setFc(new Double(getParameter("fc")).doubleValue()); gal.setL(Integer.parseInt(getParameter("L"))); gal.setPermanenceThreshold(Integer.parseInt(getParameter("permanence"))); gal.setSpeed(new Double(getParameter("speed")).doubleValue()); gal.setSpeedFactor(new Double(getParameter("speedFactor")).doubleValue()); setIterations(Integer.parseInt(getParameter("iterations"))); } /** * Starts the application. * @param args an array of command-line arguments */ public static void main(java.lang.String[] args) { // Insert code to start the application here. new Plotter(); } public void paint(Graphics g) { Civilization civ = null; //draw rim of galaxy g.setColor(new Color(0,0,64)); g.fillOval(0,0,getSize().width,getSize().height); //draw center of galaxy g.setColor(new Color(175,175,90)); int x=getSize().width/2 - getSize().width/20; int y=getSize().height/2 - getSize().height/20; int size=getSize().height/10; g.fillOval(x,y,size,size); if (!getGalaxy().getCivilizations().isEmpty()) { //Image bg = getImage(getDocumentBase(), "edited-ngc1232-2.jpg"); //g.drawImage(bg, 0, 0, Color.black, this); g.setColor(Color.white); g.setFont(f); g.drawString("Year: " + (long)getGalaxy().getYear() + " Live: " + getGalaxy().getLiveCount() + " Dead: " + getGalaxy().getDeadCount(),5,20); g.setColor(Color.red); Enumeration e = getGalaxy().getCivilizations().elements(); while (e.hasMoreElements()) { try { civ = (Civilization) e.nextElement(); if (civ.getEndYear() == 0) { int circleSize = getCircleSize(civ); g.drawOval( convertX(civ) - (circleSize / 2), convertY(civ) - (circleSize / 2), circleSize, circleSize); } } catch (Exception ex) { ex.printStackTrace(); } } } } /** * When an object implementing interface Runnable is used * to create a thread, starting the thread causes the object's * run method to be called in that separately executing * thread. *

* The general contract of the method run is that it may * take any action whatsoever. * * @see java.lang.Thread#run() */ public void run() { setBackground(Color.black); for (int i = 0; i < getIterations(); i++) { /*System.out.println( "Year: " + (long) getGalaxy().getYear() + " Civ.count: " + getGalaxy().getCivilizations().size());*/ repaint(); getGalaxy().calc(); } System.out.println( "Done - Year: " + (long) getGalaxy().getYear() + " Live Civ. count: " + getGalaxy().getLiveCount()); } /** * Insert the method's description here. * Creation date: (9/15/2002 8:59:05 PM) * @param newGalaxy Galaxy */ private void setGalaxy(Galaxy newGalaxy) { galaxy = newGalaxy; } /** * Insert the method's description here. * Creation date: (9/16/2002 3:31:15 PM) * @param newIterations int */ public void setIterations(int newIterations) { iterations = newIterations; } /** * Insert the method's description here. * Creation date: (9/16/2002 3:35:00 PM) */ public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } runner.setPriority(runner.MIN_PRIORITY); } public void update(Graphics g) { //paint(g); super.update(g); } }