Unformatted: Simon.java.

  1  /*
  2   * Copyright (C) 2007  Lassi project
  3   *
  4   * This file is part of Lassi; you can redistribute it and/or modify
  5   * it under the terms of the GNU General Public License as published by
  6   * the Free Software Foundation; either version 2 of the License, or
  7   * (at your option) any later version.
  8   *
  9   * Lassi is distributed in the hope that it will be useful,
 10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12   * GNU General Public License for more details.
 13   *
 14   * You should have received a copy of the GNU General Public License
 15   * along with Lassi; if not, write to the Free Software
 16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 17   *
 18   * http://www.lassi.be
 19   */
 20  
 21  package help.pages.tutorials.java;
 22  
 23  import java.awt.Color;
 24  
 25  import be.lassi.domain.Fixture;
 26  import be.lassi.domain.FixtureDefinition;
 27  import be.lassi.domain.FixtureGroups;
 28  import be.lassi.domain.Fixtures;
 29  import be.lassi.domain.NamedColor;
 30  import be.lassi.lanbox.domain.MixMode;
 31  import be.lassi.lanbox.domain.Time;
 32  
 33  /**
 34   * Builds cuelists for the lighting effects for the production
 35   * of "Simon Vedelaar" (May 2009): chases on 9 LED bars (with
 36   * three segments each, mounted in a fan-like shape.
 37   */
 38  public class Simon extends CueListBuilder {
 39  
 40      private static final int START_ADDRESS = 70;
 41  
 42      private static final int BAR_COUNT = 9;
 43      private static final int SEGMENTS_PER_BAR = 3;
 44  
 45      private final Fixtures conventionals = new Fixtures();
 46      private final Fixtures segments = new Fixtures();
 47      private final Fixtures strobes = new Fixtures();
 48      private final Fixtures dimmers = new Fixtures();
 49  
 50      private final FixtureGroups bars = new FixtureGroups(BAR_COUNT);
 51      private final FixtureGroups circles = new FixtureGroups(SEGMENTS_PER_BAR);
 52  
 53      public static void main(final String[] args) {
 54          new Simon().buildCueLists();
 55      }
 56  
 57      public void buildCueLists() {
 58          buildFixtures();
 59          setupLayers();
 60          baseLine();
 61          dimmersOn();
 62          dimmersOff();
 63          stop();
 64          wiper1();
 65          wiper2();
 66          threeCircleWiper();
 67          cycleColors(1, 500, 1000);
 68          cycleColors(2, 2000, 4000);
 69          wheel();
 70          random("RED");
 71          random("GREEN");
 72          random("BLUE");
 73          random("YELLOW");
 74          random("CYAN");
 75          random("MAGENTA");
 76          radiator();
 77          rainbow("SLOW", 500);
 78          rainbow("FAST", 50);
 79  
 80          writeCueLists();
 81  
 82          System.out.println("Ready");
 83      }
 84  
 85      private void buildFixtures() {
 86          int address = 1;
 87          for (int i=0; i < START_ADDRESS - 1; i++) {
 88              conventionals.add(dimmer(address++));
 89          }
 90          for (Fixtures bar : bars) {
 91              for (Fixtures circle : circles) {
 92                  Fixture segment = rgb(address);
 93                  segments.add(segment);
 94                  circle.add(segment);
 95                  bar.add(segment);
 96                  address += 3;
 97              }
 98              strobes.add(dimmer(address++));
 99              dimmers.add(dimmer(address++));
100          }
101      }
102  
103      private void setupLayers() {
104          createCueList("SETUP");
105  
106          resetLayer(LAYER_A);
107          resetLayer(LAYER_B);
108          resetLayer(LAYER_C);
109          resetLayer(LAYER_D);
110  
111          setLayerMixMode(LAYER_A, MixMode.HTP);
112          setLayerMixMode(LAYER_B, MixMode.HTP);
113          setLayerMixMode(LAYER_C, MixMode.HTP);
114          setLayerMixMode(LAYER_D, MixMode.COPY);
115      }
116  
117      private void baseLine() {
118          createCueList("BASELINE");
119          setIntensity(conventionals, 0);
120          setIntensity(dimmers, 0);
121          setIntensity(strobes, 0);
122          setColor(segments, Color.BLACK);
123          crossFade(seconds(2), Time.FOREVER);
124      }
125  
126      private void dimmersOn() {
127          createCueList("DIMMERS\nON");
128          setIntensity(dimmers, 100);
129          crossFade(seconds(2), Time.FOREVER);
130      }
131  
132      private void dimmersOff() {
133          createCueList("DIMMERS\nOFF");
134          setIntensity(dimmers, 0);
135          crossFade(seconds(2), Time.FOREVER);
136      }
137  
138      private void stop() {
139          createCueList("STOP");
140          resetLayer(LAYER_A);
141      }
142  
143      private void wiper1() {
144          createCueList("WIPER1");
145          Time holdTime = millis(50);
146          Colors colors = new Colors("red", "green", "blue", "yellow");
147          for (Color color : colors) {
148              for (Fixtures bar : bars) {
149                  setColor(bar, color);
150                  hold(holdTime);
151              }
152              for (Fixtures bar : bars.reversed()) {
153                  setColor(bar, color);
154                  hold(holdTime);
155              }
156          }
157          loopTo(1, 10);
158      }
159  
160      private void wiper2() {
161          createCueList("WIPER2");
162          Time time = millis(150);
163          Colors colors = new Colors();
164          Color color = colors.next();
165          Colors barColors = new Colors(color, bars.size());
166          for (int i=0; i < 4; i++) {
167              color = colors.next();
168              for (int j=0; j < bars.size(); j++) {
169                  barColors.set(j, color);
170                  setColors(bars, barColors);
171                  hold(time);
172              }
173              color = colors.next();
174              for (int j=bars.size() - 1; j > 0; j--) {
175                  barColors.set(j, color);
176                  setColors(bars, barColors);
177                  hold(time);
178              }
179          }
180          loopTo(1, 10);
181      }
182  
183      private void threeCircleWiper() {
184          createCueList("3 CIRCLE\nWIPER");
185  
186          Fixtures fixtures = new Fixtures();
187          fixtures.addAll(circles.get(0));
188          fixtures.addAll(circles.get(1).reversed());
189          fixtures.addAll(circles.get(2));
190  
191          Colors colors = new Colors("green", "blue", "red");
192          Colors fixtureColors = new Colors(colors.last(), fixtures.size());
193          for (Color color : colors) {
194              for (int i=0; i < fixtures.size(); i++) {
195                  fixtureColors.set(i, color);
196                  setColors(fixtures, fixtureColors);
197                  hold(millis(50));
198              }
199          }
200          loopTo(1, 10);
201      }
202  
203      private void cycleColors(final int id, final int fadeMillis, final int holdMillis) {
204          createCueList("CYCLE\nCOLORS " + id);
205          Time fadeTime = millis(fadeMillis);
206          Time holdTime = millis(holdMillis);
207          Colors colors = new Colors();
208          for (Color color : colors) {
209              setColor(segments, color);
210              crossFade(fadeTime, holdTime);
211          }
212          loopTo(1, 10);
213      }
214  
215      private void wheel() {
216          createCueList("WHEEL");
217          FixtureGroups spokeGroups = buildSpokeGroups();
218          int cueStepNumber = nextCueStepNumber();
219          for (Color color : new Colors()) {
220              for (Fixtures spokeGroup : spokeGroups) {
221                  setColor(spokeGroup, color);
222                  hold(millis(100));
223              }
224              loopTo(cueStepNumber, 10);
225              cueStepNumber = nextCueStepNumber();
226          }
227          loopTo(1, 10);
228      }
229  
230      private FixtureGroups buildSpokeGroups() {
231          Fixtures spokeGroup1 = new Fixtures();
232          spokeGroup1.addAll(bars.get(0));
233          spokeGroup1.addAll(bars.get(3));
234          spokeGroup1.addAll(bars.get(6));
235  
236          Fixtures spokeGroup2 = new Fixtures();
237          spokeGroup2.addAll(bars.get(1));
238          spokeGroup2.addAll(bars.get(4));
239          spokeGroup2.addAll(bars.get(7));
240  
241          Fixtures spokeGroup3 = new Fixtures();
242          spokeGroup3.addAll(bars.get(2));
243          spokeGroup3.addAll(bars.get(5));
244          spokeGroup3.addAll(bars.get(8));
245  
246          FixtureGroups spokeGroups = new FixtureGroups();
247  
248          spokeGroups.add(spokeGroup1);
249          spokeGroups.add(spokeGroup2);
250          spokeGroups.add(spokeGroup3);
251  
252          return spokeGroups;
253      }
254  
255      private void random(final String colorName) {
256          createCueList("RANDOM\n" + colorName);
257          Color color = NamedColor.getColor(colorName);
258          for (Fixture segment : segments.shuffled()) {
259              setColor(segment, color);
260              hold(millis(50));
261          }
262          loopTo(1, 10);
263      }
264  
265      private void radiator() {
266          createCueList("RADIATOR");
267          for (Color color : new Colors()) {
268              for (Fixtures circle : circles) {
269                  setColor(circle, color);
270                  hold(millis(250));
271              }
272          }
273          loopTo(1, 10);
274      }
275  
276      private void rainbow(final String name, final int time) {
277          createCueList(name + "\nRAINBOW");
278          Time fadeTime = millis(time);
279          Time holdTime = fadeTime;
280  
281          int steps = 30;
282          float start = 0.0f;
283          float delta = 1.0f/ steps;
284  
285          for (int i=0 ; i < steps; i++) {
286              for (int j=0 ; j < bars.size(); j++) {
287                  float hue = start + (j * 0.1f);
288                  if (hue > 1f) {
289                      hue -= 1f;
290                  }
291                  Color color = colorWithHue(hue);
292                  setColor(bars.get(j), color);
293              }
294              crossFade(fadeTime, holdTime, true);
295              start += delta;
296              if (start > 1.0f) {
297                  start = start - 1f;
298              }
299          }
300          loopTo(1, 100);
301      }
302  
303      private Fixture rgb(final int address) {
304          FixtureDefinition definition = new FixtureDefinition();
305          definition.addAttribute("Red", "1");
306          definition.addAttribute("Green", "2");
307          definition.addAttribute("Blue", "3");
308          return new Fixture(definition, "", address);
309      }
310  
311      private Fixture dimmer(final int address) {
312          FixtureDefinition definition = new FixtureDefinition();
313          definition.addAttribute("Intensity", "1");
314          return new Fixture(definition, "", address);
315      }
316  }