package cancergrowth; import java.awt.Color; import java.awt.Image; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.lang.Math; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Scanner; /* * File Name: Cell.java * Created: Nov 7, 2018 * Author: Cole Deck and Phillip Augustynowicz * * Additional comments can be found in the document submitted by Phillip. */ public class Cell extends Object { private int xval; // Declare variables like position, cycle timing private int yval; private ArrayList stages = new ArrayList(); int currentStage; private int currentTime; private static final BufferedImage p0; private static BufferedImage[] p1 = new BufferedImage[12]; // Create cell images before the widnow opens private static final BufferedImage p2; private static final BufferedImage p3; private static final BufferedImage p4; int splits = 0; static { boolean transparent = true; for (int count = 0; count < p1.length; count++) { BufferedImage g1 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); // Use buffers to preload all possible images Graphics gg1 = g1.getGraphics(); if (transparent) // Check if we want transparency { gg1.setColor(new Color(255, 0, 0, 127)); } else { gg1.setColor(new Color(255, 0, 0)); } int width; int pos; width = (int) ((count + 1) * 2 + 22.5); pos = (50 - width) / 2; gg1.fillOval(pos, pos, width, width); // Draw and fill an oval with a border and text in the middle gg1.setColor(Color.BLACK); gg1.drawOval(pos, pos, width, width); gg1.drawString("G1", 18, 30); p1[count] = g1; } BufferedImage s = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); Graphics gs = s.getGraphics(); if (transparent) { gs.setColor(new Color(255, 255, 0, 127)); } else { gs.setColor(new Color(255, 255, 0)); } gs.fillOval(0, 0, 50, 50); gs.setColor(Color.BLACK); gs.drawOval(0, 0, 50, 50); gs.drawString("S", 22, 30); p2 = s; BufferedImage g2 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); Graphics gg2 = g2.getGraphics(); if (transparent) { gg2.setColor(new Color(0, 255, 0, 127)); } else { gg2.setColor(new Color(0, 255, 0)); } gg2.fillOval(0, 0, 50, 50); gg2.setColor(Color.BLACK); gg2.drawOval(0, 0, 50, 50); gg2.drawString("G2", 18, 30); p3 = g2; BufferedImage m = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); Graphics gm = m.getGraphics(); if (transparent) { gm.setColor(new Color(0, 0, 255, 127)); } else { gm.setColor(new Color(0, 0, 255)); } gm.fillOval(0, 0, 50, 50); gm.setColor(Color.BLACK); gm.drawOval(0, 0, 50, 50); gm.drawString("M", 22, 30); p4 = m; BufferedImage g0 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); Graphics gg0 = g0.getGraphics(); if (transparent) { gg0.setColor(new Color(165, 0, 255, 127)); } else { gm.setColor(new Color(165, 0, 255)); } gg0.fillOval(0, 0, 50, 50); gg0.setColor(Color.BLACK); gg0.drawOval(0, 0, 50, 50); gg0.drawString("WBC", 12, 30); p0 = g0; } public Cell(int x, int y) // Constructor { xval = x; yval = y; stages.add(10 + (int) (Math.random() * 3 - 1)); stages.add(6 + (int) (Math.random() * 3 - 1)); stages.add(3 + (int) (Math.random() * 3 - 1)); stages.add(1 + (int) (Math.random() * 2)); currentTime = 0; currentStage = 0; } public int getX() { return xval; } public int getY() { return yval; } /*public Color getColor() { return myColor; }*/ public Cell performTime(boolean run) // Perform the simulation for this cell { if (!run || currentStage == 4) // If we are gonna kill the cells, a protein is received and the cells enter gap0. { // They are then eaten by a macrophage (white blood cell), represented by pacman. if (run) { currentStage = 0; } else { int random = (int) (Math.random() * 10); if (random == 0) { currentStage = 4; // gap0 = stage 4 in my code } return this; } } this.currentTime++; // increase elapsed time Cell newcell = this; //System.out.println("Increased Current Time to:" + this.currentTime); if (this.currentTime > stages.get(this.currentStage)) // Check if it's time to change phases { if (currentStage == 3) { splits ++; // If we need to split this code runs int width = (int) (-50 + Math.random() * 101); //randomize splitting direction int height = (int) (-50 + Math.random() * 101); while (width < 20 && width > -20) { // continue randomization if the cell don't split far enough (inside each other) width = (int) (-50 + Math.random() * 101); } while (height < 20 && height > -20) { height = (int) (-50 + Math.random() * 101); } newcell = new Cell(xval + width, yval + height); // create a daughter cell //stages = new ArrayList(); //stages.add(10 + (int) Math.random() * 3 - 1); //stages.add(7 + (int) Math.random() * 3 - 1); //stages.add(3 + (int) Math.random() * 3 - 1); //stages.add(1 + (int) Math.random() * 2); xval -= width; yval -= height; currentStage = 0; // have this cell become a daughter cell currentTime = 1; } else { this.currentStage++; this.currentTime = 0; //if(currentStage == 1) myColor = new Color(255, 255, 0, 100); //if(currentStage == 2) myColor = new Color(0, 255, 0, 100); //if(currentStage == 3) myColor = new Color(0, 0, 255, 100); } } return newcell; } public Image getImage() { // return the static images if (currentStage == 0) { return p1[currentTime]; } if (currentStage == 1) { return p2; } if (currentStage == 2) { return p3; } if (currentStage == 3) { return p4; } return p0; } }