1 /**************************************************************
3 **************************************************************/
5 class AKPong extends SCPattern
7 private final BasicParameter speed = new BasicParameter("Speed", 0);
8 private final BasicParameter leftKnob = new BasicParameter("Left", 0.5);
9 private final BasicParameter rightKnob = new BasicParameter("Right", 0.5);
10 private final float R = 20;
11 private final float W = 20;
12 private final float H = 80;
13 private final float PADDLE_STEP = 5;
14 private float oldLeft = leftKnob.getValuef();
15 private float oldRight = rightKnob.getValuef();
17 private Paddle left = new Paddle(model.xMin, model.cy - H / 2, model.xMin + W, model.cy + H / 2);
18 private Paddle right = new Paddle(model.xMax - W, model.cy - H / 2, model.xMax, model.cy + H / 2);
19 private Ball ball = new Ball();
24 public Paddle(float x1, float y1, float x2, float y2)
25 { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; }
26 public boolean contains(LXPoint p)
27 { return p.x > x1 && p.x < x2 && p.y > y1 && p.y < y2; }
30 float adj = 9 * speed.getValuef();
31 if (y2 + PADDLE_STEP < model.yMax)
33 y1 += PADDLE_STEP + adj;
34 y2 += PADDLE_STEP + adj;
42 public void moveDown()
44 float adj = 15 * speed.getValuef();
45 if (y2 - PADDLE_STEP > model.yMin)
47 y1 -= PADDLE_STEP + adj;
48 y2 -= PADDLE_STEP + adj;
57 public void moveTo(float y)
59 y1 = (model.yMax - H) * y;
60 y2 = (model.yMax * y + H *(1 - y));
66 float x = model.cx, y = model.cy, z = model.cz;
67 int xDir = 1, yDir = 1;
69 public boolean contains(LXPoint p)
70 { return sqrt(sq(p.x - ball.x) + sq(p.y - y) + sq(p.z - z)) < R; }
77 // Collision with floor/ceiling
78 if (y + R > model.yMax || y - R < model.yMin)
80 // Collision with right wall
81 if (x + R > model.xMax)
83 // Check if paddle is here
84 if (y < right.y2 && y > right.y1)
89 // Collision with left wall
90 if (x - R < model.xMin)
92 // Check if paddle is here
93 if (y < left.y2 && y > left.y1)
98 x += xDir + xDir * 9 * speed.getValuef();
99 y += yDir + yDir * 9 * speed.getValuef();
104 public boolean noteOn(Note note)
106 switch (note.getPitch())
108 case 49: // W -> left paddle up
111 case 50: // S -> left paddle down
114 case 61: // O -> right paddle up
117 case 62: // L -> right paddle down
128 addParameter(leftKnob);
129 addParameter(rightKnob);
132 public void run(double deltsMs)
134 float newLeft = leftKnob.getValuef();
135 float newRight = rightKnob.getValuef();
137 if (newLeft != oldLeft)
139 left.moveTo(newLeft);
142 if (newRight != oldRight)
144 right.moveTo(newRight);
149 for (LXPoint p : model.points)
151 if (ball.contains(p))
152 colors[p.index] = lx.hsb(ball.c, 100, 100);
153 else if (left.contains(p))
154 colors[p.index] = lx.hsb(0, 0, 100);
155 else if (right.contains(p))
156 colors[p.index] = lx.hsb(0, 0, 100);
164 ///////////////////////////////////////////////////////////////////////////////
166 /**************************************************************
168 **************************************************************/
170 class AKInvader extends SCPattern
172 private final SawLFO h = new SawLFO(0, 1, 5000);
173 public AKInvader(LX lx)
176 addModulator(h).trigger();
179 public void run(double deltaMs)
181 color c = lx.hsb(h.getValuef() * 360, 100, 100);
182 int nTowers = model.towers.size();
183 int tower = nTowers / 2;
185 for (int cube = 1; cube <= 3; ++cube)
186 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
190 for (int cube = 2; cube <= 3; ++cube)
191 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
193 // for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
194 // colors[p.index] = c;
197 for (int cube = 1; cube <= 5; ++cube)
198 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
202 for (LXPoint p : model.towers.get(tower).cubes.get(0).points)
204 for (int cube = 2; cube <= 3; ++cube)
205 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
207 for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
211 for (int cube = 2; cube <= 5; ++cube)
212 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
216 for (LXPoint p : model.towers.get(tower).cubes.get(0).points)
218 for (int cube = 2; cube <= 3; ++cube)
219 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
221 for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
225 for (int cube = 1; cube <= 5; ++cube)
226 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
230 for (int cube = 2; cube <= 3; ++cube)
231 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
233 // for (LXPoint p : model.towers.get(tower).cubes.get(5).points)
234 // colors[p.index] = c;
237 for (int cube = 1; cube <= 3; ++cube)
238 for (LXPoint p : model.towers.get(tower).cubes.get(cube).points)
244 class AKTetris extends SCPattern
246 // Movement increments
247 private final float STEP_Y = 1;
248 private final float STEP_X = 10;
250 private final float D = 10;
252 private Shape shape = new Box();
256 float x, y; // Block position, lower left corner
257 public Block(float x, float y)
266 List<Block> blocks; // Blocks comprising this shape
267 float x, y; // Shape position, lower left corner
268 float h, w; // Effective Shape dimensions
271 public boolean contains(LXPoint p)
273 for (Block b : blocks)
274 if (p.x > b.x && p.x < b.x + D && p.y > b.y && p.y < b.y + D)
279 public void dropDown(float inc)
281 for (Block b : blocks)
286 public void moveLeft(float inc)
288 for (Block b : blocks)
293 public void moveRight(float inc)
295 for (Block b : blocks)
301 class Box extends Shape
310 blocks = new LinkedList<Block>();
311 blocks.add(new Block(model.cx - D, model.yMax));
312 blocks.add(new Block(model.cx, model.yMax));
313 blocks.add(new Block(model.cx - D, model.yMax + D));
314 blocks.add(new Block(model.cx, model.yMax + D));
316 c = lx.hsb(0, 100, 100);
317 x = model.cx - w / 2;
322 public AKTetris(LX lx)
327 public boolean noteOn(Note note)
329 switch (note.getPitch())
331 case 48: // A -> left
332 shape.moveLeft(STEP_X);
334 case 52: // D -> right
335 shape.moveRight(STEP_X);
341 public void run(double deltaMs)
343 for (LXPoint p : model.points)
345 if (shape.contains(p))
346 colors[p.index] = shape.c;
350 if (shape.y > model.yMin)
351 shape.dropDown(STEP_Y);
356 class AKMatrix extends SCPattern
358 private List<TowerStrip> towerStrips = new ArrayList<TowerStrip>(0);
362 List<LXPoint> points = new ArrayList<LXPoint>(0);
368 public DXPoint(LXPoint left, LXPoint right)
375 public AKMatrix(LX lx)
378 // for (Tower t : model.towers)
380 Tower t = model.towers.get(0);
381 for (int i = 0; i < 4; ++i)
382 towerStrips.add(new TowerStrip());
385 // for (Strip s : t.strips)
387 for (int i = 1; i <= 13; i += 2)
389 Strip s = t.strips.get(i);
391 for (LXPoint p : s.points)
392 colors[p.index] = lx.hsb(80 * (i % 4), 100, 100);
400 public void run(double deltaMs)
406 class AKEgg extends SCPattern
408 private final SinLFO xRadius = new SinLFO(0.01, 1, 1500);
409 private final SinLFO yRadius = new SinLFO(0.01, 1, 2000);
410 private final SinLFO zRadius = new SinLFO(0.01, 1, 2500);
412 private LXPoint center;
414 private final float X = model.xMax / 2;
415 private final float Y = model.yMax / 2;
416 private final float Z = model.zMax / 2;
421 addModulator(xRadius).trigger();
422 addModulator(yRadius).trigger();
423 addModulator(zRadius).trigger();
425 center = new LXPoint(model.cx, model.cy, model.cz);
429 public void run(double deltaMs)
431 for (LXPoint p : model.points)
433 float v = sqrt(sq(p.x - center.x) + sq(p.y - center.y) + sq(p.z - center.z));
434 float r = sqrt(sq(xRadius.getValuef() * X) + sq(yRadius.getValuef() * Y) + sq(zRadius.getValuef() * Z));
435 if (v > r - t && v < r)
436 colors[p.index] = lx.hsb(0, 0, 100);
444 class AKCubes extends SCPattern
449 public AKCubes(LX lx)
452 cube = model.cubes.get((int) random(model.cubes.size()));
457 public void run(double deltaMs)
462 for (LXPoint p : cube.points)
464 cube = model.cubes.get((int) random(model.cubes.size()));
467 for (LXPoint p : cube.points)
468 colors[p.index] = lx.hsb(0, 0, 100);
473 class AKSpiral extends SCPattern
476 public AKSpiral(LX lx)
482 public void run(double deltaMs)
484 // colors[new LXPoint(model.cx, model.cy, model.cz).index] = lx.hsb(0, 0, 100);
489 class AKSpace extends SCPattern
491 private LinkedList<Star> stars;
495 // Current coordinates
497 // Ending coordinates
498 // final float xEnd, yEnd, zEnd;
502 float xInc, yInc, zInc;
508 // Set starting coords at center
516 this.z = model.zMax + this.r;
518 // Direction of movement
519 float angle = random(0, TWO_PI);
520 // Calculate speed of travel
521 this.xInc = cos(angle);
522 this.yInc = sin(angle);
523 // Star must cover full z range in the time it takes to cover dist
524 this.zInc = this.z / min(abs(model.xMax * cos(angle)), abs(model.yMax * sin(angle)));
527 public void increment()
534 public boolean outOfBounds()
536 return (this.x > model.xMax || this.x < model.xMin || this.y > model.yMax || this.y < model.yMin);
540 public AKSpace(LX lx)
543 stars = new LinkedList<Star>();
544 for (int i = 0; i < 50; ++i)
545 stars.add(new Star());
548 public void run(double deltaMs)
550 for (LXPoint p : model.points)
553 for (Star star : stars)
555 if (star.x > model.xMax || star.x < model.xMin || star.y > model.yMax || star.y < model.yMin)
563 // Draw stars on model
564 for (LXPoint p : model.points)
566 // Check if point falls within star
567 if (sqrt(sq(p.x - star.x) + sq(p.y - star.y) + sq(p.z - star.z)) <= star.r)
568 colors[p.index] = lx.hsb(0, 0, 100);