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: */ public class Cell extends Object { private int xval; private int yval; private Color myColor; private ArrayList stages = new ArrayList(); private int currentStage; private int currentTime; public Cell(int x, int y, Color C) { xval = x; yval = y; myColor = C; 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; } @Override public String toString() { return "(" + xval + ", " + yval + ")"; } public int getX() { return xval; } public int getY() { return yval; } public Color getColor() { return myColor; } public int moveTo(int x, int y) { xval = x; yval = y; return 0; } public Cell performTime() { this.currentTime ++; Cell newcell = this; //System.out.println("Increased Current Time to:" + this.currentTime); if(this.currentTime > stages.get(this.currentStage)) { if(currentStage == 3) { // SPLIT int width = (int) (-50 + Math.random()*101); int height = (int) (-50 + Math.random()*101); while (width < 20 && width > -20) width = (int) (-50 + Math.random()*101); while (height < 20 && height > -20) height = (int) (-50 + Math.random()*101); newcell = new Cell(xval + width, yval + height, new Color(255, 0, 0, 100)); //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; currentTime = 1; myColor = new Color(255, 0, 0, 100); } 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() { Image canvas = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); Graphics g = canvas.getGraphics(); g.setColor(this.getColor()); int width = 50; int pos = 0; if (currentStage == 0) { width = (int) ((currentTime + 1) * 2 + 22.5); pos = (50 - width) / 2; } g.fillOval(pos, pos, width, width); g.setColor(Color.BLACK); g.drawOval(pos, pos, width, width); StringBuilder x = new StringBuilder(""); if(currentStage == 0) x.append("G1"); if(currentStage == 1) x.append("S"); if(currentStage == 2) x.append("G2"); if(currentStage == 3) x.append("M"); g.drawString(x.toString(), 20, 30); return canvas; } public Cell clone(int x, int y) { Cell out = new Cell(x, y, getColor()); return out; } public Cell combine(Cell in) { int r = (this.getColor().getRed() + in.getColor().getRed()) / 2; int g = (this.getColor().getGreen() + in.getColor().getGreen()) / 2; int b = (this.getColor().getBlue() + in.getColor().getBlue()) / 2; Cell out = new Cell((in.getX() + this.getX())/2, (in.getY() + this.getY())/2, new Color(r, g, b)); return out; } }