-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ripples.java
50 lines (44 loc) · 1.33 KB
/
Ripples.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import javafx.scene.paint.Color;
import java.util.List;
/**
* Challenge Task #4
*
* This life form works slightly different from the others such that its only purpose is to provide
* a visually appealing ripple like rainbow effect when ran for multiple generations.
*
* @author Ahmet Taramis (K22038914)
*/
public class Ripples extends Cell {
// Starting hue value for the color cycle
private float hue;
/**
* Create a new Ripple life form.
*
* @param field The field currently occupied.
* @param location The location within the field.
* @param col The colour of the cell
*/
public Ripples(Field field, Location location) {
super(field, location, Color.WHITE);
hue = 0;
setColor(Color.hsb(hue, 1, 1));
}
/**
* This is how the Ripple cell's decides its behaviour
*/
public void act() {
List<Cell> neighbours = getField().getLivingNeighbours(getLocation());
if (neighbours.size() >= 2) {
hue += 20;
if (hue >= 360) {
hue = 0; // Reset hue after completing a full cycle
}
setColor(Color.hsb(hue, 1, 1));
setNextState(true);
} else {
hue = 0;
setColor(Color.hsb(hue, 1, 1));
setNextState(false);
}
}
}