add comments to Cell.java

master
shark 5 years ago
parent 3875069d47
commit 2d7bfd6344

@ -18,25 +18,25 @@ import java.util.Scanner;
public class Cell extends Object public class Cell extends Object
{ {
private int xval; private int xval; // Declare variables like position, cycle timing
private int yval; private int yval;
private ArrayList<Integer> stages = new ArrayList<Integer>(); private ArrayList<Integer> stages = new ArrayList<Integer>();
private int currentStage; private int currentStage;
private int currentTime; private int currentTime;
private static final BufferedImage p0; private static final BufferedImage p0;
private static BufferedImage[] p1 = new BufferedImage[12]; private static BufferedImage[] p1 = new BufferedImage[12]; // Create cell images before the widnow opens
private static final BufferedImage p2; private static final BufferedImage p2;
private static final BufferedImage p3; private static final BufferedImage p3;
private static final BufferedImage p4; private static final BufferedImage p4;
static static
{ {
boolean transparent = true; boolean transparent = true;
for (int count = 0; count < p1.length; count++) for (int count = 0; count < p1.length; count++)
{ {
BufferedImage g1 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); BufferedImage g1 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); // Use buffers to preload all possible images
Graphics gg1 = g1.getGraphics(); Graphics gg1 = g1.getGraphics();
if (transparent) if (transparent) // Check if we want transparency
{ {
gg1.setColor(new Color(255, 0, 0, 127)); gg1.setColor(new Color(255, 0, 0, 127));
} }
@ -48,7 +48,7 @@ public class Cell extends Object
int pos; int pos;
width = (int) ((count + 1) * 2 + 22.5); width = (int) ((count + 1) * 2 + 22.5);
pos = (50 - width) / 2; pos = (50 - width) / 2;
gg1.fillOval(pos, pos, width, width); gg1.fillOval(pos, pos, width, width); // Draw and fill an oval with a border and text in the middle
gg1.setColor(Color.BLACK); gg1.setColor(Color.BLACK);
gg1.drawOval(pos, pos, width, width); gg1.drawOval(pos, pos, width, width);
gg1.drawString("G1", 18, 30); gg1.drawString("G1", 18, 30);
@ -117,7 +117,7 @@ public class Cell extends Object
p0 = g0; p0 = g0;
} }
public Cell(int x, int y) public Cell(int x, int y) // Constructor
{ {
xval = x; xval = x;
yval = y; yval = y;
@ -143,10 +143,10 @@ public class Cell extends Object
{ {
return myColor; return myColor;
}*/ }*/
public Cell performTime(boolean run) public Cell performTime(boolean run) // Perform the simulation for this cell
{ {
if (!run || currentStage == 4) 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) if (run)
{ {
currentStage = 0; currentStage = 0;
@ -156,39 +156,39 @@ public class Cell extends Object
int random = (int) (Math.random() * 10); int random = (int) (Math.random() * 10);
if (random == 0) if (random == 0)
{ {
currentStage = 4; currentStage = 4; // gap0 = stage 4 in my code
} }
return this; return this;
} }
} }
this.currentTime++; this.currentTime++; // increase elapsed time
Cell newcell = this; Cell newcell = this;
//System.out.println("Increased Current Time to:" + this.currentTime); //System.out.println("Increased Current Time to:" + this.currentTime);
if (this.currentTime > stages.get(this.currentStage)) if (this.currentTime > stages.get(this.currentStage)) // Check if it's time to change phases
{ {
if (currentStage == 3) if (currentStage == 3)
{ {
// SPLIT // If we need to split this code runs
int width = (int) (-50 + Math.random() * 101); int width = (int) (-50 + Math.random() * 101); //randomize splitting direction
int height = (int) (-50 + Math.random() * 101); int height = (int) (-50 + Math.random() * 101);
while (width < 20 && width > -20) while (width < 20 && width > -20)
{ { // continue randomization if the cell don't split far enough (inside each other)
width = (int) (-50 + Math.random() * 101); width = (int) (-50 + Math.random() * 101);
} }
while (height < 20 && height > -20) while (height < 20 && height > -20)
{ {
height = (int) (-50 + Math.random() * 101); height = (int) (-50 + Math.random() * 101);
} }
newcell = new Cell(xval + width, yval + height); newcell = new Cell(xval + width, yval + height); // create a daughter cell
//stages = new ArrayList<Integer>(); //stages = new ArrayList<Integer>();
//stages.add(10 + (int) Math.random() * 3 - 1); //stages.add(10 + (int) Math.random() * 3 - 1);
//stages.add(7 + (int) Math.random() * 3 - 1); //stages.add(7 + (int) Math.random() * 3 - 1);
//stages.add(3 + (int) Math.random() * 3 - 1); //stages.add(3 + (int) Math.random() * 3 - 1);
//stages.add(1 + (int) Math.random() * 2); //stages.add(1 + (int) Math.random() * 2);
xval -= width; xval -= width;
yval -= height; yval -= height;
currentStage = 0; currentStage = 0; // have this cell become a daughter cell
currentTime = 1; currentTime = 1;
} }
else else
@ -204,7 +204,7 @@ public class Cell extends Object
} }
public Image getImage() public Image getImage()
{ { // return the static images
if (currentStage == 0) if (currentStage == 0)
{ {
return p1[currentTime]; return p1[currentTime];

Loading…
Cancel
Save