From 7ef61b89c1fb05d502b55052dd09a3c29213c35d Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Sun, 9 Jun 2013 20:45:34 -0700 Subject: [PATCH] A few cleanups to test patterns --- TestPatterns.pde | 93 ++++++++++++++++++++++++++++++++++------------- code/GLucose.jar | Bin 15121 -> 15328 bytes 2 files changed, 67 insertions(+), 26 deletions(-) diff --git a/TestPatterns.pde b/TestPatterns.pde index 516c3e4..2b44a93 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -1,72 +1,104 @@ +/** + * Simplest demonstration of using the rotating master hue. + * All pixels are full-on the same color. + */ class TestHuePattern extends SCPattern { public TestHuePattern(GLucose glucose) { super(glucose); } + public void run(int deltaMs) { + // Access the core master hue via this method call + float hv = lx.getBaseHuef(); for (int i = 0; i < colors.length; ++i) { - colors[i] = color(lx.getBaseHuef(), 100, 100); + colors[i] = color(hv, 100, 100); } } } +/** + * Test of a wave moving across the X axis. + */ class TestXPattern extends SCPattern { - private SinLFO xPos = new SinLFO(0, model.xMax, 4000); + private final SinLFO xPos = new SinLFO(0, model.xMax, 4000); public TestXPattern(GLucose glucose) { super(glucose); addModulator(xPos).trigger(); } public void run(int deltaMs) { + float hv = lx.getBaseHuef(); for (Point p : model.points) { - colors[p.index] = color( - lx.getBaseHuef(), - 100, - max(0, 100 - abs(p.fx - xPos.getValuef())) - ); + // This is a common technique for modulating brightness. + // You can use abs() to determine the distance between two + // values. The further away this point is from an exact + // point, the more we decrease its brightness + float bv = max(0, 100 - abs(p.fx - xPos.getValuef())); + colors[p.index] = color(hv, 100, bv); } } } +/** + * Test of a wave on the Y axis. + */ class TestYPattern extends SCPattern { - private SinLFO yPos = new SinLFO(0, model.yMax, 4000); + private final SinLFO yPos = new SinLFO(0, model.yMax, 4000); public TestYPattern(GLucose glucose) { super(glucose); addModulator(yPos).trigger(); } public void run(int deltaMs) { + float hv = lx.getBaseHuef(); for (Point p : model.points) { - colors[p.index] = color( - lx.getBaseHuef(), - 100, - max(0, 100 - abs(p.fy - yPos.getValuef())) - ); + float bv = max(0, 100 - abs(p.fy - yPos.getValuef())); + colors[p.index] = color(hv, 100, bv); } } } +/** + * Test of a wave on the Z axis. + */ class TestZPattern extends SCPattern { - private SinLFO zPos = new SinLFO(0, model.zMax, 4000); + private final SinLFO zPos = new SinLFO(0, model.zMax, 4000); public TestZPattern(GLucose glucose) { super(glucose); addModulator(zPos).trigger(); } public void run(int deltaMs) { + float hv = lx.getBaseHuef(); for (Point p : model.points) { - colors[p.index] = color( - lx.getBaseHuef(), - 100, - max(0, 100 - abs(p.fz - zPos.getValuef())) - ); + float bv = max(0, 100 - abs(p.fz - zPos.getValuef())); + colors[p.index] = color(hv, 100, bv); } } } +/** + * 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 + * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire + * art car. However, since in reality the car does not move, the result is that + * it appears that the object we are drawing on the car is actually moving. + * + * Keep in mind that what we are creating a projection of is the view coordinates. + * Depending on your intuition, some operations may feel backwards. For instance, + * if you translate the view to the right, it will make it seem that the object + * you are drawing has moved to the left. If you scale the view up 2x, objects + * drawn with the same absolute values will seem to be half the size. + * + * If this feels counterintuitive at first, don't worry. Just remember that you + * are moving the pixels, not the structure. We're dealing with a finite set + * of sparse, non-uniformly spaced pixels. Mutating the structure would move + * things to a space where there are no pixels in 99% of the cases. + */ class TestProjectionPattern extends SCPattern { - final Projection projection; - final SawLFO angle = new SawLFO(0, TWO_PI, 9000); - final SinLFO yPos = new SinLFO(-20, 40, 5000); + private final Projection projection; + private final SawLFO angle = new SawLFO(0, TWO_PI, 9000); + private final SinLFO yPos = new SinLFO(-20, 40, 5000); - TestProjectionPattern(GLucose glucose) { + public TestProjectionPattern(GLucose glucose) { super(glucose); projection = new Projection(model); addModulator(angle).trigger(); @@ -74,18 +106,27 @@ class TestProjectionPattern extends SCPattern { } public void run(int deltaMs) { - // Note: logically, you typically apply the transformations in reverse order + // For the same reasons described above, it may logically feel to you that + // some of these operations are in reverse order. Again, just keep in mind that + // the car itself is what's moving, not the object projection.reset(model) - .translate(-model.xMax/2., -model.yMax/2. + yPos.getValuef(), -model.zMax/2.) + + // Translate so the center of the car is the origin, offset by yPos + .translateCenter(0, yPos.getValuef(), 0) + + // Rotate around the origin (now the center of the car) about an X-vector .rotate(angle.getValuef(), 1, 0, 0) + + // Scale up the Y axis (objects will look smaller in that access) .scale(1, 1.5, 1); + float hv = lx.getBaseHuef(); for (Coord c : projection) { float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing d = max(0, abs(c.y) - 10 + .3*abs(c.z) + .08*abs(c.x)); // plane / spear thing colors[c.index] = color( - (lx.getBaseHuef() + .6*abs(c.x) + abs(c.z)) % 360, + (hv + .6*abs(c.x) + abs(c.z)) % 360, 100, constrain(140 - 10*d, 0, 100) ); diff --git a/code/GLucose.jar b/code/GLucose.jar index ecd95efeb9945f9c40f5b0ed98dcfbc5ad7ba43e..d39d6d4e1e9fe1d95e84592bf6b6b69cef412ef2 100644 GIT binary patch delta 1789 zcmYL~XIRr$8^)86PzZuG5Ugy%2o%GT3<7~Lj36V7M37Y?D%uEPIm!wsgdtGE->?J} zjZ$i%ETyze!QjA%phW3g3kDE{H;|TBcq@^@AA9wD`91gjoO7;ozT6N0%+y)+03Rhd z5&}_yKn}5o`05r)%uSF=l(y6ZBM^%wTL4f{E09#^mmuSymLRJ>`NL2gs8^xZAT40# zTWk-6btr*_in9K8VWH{`1)UV+EhUZ3J?<6crc4TA^BG8hi$u4(YXl&`4Fb)1Bv@n_ z)NP+N#*Dx~XW2A;yWn6cP}J5X6wy;Cbn_Da=6^5{VA)X%pp!r6)-uDBgPB?%&m@%r z!iEY{KaIwwEN@f4d(=xhYK;2N_lFm1@y~ZAPXcA7=Cd;$4uS(B;_-9xY>CVLB06at zIUkzwe!y_bW*JK=3X+h$ffd@lqiyde7v48Ldgatd`H-ki)#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