|
|
|
@ -9,27 +9,74 @@ 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<Integer> stages = new ArrayList<Integer>();
|
|
|
|
|
private int currentStage;
|
|
|
|
|
private int currentTime;
|
|
|
|
|
public Cell(int x, int y, Color C)
|
|
|
|
|
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;
|
|
|
|
|
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));
|
|
|
|
@ -37,11 +84,6 @@ public class Cell extends Object
|
|
|
|
|
currentTime = 0;
|
|
|
|
|
currentStage = 0;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String toString()
|
|
|
|
|
{
|
|
|
|
|
return "(" + xval + ", " + yval + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getX()
|
|
|
|
|
{
|
|
|
|
@ -53,29 +95,31 @@ public class Cell extends Object
|
|
|
|
|
return yval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color getColor()
|
|
|
|
|
/*public Color getColor()
|
|
|
|
|
{
|
|
|
|
|
return myColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int moveTo(int x, int y)
|
|
|
|
|
}*/
|
|
|
|
|
public Cell performTime()
|
|
|
|
|
{
|
|
|
|
|
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) {
|
|
|
|
|
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));
|
|
|
|
|
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);
|
|
|
|
@ -86,14 +130,14 @@ public class Cell extends Object
|
|
|
|
|
yval -= height;
|
|
|
|
|
currentStage = 0;
|
|
|
|
|
currentTime = 1;
|
|
|
|
|
myColor = new Color(255, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.currentStage++;
|
|
|
|
|
this.currentTime = 0;
|
|
|
|
|
if(currentStage == 1) myColor = new Color(255, 255, 0);
|
|
|
|
|
if(currentStage == 2) myColor = new Color(0, 255, 0);
|
|
|
|
|
if(currentStage == 3) myColor = new Color(0, 0, 255);
|
|
|
|
|
//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;
|
|
|
|
@ -101,39 +145,20 @@ public class Cell extends Object
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
if (currentStage == 0)
|
|
|
|
|
{
|
|
|
|
|
return p1[currentTime];
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
if (currentStage == 1)
|
|
|
|
|
{
|
|
|
|
|
return p2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Cell clone(int x, int y)
|
|
|
|
|
if (currentStage == 2)
|
|
|
|
|
{
|
|
|
|
|
Cell out = new Cell(x, y, getColor());
|
|
|
|
|
return out;
|
|
|
|
|
return p3;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
return p4;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|