Commit 5b6a9d23 authored by Ashley Chen's avatar Ashley Chen
Browse files

applied Mark’s comments to remaining classes

parent 4ca1ceac
import heronarts.lx.LX;
import heronarts.lx.effect.LXEffect;
import heronarts.lx.model.LXModel;
import heronarts.lx.effect.LXModelEffect;
import heronarts.lx.model.LXPoint;
abstract class Effect extends LXEffect {
abstract class Effect extends LXModelEffect<FlightModel> {
protected FlightModel model;
Effect(LX lx) {
super(lx);
model = (FlightModel)lx.getModel();
}
@Override
public void loop(double deltaMs) {
if (isEnabled()) {
super.loop(deltaMs);
}
// REVIEW(mcslee): this is already handled by LXEffect
// unclear if there's some different goal here?
// @Override
// public void loop(double deltaMs) {
// if (isEnabled()) {
// super.loop(deltaMs);
// }
// }
/**
* Get the current color at this point
*
* @param p Point
* @return Current color of this point
*/
public int getColor(LXPoint p) {
return this.colors[p.index];
}
/**
* Update the color for the given point
*
* @param p Point
* @param color The color to set for this point
*/
public void setColor(LXPoint p, int color) {
this.colors[p.index] = color;
}
// REVIEW(mcslee): I would suggest collapsing your distinction between
// the interface and class, then these metohds will just work without
// an extra layer of method call abstraction around LXPoint, the above
// methods should be sufficient
// public int getColor(LightSamplePoint p) {
// return this.colors[p.getIndex()];
// }
//
// public void setColor(LightSamplePoint p, int color) {
// this.colors[p.getIndex()] = color;
// }
@Override
public void onModelChanged(LXModel model) {
super.onModelChanged(model);
this.model = (FlightModel)model;
}
}
import java.util.List;
import heronarts.lx.LX;
import heronarts.lx.LXLayer;
import heronarts.lx.color.LXColor;
import heronarts.lx.parameter.BooleanParameter;
import heronarts.lx.parameter.DiscreteParameter;
import heronarts.lx.parameter.LXParameter;
import heronarts.lx.parameter.LXParameterListener;
import heronarts.lx.modulator.QuadraticEnvelope;
class FlyerHighlighter extends Effect {
......@@ -18,24 +19,42 @@ class FlyerHighlighter extends Effect {
super(lx);
flyerConfigurations = configs;
flyerIndex = new DiscreteParameter("FLYER", flyerConfigurations.length);
flyerIndex.addListener(new LXParameterListener() {
public void onParameterChanged(LXParameter parameter) {
strobe.setStartValue(100);
strobe.trigger();
}
});
// REVIEW(mcslee): add the parameter to the component, and your effect
// will automatically be registered as a listener
addParameter("flyerIndex", flyerIndex);
// flyerIndex.addListener(new LXParameterListener() {
// public void onParameterChanged(LXParameter parameter) {
// strobe.setStartValue(100);
// strobe.trigger();
// }
// });
addModulator(strobe).start();
addLayer(new HighlightLayer());
}
// REVIEW(mcslee): automatically receive these changes from our
// registered parameter
@Override
public void onParameterChanged(LXParameter p) {
if (p == flyerIndex) {
strobe.setStartValue(100);
strobe.trigger();
}
}
FlyerConfig getConfig() {
return flyerConfigurations[flyerIndex.getValuei()];
}
Flyer getFlyer() {
FlyerModel getFlyer() {
return model.getFlyer(flyerIndex.getValuei());
}
List<LightSamplePointModel> getFlyerLightPoints() {
return model.getFlyerLights(flyerIndex.getValuei());
}
void reloadModel() {
lx.setModel(new FlightModel(flyerConfigurations));
}
......@@ -45,23 +64,30 @@ class FlyerHighlighter extends Effect {
}
void highlight() {
// REVIEW(mcslee): looks redunant with HighlightLayer below?
if (isEnabled()) {
for (LightSamplePoint point: model.getFlyerLights(getFlyer().getIndex())) {
int oldColor = point.getColor();
for (LightSamplePointModel point : getFlyerLightPoints()) {
int oldColor = getColor(point);
float val = strobe.getValuef();
int highlightColor = lx.hsb(0, 0, val);
int highlightColor = LX.hsb(0, 0, val);
int newColor = LXColor.blend(oldColor,
highlightColor,
LXColor.Blend.ADD);
point.setColor(newColor);
setColor(point, newColor);
}
}
}
public void run(double deltaMs) {}
// REVIEW(mcslee): this doesn't do anything
// public void run(double deltaMs) {}
@Override
public void run(double deltaMs, double foo) {}
public void run(double deltaMs, double enabledAmount) {
// REVIEW(mcslee): this is where your effect logic should be
}
// REVIEW(mcslee): not sure there's any reason for a layer here, put this logic in
// the run(double deltaMs, double foo)
class HighlightLayer extends LXLayer {
HighlightLayer() {
......@@ -71,14 +97,14 @@ class FlyerHighlighter extends Effect {
@Override
public void run(double deltaMs) {
if (isEnabled()) {
for (LightSamplePoint point: ((FlightModel) model).getFlyerLights(getFlyer().getIndex())) {
int oldColor = point.getColor();
for (LightSamplePointModel point : getFlyerLightPoints()) {
int oldColor = getColor(point);
float val = strobe.getValuef();
int highlightColor = lx.hsb(0, 0, val);
int highlightColor = LX.hsb(0, 0, val);
int newColor = LXColor.blend(oldColor,
highlightColor,
LXColor.Blend.ADD);
point.setColor(newColor);
FlyerHighlighter.this.setColor(point, newColor);
}
}
}
......
......@@ -9,22 +9,21 @@ import java.util.ArrayList;
import java.util.List;
import java.io.DataInput;
import heronarts.lx.LX;
import heronarts.lx.model.LXPoint;
import heronarts.lx.output.LXOutput;
import java.awt.Color;
/*
* Generates python command for fractal flyer
* TODO change colour representation in model from string to value
*/
public class Generator extends LXOutput implements GeometryConstants {
final Flight flight;
final List<Flyer> flyers;
final FlightModel flight;
final List<FlyerModel> flyers;
final DataInput[] in;
final PrintStream[] out;
protected int[] frameColors;
static final String LEFT_WING_POS = "wing_angle(LEFT, %s)\n";
static final String RIGHT_WING_POS = "wing_angle(RIGHT, %s)\n";
static final String LEFT_WING_LEDs = "wing_leds(LEFT, (%d, %d, %d), (%d, %d, %d), (%d, %d, %d))\n";
......@@ -32,7 +31,7 @@ public class Generator extends LXOutput implements GeometryConstants {
static final String BODY_LED = "body_leds((%d, %d, %d))";
Generator(LX lx, Flight flight, DataInput[] inSockets, PrintStream[] outSockets) {
Generator(LX lx, FlightModel flight, DataInput[] inSockets, PrintStream[] outSockets) {
super(lx);
this.flight = flight;
this.flyers = this.flight.getFlyers();
......@@ -40,10 +39,20 @@ public class Generator extends LXOutput implements GeometryConstants {
this.out = outSockets;
}
private Color[] getRGBColors(List<? extends LXPoint> points) {
private Color getRGBColor(LightSamplePointModel point) {
return new Color(this.frameColors[point.getIndex()]);
}
private Color[] getRGBColors(List<LightSamplePointModel> points) {
// REVIEW(mcslee) - unclear benefit to making dynamic copies with java.awt.Color on every frame...
// consider using int[] and you have the LXColor.red()/LXColor.green()/LXColor.blue() methods
// which are simlar to java.awt.Color.getRed(), etc.
//
// There's no fundamental problem with what you're doing here, but you're just going to be putting
// the garbage collector to work
Color[] ledColors = new Color[points.size()];
for (int i = 0; i < points.size(); i++) {
ledColors[i] = new Color(((LightSamplePoint) points.get(i)).getColor());
ledColors[i] = new Color(this.frameColors[points.get(i).getIndex()]);
}
return ledColors;
}
......@@ -63,42 +72,36 @@ public class Generator extends LXOutput implements GeometryConstants {
* Perhaps that should be handled by engine
*/
private ArrayList<String> generateCommands(Flyer flyer) {
private ArrayList<String> generateCommands(int flyerIndex) {
/*
* String s = "hello %s!";
* s = String.format(s, "world");
* assertEquals(s, "hello world!");
*/
// Wing[] wings = flyer.getWings();
Wing lWing = flyer.getLeftWing();
Wing rWing = flyer.getRightWing();
Wing lWing = flight.getFlyerLeftWing(flyerIndex);
Wing rWing = flight.getFlyerRightWing(flyerIndex);
int leftWingPos = lWing.getSkew();
int rightWingPos = rWing.getSkew();
LXPoint bodyLightPoint = flyer.getBodyLightPoint();
List<? extends LXPoint> leftLEDs = lWing.getLightPoints();
List<? extends LXPoint> rightLEDs = rWing.getLightPoints();
LightSamplePointModel bodyLightPoint = flight.getFlyerBodyLight(flyerIndex);
List<LightSamplePointModel> leftLEDs = flight.getFlyerLeftWingLights(flyerIndex);
List<LightSamplePointModel> rightLEDs = flight.getFlyerRightWingLights(flyerIndex);
ArrayList<String> commands = new ArrayList<String>();
Color[] leftLights = getRGBColors(leftLEDs);
Color[] rightLights = getRGBColors(rightLEDs);
Color bodyLED = new Color(((LightSamplePoint) bodyLightPoint).getColor());
Color bodyLED = getRGBColor(bodyLightPoint);
commands.add(String.format(LEFT_WING_POS, leftWingPos));
commands.add(String.format(RIGHT_WING_POS, rightWingPos));
// if (leftWingPos >= 0) {
// commands.add(String.format(LEFT_WING_POS, leftWingPos));
// }
//
// if (rightWingPos >= 0) {
// commands.add(String.format(RIGHT_WING_POS, rightWingPos));
// }
commands.add(String.format(BODY_LED,
bodyLED.getRed(), bodyLED.getGreen(), bodyLED.getBlue()));
......@@ -121,9 +124,13 @@ public class Generator extends LXOutput implements GeometryConstants {
protected void onSend(int[] colors, double brightness) {
// super.onSend(colors, brightness);
// REVIEW(mcslee): here we are being given the engine's composited and mixed
// colors for this frame
this.frameColors = colors;
for (int i=0; i<flyers.size(); i++) {
ArrayList<String> commands = generateCommands(flyers.get(i));
for (String command: commands) {
ArrayList<String> commands = generateCommands(i);
for (String command : commands) {
try {
// out[i].println(command);
} catch (Exception e) {
......
Supports Markdown
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