X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TestPatterns.pde;h=c4432ab0baa1d7cc976b5fcddecfcb43cce67529;hb=466150f6a953b37d9254ede0095669d5ac3a68e0;hp=2b44a93f632c4b5189e90cc7a6567a3481ebe27d;hpb=7ef61b89c1fb05d502b55052dd09a3c29213c35d;p=SugarCubes.git diff --git a/TestPatterns.pde b/TestPatterns.pde index 2b44a93..c4432ab 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -112,7 +112,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 +133,209 @@ class TestProjectionPattern extends SCPattern { } } } + +class TestCubePattern extends SCPattern { + + private int POINTS_PER_CUBE = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE * Strip.POINTS_PER_STRIP; + private SawLFO index = new SawLFO(0, POINTS_PER_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 static int NUM_CHANNELS = 16; + + private final int[][] frontChannels; + private final int[][] rearChannels; + private int[] activeChannels; + + MappingTool(GLucose glucose, int[][]frontChannels, int[][]rearChannels) { + super(glucose); + this.frontChannels = frontChannels; + this.rearChannels = rearChannels; + setChannel(); + } + + private void setChannel() { + if (channelIndex < frontChannels.length) { + activeChannels = frontChannels[channelIndex]; + } else { + activeChannels = rearChannels[channelIndex - frontChannels.length]; + } + } + + private int cubeInChannel(Cube c) { + int i = 1; + for (int index : activeChannels) { + 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.FACES_PER_CUBE * Face.STRIPS_PER_FACE; + 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) % NUM_CHANNELS; + setChannel(); + } + + public void decChannel() { + --channelIndex; + if (channelIndex < 0) { + channelIndex += NUM_CHANNELS; + } + 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; + } + } +}