You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.1 KiB
Java

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 ArrayList<Integer> stages = new ArrayList<Integer>();
private int currentStage;
private int currentTime;
private static BufferedImage[] p1 = new BufferedImage[12];
private static final BufferedImage p2;
private static final BufferedImage p3;
private static final BufferedImage p4;
static
{
for (int count = 0; count < p1.length; count++)
{
BufferedImage g1 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gg1 = g1.getGraphics();
gg1.setColor(new Color(255, 0, 0, 127));
int width;
int pos;
width = (int) ((count + 1) * 2 + 22.5);
pos = (50 - width) / 2;
gg1.fillOval(pos, pos, width, width);
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();
gs.setColor(new Color(255, 255, 0, 127));
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();
gg2.setColor(new Color(0, 255, 0, 127));
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();
gm.setColor(new Color(0, 0, 255, 127));
gm.fillOval(0, 0, 50, 50);
gm.setColor(Color.BLACK);
gm.drawOval(0, 0, 50, 50);
gm.drawString("M", 22, 30);
p4 = m;
}
public Cell(int x, int y)
{
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()
{
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);
//stages = new ArrayList<Integer>();
//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;
}
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()
{
if (currentStage == 0)
{
return p1[currentTime];
}
if (currentStage == 1)
{
return p2;
}
if (currentStage == 2)
{
return p3;
}
return p4;
}
}