Commit 797d5962 authored by Ashley Chen's avatar Ashley Chen
Browse files

Merge branch 'dev/patterns-ashley' into 'master'

Dev/patterns ashley

See merge request !43
parents f452fb70 ecaa693d
......@@ -641,6 +641,11 @@ public abstract class FlightEngine implements FlightTrack {
patterns.add(new ColorWave(lx));
patterns.add(new ColorWheel(lx));
patterns.add(new RaspberryTrip(lx));
patterns.add(new Twinkle(lx));
patterns.add(new LightHouseColor(lx));
patterns.add(new SlowFlap(lx));
patterns.add(new SplitWings(lx));
patterns.add(new VogueWings(lx));
}
/* Create an array with a new instance of each available Pattern. */
......
package engine;
import java.util.List;
import java.util.List;
import java.util.PrimitiveIterator.OfInt;
import java.util.ArrayList;
import model.FlyerModel;
......@@ -138,7 +139,7 @@ class WheelOfcolor extends FlightPattern{
* Flyer wing only function, where the flyers traverse in an ordering, flpping its wings in succession
* @author Kyung-Tae Kim <kim1@stanford.edu>
*/
class climbFlap extends FlightPattern{
class ClimbFlap extends FlightPattern{
int NUM_FLYERS = Geometry.NUM_FLYERS;
int FLYER_MOD = NUM_FLYERS - 1;
final BoundedParameter rate = new BoundedParameter("RATE", 5000, 5000, 100000);
......@@ -147,7 +148,7 @@ class climbFlap extends FlightPattern{
final BoundedParameter speed = new BoundedParameter("SPEED", 5000, 12500, 25000);
final SinLFO colorFlap = new SinLFO(0, 360, speed);
climbFlap(LX lx){
ClimbFlap(LX lx){
super(lx);
addParameter("climbFlap_RATE", rate);
//Starting modulator that takes in those speeds
......@@ -172,14 +173,14 @@ class climbFlap extends FlightPattern{
* Flaps the wings in a slow fashion where the right and left wing are skewed
* @author Kyung-Tae Kim <kim1@stanford.edu>
*/
class slowFlap extends FlightPattern{
class SlowFlap extends FlightPattern{
int NUM_FLYERS = Geometry.NUM_FLYERS;
int FLYER_MOD = NUM_FLYERS - 1;
//Speed by which the wings are rotating "GUESS"
final BoundedParameter speed = new BoundedParameter("SPEED", 5000, 12500, 25000);
final SinLFO colorFlap = new SinLFO(0, 360, speed);
slowFlap(LX lx){
SlowFlap(LX lx){
super(lx);
addParameter("slowFlap_SPEED", speed);
addModulator(colorFlap).start();
......@@ -1220,3 +1221,265 @@ class ColorWall extends FlightPattern {
}
}
/**
* Twinkles by adjusting the brightness of individual light points, without regard to how the light points are defined in the space.
* Swap out the commented code to see the effect on only the body lights. You might want to do this because the GUI only shows each wing as
* one light point, when in reality it is 3.
* Adapted from the Twinkle pattern from Entwined
*
* @author Ashley Chen <ashleyic@cs.stanford.edu>
*/
class Twinkle extends FlightPattern {
private SinLFO[] bright;
final BoundedParameter brightnessParam = new BoundedParameter("Brightness", 0.9, 0.5, 1);
final int numBrights = 30;
final int density = 20;
int[] sparkleTimeOuts;
int[] lightPointToModulatorMapping;
Random rand = new Random();
static private final long millisOffset = System.currentTimeMillis();
Twinkle(LX lx) {
super(lx);
addParameter("Twinkle_BRIGHTNESS", brightnessParam);
// sparkleTimeOuts = new int[model.getAllBodyLights().size()];
// lightPointToModulatorMapping = new int[model.getAllBodyLights().size()];
sparkleTimeOuts = new int[model.getAllLights().size()];
lightPointToModulatorMapping = new int[model.getAllLights().size()];
for (int i = 0; i < lightPointToModulatorMapping.length; i++ ) {
lightPointToModulatorMapping[i] = rand.nextInt(numBrights);
}
bright = new SinLFO[numBrights];
int numLight = density / 100 * bright.length; // number of brights array that are most bright
int numDarkReverse = (bright.length - numLight) / 2; // number of brights array that go from light to dark
for (int i = 0; i < bright.length; i++ ) {
if (i <= numLight) {
if (rand.nextFloat() < 0.5f) {
bright[i] = new SinLFO(rand.nextInt(100 - 80) + 80, 0, rand.nextInt(7700 - 2300) + 2300);
}
else {
bright[i] = new SinLFO(0, rand.nextInt(90 - 70) + 70, rand.nextInt(9200 - 5300) + 5300);
}
}
else if ( i < numDarkReverse ) {
bright[i] = new SinLFO(rand.nextInt(70 - 50) + 50, 0, rand.nextInt(11300 - 3300) + 3300);
}
else {
bright[i] = new SinLFO(0, rand.nextInt(80 - 30) + 30, rand.nextInt(9300 - 3100) + 3100);
}
addModulator(bright[i]).start();
}
}
@Override
public void run(double deltaMs) {
// for (LightSamplePointModel point : model.getAllBodyLights()) {
// if (sparkleTimeOuts[point.getBodyIndex()] < (int)(System.currentTimeMillis() - millisOffset)) {
// // randomly change modulators
// if (rand.nextInt(10) <= 3) {
// lightPointToModulatorMapping[point.getBodyIndex()] = rand.nextInt(numBrights);
// }
// sparkleTimeOuts[point.getBodyIndex()] = (int)(System.currentTimeMillis() - millisOffset) + rand.nextInt(23300 - 11100) + 11100;
// }
// setColor(point, LX.hsb(
// 0,
// 0,
// bright[lightPointToModulatorMapping[point.getBodyIndex()]].getValuef() * brightnessParam.getValuef()
// ));
// }
for (WingModel wing : model.getAllWings()) {
setSkew(wing, 180);
}
for (LightSamplePointModel point : model.getAllLights()) {
if (sparkleTimeOuts[point.index] < (int)(System.currentTimeMillis() - millisOffset)) {
// randomly change modulators
if (rand.nextInt(10) <= 3) {
lightPointToModulatorMapping[point.index] = rand.nextInt(numBrights);
}
sparkleTimeOuts[point.index] = (int)(System.currentTimeMillis() - millisOffset) + rand.nextInt(23300 - 11100) + 11100;
}
setColor(point, LX.hsb(
0,
0,
bright[lightPointToModulatorMapping[point.index]].getValuef() * brightnessParam.getValuef()
));
}
}
}
/**
* This creates a rotating ray of colored light around a center point.
* @author Ashley Chen <ashleyic@cs.stanford.edu>
*/
class LightHouseColor extends FlightPattern{
private float speedMult = 1000;
final BoundedParameter hue = new BoundedParameter("hue", 50, 0, 360);
final BoundedParameter width = new BoundedParameter("width", 45, 0, 100);
final BoundedParameter colorSpeed = new BoundedParameter("colorSpeed", 160, 0, 200);
final BoundedParameter speedParam = new BoundedParameter("Speed", 5, 20, .01);
final SawLFO wave = new SawLFO(0, 360, 1000);
float total_ms=0;
int shrub_offset[];
LightHouseColor(LX lx) {
super(lx);
addModulator(wave).start();
addParameter("LightHouse_hue", hue);
addParameter("LightHouse_speedParam", speedParam);
addParameter("LightHouse_colorSpeed", colorSpeed);
addParameter("LightHouse_width", width);
}
@Override
public void run(double deltaMs) {
wave.setPeriod(speedParam.getValuef() * speedMult );
total_ms+=deltaMs*speedParam.getValuef();
float offset = (wave.getValuef()+360.0f)%360.0f;
for (LightSamplePointModel point : model.getAllLights()) {
FlyerModel fl = model.getFlyers().get(point.getBodyIndex());
float x = fl.getX()-310; //Approximate x offset from center
float y = fl.getY()-250; //Approximate y offset from center
// float x = point.x - 310; //Approximate x offset from center
// float y = point.y-250; //Approximate y offset from center
double angle = 57.3 * Math.atan(x/y);//Calculate angle of flyer
float diff = (360.0f+(wave.getValuef() - (float)angle)%360.0f)%360.f; // smallest postive representation modulo 360
if ((360-diff)<diff) {
diff=360-diff;
}
float b = diff<width.getValuef() ? 100.0f : 0.0f;
float h = (360+(hue.getValuef() +
total_ms*colorSpeed.getValuef()/10000)%360)%360;
setColor(point, LX.hsb(h,
100,
b));
}
}
}
/**
* This should allow the user to manually adjust the XYZ parameters to sweep a beam of green
* across the specified coordinate plane. It does not work at the moment, because the model has not
* been set up to support coordinate calculations down to the LightSamplePoint level :'(
*
* @author Ashley Chen <ashleyic@cs.stanford.edu>
*/
class TestSweep extends FlightPattern {
final BoundedParameter x;
final BoundedParameter y;
final BoundedParameter z;
final BoundedParameter beam;
TestSweep(LX lx) {
super(lx);
addParameter("test_x", x = new BoundedParameter("X", 0, model.xMin, model.xMax));
addParameter("test_y", y = new BoundedParameter("Y", 0, model.yMin, model.yMax));
addParameter("test_z", z = new BoundedParameter("Z", 0, model.zMin, model.zMax));
addParameter("test_beam", beam = new BoundedParameter("beam", 5, 1, 15));
}
static public final float abs(float n) {
return (n < 0) ? -n : n;
}
public void run(double deltaMs) {
for (LightSamplePointModel cube : model.getAllLights()) {
if (abs(cube.x - x.getValuef()) < beam.getValuef() ||
abs(cube.y - y.getValuef()) < beam.getValuef() ||
abs(cube.z - z.getValuef()) < beam.getValuef()) {
colors[cube.index] = lx.hsb(135, 100, 100);
} else {
colors[cube.index] = lx.hsb(135, 100, 0);
}
}
}
}
/**
* Pattern to make the wings appear as if they're dancing.
* Move into a position then hold the pose.
* Pretty glitchy, but it might work okay with how commands are issued to the actual
* wing motors themselves.
*
* @author Ashley Chen <ashleyic@cs.stanford.edu>
*/
class VogueWings extends FlightPattern{
final BoundedParameter speed = new BoundedParameter("SPEED", 5000, 5000, 25000);
Random rand = new Random();
OfInt randomSkew;
long millisOffset = System.currentTimeMillis();
private SinLFO[] leftPoseTransitions = new SinLFO[20];
private SinLFO[] rightPoseTransitions = new SinLFO[20];
int firstLeftPose;
int firstRightPose;
int leftCursor = 0;
int rightCursor = 1;
boolean isPosed = false;
VogueWings(LX lx){
super(lx);
addParameter("VogueWings_SPEED", speed);
randomSkew = rand.ints(-90, 90).iterator();
int leftSkew = 0;
int rightSkew = 0;
firstLeftPose = leftSkew;
firstRightPose = rightSkew;
for (int i = 0; i < leftPoseTransitions.length; i++ ) {
if (i != leftPoseTransitions.length - 1) {
int temp = randomSkew.nextInt();
leftPoseTransitions[i] = new SinLFO(leftSkew, temp, speed);
leftSkew = temp;
temp = randomSkew.nextInt();
rightPoseTransitions[i] = new SinLFO(rightSkew, temp, speed);
rightSkew = temp;
} else {
leftPoseTransitions[i] = new SinLFO(leftSkew, firstLeftPose, speed);
rightPoseTransitions[i] = new SinLFO(rightSkew, firstRightPose, speed);
}
addModulator(leftPoseTransitions[i]).start();
addModulator(rightPoseTransitions[i]).start();
}
}
@Override
public void run(double deltaMs){
if ((int)speed.getValuef()/2 < (int)(System.currentTimeMillis() - millisOffset)) {
millisOffset = System.currentTimeMillis();
if (isPosed) {
if (leftCursor != leftPoseTransitions.length - 1) {
leftCursor++;
} else {
leftCursor = 0;
}
if (rightCursor != rightPoseTransitions.length - 1) {
rightCursor++;
} else {
rightCursor = 0;
}
isPosed = false;
} else {
isPosed = true;
}
}
if (!isPosed) {
for (int i = 0; i < Geometry.NUM_FLYERS; i++) {
setSkew(model.getFlyerLeftWing(i),(int)leftPoseTransitions[leftCursor].getValuef());
setSkew(model.getFlyerRightWing(i),(int)rightPoseTransitions[rightCursor].getValuef());
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment