1 class VSTowers extends SCPattern {
2 private BasicParameter saturationParameter = new BasicParameter("SAT", 80, 0, 100);
3 private BasicParameter attackParameter = new BasicParameter("ATTK", 0.96, 0.1, 1.0);
4 private BasicParameter decayParameter = new BasicParameter("DECAY", 0.7, 0.1, 1.0);
5 private SawLFO hueLfo = new SawLFO(0, 360, 20000);
7 private Map<Tower, Boolean> towerOn;
18 t = model.towers.get(floor(random(model.towers.size())));
19 } while (towerOn.get(t));
21 hue = (hueLfo.getValuef() + 50*(random(2)-1.0f)) % 360;
23 maxVal = random(0.4) + 0.6;
26 boolean run(double deltaMs) {
28 float atk = attackParameter.getValuef();
29 float atkDuration = 10000 * (1/sqrt(atk) - 1.0f);
30 value = value + (float)deltaMs / atkDuration;
31 if (value >= maxVal) {
37 float dec = decayParameter.getValuef();
38 float decDuration = 10000 * (1/sqrt(dec) - 1.0f);
39 value = value - (float)deltaMs / decDuration;
45 public VSTowers(LX lx) {
47 addParameter(saturationParameter);
48 addParameter(attackParameter);
49 addParameter(decayParameter);
50 addModulator(hueLfo).trigger();
51 flashes = new LinkedList<TowerFlash>();
52 towerOn = new HashMap();
53 for (Tower t : model.towers) {
54 towerOn.put(t, false);
58 private List<TowerFlash> flashes;
59 private float accDelta = 0;
61 public void run(double deltaMs) {
63 float rate = lx.tempo.rampf();
64 float msPerFlash = 5000 * (1/sqrt(rate) - 1.0f);
65 if (accDelta >= msPerFlash) {
66 accDelta -= msPerFlash;
67 if (flashes.size() < model.towers.size()) {
68 flashes.add(new TowerFlash());
71 for (LXPoint p : model.points) {
72 if (random(1) < 0.2) {
76 for (TowerFlash tf : flashes) {
77 for (LXPoint p : tf.t.points) {
78 float towerHeight = model.yMin + tf.value * (model.yMax - model.yMin);
79 if (p.y <= towerHeight) {
80 colors[p.index] = lx.hsb(
81 (tf.hue + tf.value*50 - p.y/2) % 360,
82 saturationParameter.getValuef(),
87 float towerMaxHeight = model.yMin + tf.maxVal * (model.yMax - model.yMin);
88 Cube top = tf.t.cubes.get(tf.t.cubes.size()-1);
89 for (int i = tf.t.cubes.size()-1; i >= 0; --i) {
90 Cube c = tf.t.cubes.get(i);
91 float maxY = c.points.get(0).y;
92 for (LXPoint p : c.points) {
93 maxY = max(maxY, p.y);
95 if (towerMaxHeight < maxY) {
99 for (LXPoint p : top.points) {
100 if (tf.value > 0.5) {
101 colors[p.index] = lx.hsb(0, 0, tf.value*100);
102 } else if (random(1) < 0.2) {
108 // Run flashes and remove completed ones
109 Iterator<TowerFlash> it = flashes.iterator();
110 while (it.hasNext()) {
111 TowerFlash flash = it.next();
112 if (flash.run(deltaMs)) {
113 towerOn.put(flash.t, false);