import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; import java.lang.Math.*; public class Virus extends Applet { ControlPanel controls; public void init() { setLayout(new BorderLayout()); DisplayCanvas c = new DisplayCanvas(); add("Center", c); add("North", controls = new ControlPanel(c)); } public void start() { controls.setEnabled(true); } public void stop() { controls.setEnabled(false); } public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { System.exit(0); } return false; } public static void main(String args[]) { Frame f = new Frame("Virus"); Virus virus = new Virus(); virus.init(); virus.start(); f.add("Center", virus); f.setSize(900, 400); f.show(); } } class DisplayCanvas extends Canvas { static final int SIZE = 200; static int FOCAL_RADIUS = 20; static int MAX_AGE = 5; static double INIT_RATE = 0.10; static double INFECT_RATE = 0.10; static final int normal_cell = 0; static final int red_v = 1; static final int new_red_v = 2; static final int old_red_v = 3; static final int green_v = 4; static final int new_green_v = 5; static final int old_green_v = 6; static Color darkgreen = Color.green.darker(); static int timestep, randchoice; Random randval = new Random(); int[][] cell_state = new int[2*SIZE-1][]; int[][] cell_age = new int[2*SIZE-1][]; public DisplayCanvas() { for (int row=0; row 0) { //Loop for number of replications timestep++; iterations--; for (int row=1; row 0) cell_state[row][col] = new_green_v; } else { if (Math.abs( randval.nextInt())%(redcount+greencount) < redcount) cell_state[row][col] = new_red_v; else cell_state[row][col] = new_green_v; } } for (int col=1; col 0) cell_state[SIZE-1][col] = new_green_v; } else { if (Math.abs( randval.nextInt())%(redcount+greencount) < redcount) cell_state[SIZE-1][col] = new_red_v; else cell_state[SIZE-1][col] = new_green_v; } } for (int row=SIZE; row<2*SIZE-2; row++) for (int col=1; col 0) cell_state[row][col] = new_green_v; } else { if (Math.abs( randval.nextInt())%(redcount+greencount) < redcount) cell_state[row][col] = new_red_v; else cell_state[row][col] = new_green_v; } } for (int row=1; row<2*SIZE-2; row++) for (int col=1; col