+}
+
+class L8onStrips extends SCPattern {
+ // Controls the rate of life algorithm ticks, in milliseconds
+ private BasicParameter rateParameter = new BasicParameter("DELAY", 112.5, 0.0, 1000.0);
+ // Controls if the cubes should be randomized even if something changes. Set above 0.5 to randomize cube aliveness.
+ private BasicParameter randomParameter = new BasicParameter("RAND", 0.0);
+ // Controls the brightness of dead cubes.
+ private BasicParameter deadParameter = new BasicParameter("DEAD", 25.0, 0.0, 100.0);
+ // Controls the saturation.
+ private BasicParameter saturationParameter = new BasicParameter("SAT", 90.0, 0.0, 100.0);
+
+ public final double MIN_ALIVE_PROBABILITY = 0.2;
+ public final double MAX_ALIVE_PROBABILITY = 0.9;
+
+ private final SinLFO xPos = new SinLFO(0, model.xMax, 4500);
+ private final SinLFO zPos = new SinLFO(0, model.zMax, 2500);
+
+ class StripState {
+ // Index of strip in glucose.model.strips
+ public Integer index;
+ // Boolean which describes if strip is alive.
+ public boolean alive;
+ // List of this cubes neighbors
+ public List<Integer> neighbors;
+
+ public StripState(Integer index, boolean alive, List<Integer> neighbors) {
+ this.index = index;
+ this.alive = alive;
+ this.neighbors = neighbors;
+ }
+ }
+
+ // Contains the state of all cubes by index.
+ private List<StripState> strip_states;
+ // Contains the amount of time since the last cycle of life.
+ private int time_since_last_run;
+ // Boolean describing if life changes were made during the current run.
+ private boolean any_changes_this_run;
+ // Hold the new lives
+ private List<Boolean> new_lives;
+
+ public L8onStrips(GLucose glucose) {
+ super(glucose);
+
+ //Print debug info about the strips.
+ //outputStripInfo();
+
+ initStripStates();
+ randomizeStripStates();
+ time_since_last_run = 0;
+ any_changes_this_run = false;
+ new_lives = new ArrayList<Boolean>();
+
+ addParameter(rateParameter);
+ addParameter(randomParameter);
+ addParameter(deadParameter);
+ addParameter(saturationParameter);
+
+ addModulator(xPos).trigger();
+ addModulator(zPos).trigger();
+ }
+
+ public void run(double deltaMs) {
+ Integer i = 0;
+ StripState strip_state;
+
+ any_changes_this_run = false;
+ new_lives.clear();
+ time_since_last_run += deltaMs;
+
+ for (Strip strip : model.strips) {
+ strip_state = this.strip_states.get(i);
+
+ if(shouldLightStrip(strip_state)) {
+ lightLiveStrip(strip);
+ } else {
+ lightDeadStrip(strip);
+ }
+
+ i++;
+ }
+
+ boolean should_randomize_anyway = (randomParameter.getValuef() > 0.5);
+ if(should_randomize_anyway || !any_changes_this_run) {
+ randomizeStripStates();
+ } else {
+ applyNewLives();
+ }
+
+ if(time_since_last_run >= rateParameter.getValuef()) {
+ time_since_last_run = 0;
+ }
+ }
+
+ public void lightLiveStrip(Strip strip) {
+ for (LXPoint p : strip.points) {
+ float hv = max(0, lx.getBaseHuef() - abs(p.z - zPos.getValuef()));
+ colors[p.index] = lx.hsb(
+ hv,
+ saturationParameter.getValuef(),
+ 75
+ );
+ }
+ }
+
+ public void lightDeadStrip(Strip strip) {
+ for (LXPoint p : strip.points) {
+ float hv = max(0, lx.getBaseHuef() - abs(p.x - xPos.getValuef()));
+ double dead_bright = deadParameter.getValuef() * Math.random();