1 /**************************************************************
3 **************************************************************/
5 import java.util.LinkedList;
6 class AKPong extends SCPattern
8 private final BasicParameter speed = new BasicParameter("Speed", 0);
9 private final BasicParameter leftKnob = new BasicParameter("Left", 0.5);
10 private final BasicParameter rightKnob = new BasicParameter("Right", 0.5);
11 private final float R = 20;
12 private final float W = 20;
13 private final float H = 80;
14 private final float PADDLE_STEP = 5;
15 private float oldLeft = leftKnob.getValuef();
16 private float oldRight = rightKnob.getValuef();
18 private Paddle left = new Paddle(model.xMin, model.cy - H / 2, model.xMin + W, model.cy + H / 2);
19 private Paddle right = new Paddle(model.xMax - W, model.cy - H / 2, model.xMax, model.cy + H / 2);
20 private Ball ball = new Ball();
25 public Paddle(float x1, float y1, float x2, float y2)
26 { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; }
27 public boolean contains(LXPoint p)
28 { return p.x > x1 && p.x < x2 && p.y > y1 && p.y < y2; }
31 float adj = 9 * speed.getValuef();
32 if (y2 + PADDLE_STEP < model.yMax)
34 y1 += PADDLE_STEP + adj;
35 y2 += PADDLE_STEP + adj;
43 public void moveDown()
45 float adj = 15 * speed.getValuef();
46 if (y2 - PADDLE_STEP > model.yMin)
48 y1 -= PADDLE_STEP + adj;
49 y2 -= PADDLE_STEP + adj;
58 public void moveTo(float y)
60 y1 = (model.yMax - H) * y;
61 y2 = (model.yMax * y + H *(1 - y));
67 float x = model.cx, y = model.cy, z = model.cz;
68 int xDir = 1, yDir = 1;
70 public boolean contains(LXPoint p)
71 { return sqrt(sq(p.x - ball.x) + sq(p.y - y) + sq(p.z - z)) < R; }
78 // Collision with floor/ceiling
79 if (y + R > model.yMax || y - R < model.yMin)
81 // Collision with right wall
82 if (x + R > model.xMax)
84 // Check if paddle is here
85 if (y < right.y2 && y > right.y1)
90 // Collision with left wall
91 if (x - R < model.xMin)
93 // Check if paddle is here
94 if (y < left.y2 && y > left.y1)
99 x += xDir + xDir * 9 * speed.getValuef();
100 y += yDir + yDir * 9 * speed.getValuef();
105 public boolean noteOn(Note note)
107 switch (note.getPitch())
109 case 49: // W -> left paddle up
112 case 50: // S -> left paddle down
115 case 61: // O -> right paddle up
118 case 62: // L -> right paddle down
129 addParameter(leftKnob);
130 addParameter(rightKnob);
133 public void run(double deltsMs)
135 float newLeft = leftKnob.getValuef();
136 float newRight = rightKnob.getValuef();
138 if (newLeft != oldLeft)
140 left.moveTo(newLeft);
143 if (newRight != oldRight)
145 right.moveTo(newRight);
150 for (LXPoint p : model.points)
152 if (ball.contains(p))
153 colors[p.index] = lx.hsb(ball.c, 100, 100);
154 else if (left.contains(p))
155 colors[p.index] = lx.hsb(0, 0, 100);
156 else if (right.contains(p))
157 colors[p.index] = lx.hsb(0, 0, 100);
165 ///////////////////////////////////////////////////////////////////////////////
167 /**************************************************************
169 **************************************************************/
171 class AKInvader extends SCPattern
173 private final SawLFO h = new SawLFO(0, 1, 5000);
174 public AKInvader(LX lx)
177 addModulator(h).trigger();
180 public void run(double deltaMs)
182 color c = lx.hsb(h.getValuef() * 360, 100, 100);
183 int nTowers = model.towers.size();
184 int tower = nTowers / 2;
186 for (int cube = 1; cube <= 3; ++cube)
187 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
191 for (int cube = 2; cube <= 3; ++cube)
192 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
194 // for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
195 // colors[p.index] = c;
198 for (int cube = 1; cube <= 5; ++cube)
199 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
203 for (LXPoint p : model.towers.get(tower).cubes.get(0).points)
205 for (int cube = 2; cube <= 3; ++cube)
206 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
208 for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
212 for (int cube = 2; cube <= 5; ++cube)
213 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
217 for (LXPoint p : model.towers.get(tower).cubes.get(0).points)
219 for (int cube = 2; cube <= 3; ++cube)
220 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
222 for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
226 for (int cube = 1; cube <= 5; ++cube)
227 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
231 for (int cube = 2; cube <= 3; ++cube)
232 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
234 // for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
235 // colors[p.index] = c;
238 for (int cube = 1; cube <= 3; ++cube)
239 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
245 class AKTetris extends SCPattern
247 // Movement increments
248 private final float STEP_Y = 1;
249 private final float STEP_X = 10;
251 private final float D = 10;
253 private Shape shape = new Box();
257 float x, y; // Block position, lower left corner
258 public Block(float x, float y)
267 List<Block> blocks; // Blocks comprising this shape
268 float x, y; // Shape position, lower left corner
269 float h, w; // Effective Shape dimensions
272 public boolean contains(LXPoint p)
274 for (Block b : blocks)
275 if (p.x > b.x && p.x < b.x + D && p.y > b.y && p.y < b.y + D)
280 public void dropDown(float inc)
282 for (Block b : blocks)
287 public void moveLeft(float inc)
289 for (Block b : blocks)
294 public void moveRight(float inc)
296 for (Block b : blocks)
302 class Box extends Shape
311 blocks = new LinkedList<Block>();
312 blocks.add(new Block(model.cx - D, model.yMax));
313 blocks.add(new Block(model.cx, model.yMax));
314 blocks.add(new Block(model.cx - D, model.yMax + D));
315 blocks.add(new Block(model.cx, model.yMax + D));
317 c = lx.hsb(0, 100, 100);
318 x = model.cx - w / 2;
323 public AKTetris(LX lx)
328 public boolean noteOn(Note note)
330 switch (note.getPitch())
332 case 48: // A -> left
333 shape.moveLeft(STEP_X);
335 case 52: // D -> right
336 shape.moveRight(STEP_X);
342 public void run(double deltaMs)
344 for (LXPoint p : model.points)
346 if (shape.contains(p))
347 colors[p.index] = shape.c;
351 if (shape.y > model.yMin)
352 shape.dropDown(STEP_Y);
357 class AKMatrix extends SCPattern
359 private List<TowerStrip> towerStrips = new ArrayList<TowerStrip>(0);
363 List<LXPoint> points = new ArrayList<LXPoint>(0);
369 public DXPoint(LXPoint left, LXPoint right)
376 public AKMatrix(LX lx)
379 // for (Tower t : model.towers)
381 Tower t = model.towers.get(0);
382 for (int i = 0; i < 4; ++i)
383 towerStrips.add(new TowerStrip());
386 // for (Strip s : t.strips)
388 for (int i = 1; i <= 13; i += 2)
390 Strip s = t.strips.get(i);
392 for (LXPoint p : s.points)
393 colors[p.index] = lx.hsb(80 * (i % 4), 100, 100);
401 public void run(double deltaMs)
407 class AKEgg extends SCPattern
409 private final SinLFO xRadius = new SinLFO(0.01, 1, 1500);
410 private final SinLFO yRadius = new SinLFO(0.01, 1, 2000);
411 private final SinLFO zRadius = new SinLFO(0.01, 1, 2500);
413 private LXPoint center;
415 private final float X = model.xMax / 2;
416 private final float Y = model.yMax / 2;
417 private final float Z = model.zMax / 2;
422 addModulator(xRadius).trigger();
423 addModulator(yRadius).trigger();
424 addModulator(zRadius).trigger();
426 center = new LXPoint(model.cx, model.cy, model.cz);
430 public void run(double deltaMs)
432 for (LXPoint p : model.points)
434 float v = sqrt(sq(p.x - center.x) + sq(p.y - center.y) + sq(p.z - center.z));
435 float r = sqrt(sq(xRadius.getValuef() * X) + sq(yRadius.getValuef() * Y) + sq(zRadius.getValuef() * Z));
436 if (v > r - t && v < r)
437 colors[p.index] = lx.hsb(0, 0, 100);
445 class AKCubes extends SCPattern
450 public AKCubes(LX lx)
453 cube = model.cubes.get((int) random(model.cubes.size()));
458 public void run(double deltaMs)
463 for (LXPoint p : cube.points)
465 cube = model.cubes.get((int) random(model.cubes.size()));
468 for (LXPoint p : cube.points)
469 colors[p.index] = lx.hsb(0, 0, 100);
474 class AKSpiral extends SCPattern
477 public AKSpiral(LX lx)
483 public void run(double deltaMs)
485 // colors[new LXPoint(model.cx, model.cy, model.cz).index] = lx.hsb(0, 0, 100);
490 class AKSpace extends SCPattern
492 private LinkedList<Star> stars;
496 // Current coordinates
498 // Ending coordinates
499 // final float xEnd, yEnd, zEnd;
503 float xInc, yInc, zInc;
509 // Set starting coords at center
517 this.z = model.zMax + this.r;
519 // Direction of movement
520 float angle = random(0, TWO_PI);
521 // Calculate speed of travel
522 this.xInc = cos(angle);
523 this.yInc = sin(angle);
524 // Star must cover full z range in the time it takes to cover dist
525 this.zInc = this.z / min(abs(model.xMax * cos(angle)), abs(model.yMax * sin(angle)));
528 public void increment()
535 public boolean outOfBounds()
537 return (this.x > model.xMax || this.x < model.xMin || this.y > model.yMax || this.y < model.yMin);
541 public AKSpace(LX lx)
544 stars = new LinkedList<Star>();
545 for (int i = 0; i < 50; ++i)
546 stars.add(new Star());
549 public void run(double deltaMs)
551 for (LXPoint p : model.points)
554 for (Star star : stars)
556 if (star.x > model.xMax || star.x < model.xMin || star.y > model.yMax || star.y < model.yMin)
564 // Draw stars on model
565 for (LXPoint p : model.points)
567 // Check if point falls within star
568 if (sqrt(sq(p.x - star.x) + sq(p.y - star.y) + sq(p.z - star.z)) <= star.r)
569 colors[p.index] = lx.hsb(0, 0, 100);