X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TestPatterns.pde;h=38ea2296200d31e7f13e370a7d1f3acc35a7df7d;hb=f5d9de39b45481476cfa2a34d30aa8c6578f7d9c;hp=2b44a93f632c4b5189e90cc7a6567a3481ebe27d;hpb=7ef61b89c1fb05d502b55052dd09a3c29213c35d;p=SugarCubes.git diff --git a/TestPatterns.pde b/TestPatterns.pde index 2b44a93..38ea229 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -74,6 +74,33 @@ class TestZPattern extends SCPattern { } } +/** + * This shows how to iterate over towers, enumerated in the model. + */ +class TestTowerPattern extends SCPattern { + private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size()); + + public TestTowerPattern(GLucose glucose) { + super(glucose); + addModulator(towerIndex).trigger(); + } + + public void run(int deltaMs) { + int ti = 0; + for (Tower t : model.towers) { + for (Point p : t.points) { + colors[p.index] = color( + lx.getBaseHuef(), + 100, + max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size())) + ); + } + ++ti; + } + } + +} + /** * This is a demonstration of how to use the projection library. A projection * creates a mutation of the coordinates of all the points in the model, creating @@ -112,7 +139,7 @@ class TestProjectionPattern extends SCPattern { projection.reset(model) // Translate so the center of the car is the origin, offset by yPos - .translateCenter(0, yPos.getValuef(), 0) + .translateCenter(model, 0, yPos.getValuef(), 0) // Rotate around the origin (now the center of the car) about an X-vector .rotate(angle.getValuef(), 1, 0, 0) @@ -133,3 +160,205 @@ class TestProjectionPattern extends SCPattern { } } } + +class TestCubePattern extends SCPattern { + + private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60); + + TestCubePattern(GLucose glucose) { + super(glucose); + addModulator(index).start(); + } + + public void run(int deltaMs) { + for (Cube c : model.cubes) { + int i = 0; + for (Point p : c.points) { + colors[p.index] = color( + lx.getBaseHuef(), + 100, + max(0, 100 - 80.*abs(i - index.getValuef())) + ); + ++i; + } + } + } +} + +class MappingTool extends SCPattern { + + private int cubeIndex = 0; + private int stripIndex = 0; + private int channelIndex = 0; + + public final int MAPPING_MODE_ALL = 0; + public final int MAPPING_MODE_CHANNEL = 1; + public final int MAPPING_MODE_SINGLE_CUBE = 2; + public int mappingMode = MAPPING_MODE_ALL; + + public final int CUBE_MODE_ALL = 0; + public final int CUBE_MODE_SINGLE_STRIP = 1; + public final int CUBE_MODE_STRIP_PATTERN = 2; + public int cubeMode = CUBE_MODE_ALL; + + public boolean channelModeRed = true; + public boolean channelModeGreen = false; + public boolean channelModeBlue = false; + + private final int numChannels; + + private final PandaMapping[] pandaMappings; + private PandaMapping activeMapping; + private int mappingChannelIndex; + + MappingTool(GLucose glucose, PandaMapping[] pandaMappings) { + super(glucose); + this.pandaMappings = pandaMappings; + numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD; + setChannel(); + } + + private void setChannel() { + mappingChannelIndex = channelIndex % PandaMapping.CHANNELS_PER_BOARD; + activeMapping = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD]; + } + + private int cubeInChannel(Cube c) { + int i = 1; + for (int index : activeMapping.channelList[mappingChannelIndex]) { + if (c == model.getCubeByRawIndex(index)) { + return i; + } + ++i; + } + return 0; + } + + private void printInfo() { + println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1)); + } + + public void cube(int delta) { + int len = model.cubes.size(); + cubeIndex = (len + cubeIndex + delta) % len; + printInfo(); + } + + public void strip(int delta) { + int len = Cube.STRIPS_PER_CUBE; + stripIndex = (len + stripIndex + delta) % len; + printInfo(); + } + + public void run(int deltaMs) { + color off = color(0, 0, 0); + color c = off; + color r = #FF0000; + color g = #00FF00; + color b = #0000FF; + if (channelModeRed) c |= r; + if (channelModeGreen) c |= g; + if (channelModeBlue) c |= b; + + int ci = 0; + for (Cube cube : model.cubes) { + boolean cubeOn = false; + int channelIndex = cubeInChannel(cube); + switch (mappingMode) { + case MAPPING_MODE_ALL: cubeOn = true; break; + case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break; + case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break; + } + if (cubeOn) { + if (mappingMode == MAPPING_MODE_CHANNEL) { + color cc = off; + switch (channelIndex) { + case 1: cc = r; break; + case 2: cc = r|g; break; + case 3: cc = g; break; + case 4: cc = b; break; + case 5: cc = r|b; break; + } + setColor(cube, cc); + } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) { + int si = 0; + color sc = off; + for (Strip strip : cube.strips) { + int faceI = si / Face.STRIPS_PER_FACE; + switch (faceI) { + case 0: sc = r; break; + case 1: sc = g; break; + case 2: sc = b; break; + case 3: sc = r|g|b; break; + } + if (si % Face.STRIPS_PER_FACE == 2) { + sc = r|g; + } + setColor(strip, sc); + ++si; + } + } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) { + setColor(cube, off); + setColor(cube.strips.get(stripIndex), c); + } else { + setColor(cube, c); + } + } else { + setColor(cube, off); + } + ++ci; + } + + } + + public void incCube() { + cubeIndex = (cubeIndex + 1) % model.cubes.size(); + } + + public void decCube() { + --cubeIndex; + if (cubeIndex < 0) { + cubeIndex += model.cubes.size(); + } + } + + public void incChannel() { + channelIndex = (channelIndex + 1) % numChannels; + setChannel(); + } + + public void decChannel() { + --channelIndex; + if (channelIndex < 0) { + channelIndex += numChannels; + } + setChannel(); + } + + public void incStrip() { + int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE; + stripIndex = (stripIndex + 1) % stripsPerCube; + } + + public void decStrip() { + int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE; + --stripIndex; + if (stripIndex < 0) { + stripIndex += stripsPerCube; + } + } + + public void keyPressed() { + switch (keyCode) { + case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break; + case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break; + case LEFT: decStrip(); break; + case RIGHT: incStrip(); break; + } + switch (key) { + case 'r': channelModeRed = !channelModeRed; break; + case 'g': channelModeGreen = !channelModeGreen; break; + case 'b': channelModeBlue = !channelModeBlue; break; + } + } +}