X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=L8onWallace.pde;h=d3c083f95eb9dc9c0daad60b0325315e99dd74bd;hb=61f677b8fb206d040cd834fb0d8795d1eda14c9b;hp=80f8b8dfd3c888d75be884d26552aeb41763ceab;hpb=4861d6c4ade9dfa8bf3ee999b81e4d8c53f08346;p=SugarCubes.git diff --git a/L8onWallace.pde b/L8onWallace.pde index 80f8b8d..d3c083f 100644 --- a/L8onWallace.pde +++ b/L8onWallace.pde @@ -22,11 +22,14 @@ class L8onLife extends SCPattern { 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); + // Controls the number of neighbors needed to birth a new life. + private BasicParameter fertilityParameter = new BasicParameter("FERT", 2.0, 1.0, 5.0); + - public final double MIN_ALIVE_PROBABILITY = 0.1; - public final double MAX_ALIVE_PROBABILITY = 0.8; + 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, 3500); + private final SinLFO xPos = new SinLFO(0, model.xMax, 4500); // Contains the state of all cubes by index. private List cube_states; @@ -34,6 +37,8 @@ class L8onLife extends SCPattern { 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 new_lives; public L8onLife(GLucose glucose) { super(glucose); @@ -44,11 +49,13 @@ class L8onLife extends SCPattern { initCubeStates(); time_since_last_run = 0; any_changes_this_run = false; + new_lives = new ArrayList(); addParameter(rateParameter); addParameter(randomParameter); addParameter(deadParameter); - addParameter(saturationParameter); + addParameter(saturationParameter); + addParameter(fertilityParameter); addModulator(xPos).trigger(); } @@ -57,11 +64,12 @@ class L8onLife extends SCPattern { CubeState cube_state; any_changes_this_run = false; + new_lives.clear(); time_since_last_run += deltaMs; for (Cube cube : model.cubes) { cube_state = this.cube_states.get(i); - + if(shouldLightCube(cube_state)) { lightLiveCube(cube); } else { @@ -74,6 +82,8 @@ class L8onLife extends SCPattern { boolean should_randomize_anyway = (randomParameter.getValuef() > 0.5); if(should_randomize_anyway || !any_changes_this_run) { randomizeCubeStates(); + } else { + applyNewLives(); } if(time_since_last_run >= rateParameter.getValuef()) { @@ -165,39 +175,50 @@ class L8onLife extends SCPattern { // Respect rate parameter. if(time_since_last_run < rateParameter.getValuef()) { any_changes_this_run = true; - return cube_state.alive; + return cube_state.alive; } else { - return cycleOfLife(cube_state); - } + boolean new_life = cycleOfLife(cube_state); + new_lives.add(new_life); + return new_life; + } + } + + public void applyNewLives() { + int index = 0; + for(boolean liveliness: new_lives) { + CubeState cube_state = this.cube_states.get(index); + cube_state.alive = new_lives.get(index); + index++; + } } public boolean cycleOfLife(CubeState cube_state) { Integer index = cube_state.index; Integer alive_neighbor_count = countLiveNeighbors(cube_state); boolean before_alive = cube_state.alive; + boolean after_alive = before_alive; + int fetility_count = (int) fertilityParameter.getValuef(); if(cube_state.alive) { if(alive_neighbor_count < 2 || alive_neighbor_count > 3) { - cube_state.alive = false; + after_alive = false; } else { - cube_state.alive = true; + after_alive = true; } } else { - if(alive_neighbor_count == 3) { - cube_state.alive = true; + if(alive_neighbor_count == fetility_count) { + after_alive = true; } else { - cube_state.alive = false; + after_alive = false; } - } - - this.cube_states.set(index, cube_state); - - if(before_alive != cube_state.alive) { + } + + if(before_alive != after_alive) { any_changes_this_run = true; - } - - return cube_state.alive; + } + + return after_alive; } public Integer countLiveNeighbors(CubeState cube_state) {