Commit b27e4cf9 authored by Philip Levis's avatar Philip Levis
Browse files

Merge branch 'master' of code.stanford.edu:plevis/ee185 into dev/pal

parents ff62ae5c a2b909f1
import heronarts.lx.*;
import heronarts.lx.audio.*;
import heronarts.lx.color.LXColor;
import heronarts.lx.effect.*;
import heronarts.lx.model.*;
import heronarts.lx.output.*;
import heronarts.lx.parameter.*;
import heronarts.lx.pattern.*;
import heronarts.lx.studio.LXStudio;
import heronarts.lx.transform.*;
import heronarts.lx.modulator.*;
......@@ -46,14 +48,12 @@ UI3dContext viewContext;
FlyerHighlighter flyerHighlighter;
class ProcessingEngine extends FlightEngine {
ProcessingEngine(String projectPath, FlightModel model, LXStudio lx) {
super(projectPath, model, lx);
}
}
// Derived from Mark Slee's LXStudioApp example
private static final String WINDOW_TITLE = "FLIGHT Graphical UI";
private static int WIDTH = 1280;
......@@ -67,17 +67,17 @@ void settings() {
// Starts wings as Red and bodies as Blue, why not.
void initializeModel() {
model = new Model(flyerConfigurations).getFlightModel();
List<LightSamplePoint> wingLights = model.getLightsOfAllWings();
for (LightSamplePoint light: wingLights) {
light.setColor(LXColor.hsb(0, 0.5, 0.8));
}
List<LightSamplePoint> bodyLights = model.getLightsOfAllBodies();
for (LightSamplePoint light: bodyLights) {
light.setColor(LXColor.hsb(0.7, 0.5, 0.8));
}
model = new Model(flyerConfigurations).getFlightModel();
List<LightSamplePoint> wingLights = model.getAllWingsLights();
for (LightSamplePoint light: wingLights) {
light.setColor(LXColor.hsb(0, 0.5, 0.8));
}
List<LightSamplePoint> bodyLights = model.getAllBodyLights();
for (LightSamplePoint light: bodyLights) {
light.setColor(LXColor.hsb(0.7, 0.5, 0.8));
}
}
......@@ -87,20 +87,20 @@ void setup() {
IO io = new IO(sketchPath());
flyerConfigurations = io.loadConfigFile(Config.FLYER_CONFIG_FILE);
initializeModel();
lx = new LXStudio(this, model);
lx = new LXStudio(this, model);
}
void initializeUI(LXStudio lx, LXStudio.UI ui) {
pengine = new ProcessingEngine(sketchPath(), model, lx);
lx.engine.setThreaded(true);
lx.engine.addLoopTask(new FadeTest(lx));
lx.engine.addLoopTask(new BlackPinkTest(lx));
}
public void onUIReady(LXStudio lx, LXStudio.UI ui) {
System.out.println("Creating UI.");
FlightGui.this.flyerHighlighter = new FlyerHighlighter(lx, flyerConfigurations);
lx.addEffect(flyerHighlighter);
configureUI(ui);
System.out.println("Creating UI.");
FlightGui.this.flyerHighlighter = new FlyerHighlighter(lx, flyerConfigurations);
lx.addEffect(flyerHighlighter);
configureUI(ui);
}
void configureUI(LXStudio.UI ui) {
......@@ -140,25 +140,23 @@ void configureUI(LXStudio.UI ui) {
viewContext.setInteractionMode(UI3dContext.InteractionMode.ZOOM);
viewContext.setRadius(85 * GeometryConstants.FEET);
viewContext.addComponent(new UIFlightDisplay());
viewContext.addComponent(new UIFlightDisplay(model));
// Adds the control panel for selecting and moving Flyers
ui.addLayer(viewContext);
ui.addLayer(new UIFlyerConfiguration(ui));
}
@Override
public void draw() {
//background(#222222);
// The actual model and such are drawn in their own
// draw methods, e.g. UIFlightDisplay.onDraw.
//background(#222222);
// The actual model and such are drawn in their own
// draw methods, e.g. UIFlightDisplay.onDraw.
}
void keyPressed() {
switch (key) {
case 'a':
System.out.println("Pressed a");
break;
case 'a':
System.out.println("Pressed a");
break;
}
}
import java.util.List;
class UIFlyerConfiguration extends UIWindow {
final static int WIDTH = 140;
final static int HEIGHT = 360;
......@@ -14,7 +16,7 @@ class UIFlyerConfiguration extends UIWindow {
private UIToggleSet pipeToggle; // Ceiling: which pipe
private UISlider mountPointSlider; // Ceiling: were on pipe
private UIToggleSet faceToggle;
private UILabel name;
private UILabel text;
......@@ -33,7 +35,7 @@ class UIFlyerConfiguration extends UIWindow {
pipeToggle.setVisible(false);
positionSlider.setVisible(false);
mountPointSlider.setVisible(false);
if (face.equals("C")) {
pipeToggle.setVisible(true);
mountPointSlider.setVisible(true);
......@@ -47,15 +49,15 @@ class UIFlyerConfiguration extends UIWindow {
} else {
System.err.println("Unrecognized face: " + face + "; disable all controls.");
}
}
UIFlyerConfiguration(UI ui) {
super(ui, "LAYOUT TOOL",
BORDER, FlightGui.this.height - (HEIGHT + BORDER),
WIDTH, HEIGHT);
makeEnableButton();
makeFlyerSelect();
makeFaceToggle();
......@@ -67,17 +69,18 @@ class UIFlyerConfiguration extends UIWindow {
makePositionSlider();
makePipeToggle();
makeMountingSlider();
name = new UILabel(0, 0, 0, 16);
name.setLabel("?");
text = new UILabel(0, 0, 0, 16);
text.setLabel("?");
float yPos = TITLE_LABEL_HEIGHT;
yPos += ROW_HEIGHT;
yPos = labelRow(yPos, "FLYER #", flyerSelect);
yPos = labelRow(yPos, "NAME", name);
yPos = labelRow(yPos, "TEXT", text);
......@@ -90,7 +93,7 @@ class UIFlyerConfiguration extends UIWindow {
yPos = labelRow(yPos, "POS", positionSlider);
yPos = labelRow(yPos, "PIPE", pipeToggle);
yPos = labelRow(yPos, "MOUNT", mountPointSlider);
new UIButton(4, yPos, this.width-8, 20) {
void onToggle(boolean active) {
if (active) {
......@@ -103,10 +106,10 @@ class UIFlyerConfiguration extends UIWindow {
}
}
}.setMomentary(true).setLabel("Save Changes").addToContainer(this);
setFlyer();
}
private void makeEnableButton() {
this.enableButton = new UIButton(4, TITLE_LABEL_HEIGHT, width-8, 20) {
public void onToggle(boolean enabled) {
......@@ -137,7 +140,7 @@ class UIFlyerConfiguration extends UIWindow {
};
flyerHighlighter.flyerIndex.addListener(selectListener);
}
private void makeFaceToggle() {
this.faceToggle = new UIToggleSet() {
protected void onToggle(String value) {
......@@ -146,7 +149,7 @@ class UIFlyerConfiguration extends UIWindow {
flyerHighlighter.reloadModel();
}
};
// We have to convert to intern() because of a bug in ToggleSet
// that compares with == rather than .equals(); if you don't
// use .intern(), then strings don't match. -pal
......@@ -157,7 +160,7 @@ class UIFlyerConfiguration extends UIWindow {
}
this.faceToggle.setOptions(options);
}
private void makeHangLengthSlider() {
BoundedParameter hang = new BoundedParameter("Hang", 0, 8 * GeometryConstants.FEET);
this.hangDistanceSlider = new UISlider(0, 0, 0, 16) {
......@@ -223,7 +226,7 @@ class UIFlyerConfiguration extends UIWindow {
this.positionSlider.setParameter(pos);
}
private void makeMountingSlider() {
BoundedParameter mount = new BoundedParameter("Mount", 0, 0, 1);
this.mountPointSlider = new UISlider(0, 0, 0, 16) {
......@@ -234,7 +237,7 @@ class UIFlyerConfiguration extends UIWindow {
};
this.mountPointSlider.setParameter(mount);
}
private void makePipeToggle() {
this.pipeToggle = new UIToggleSet() {
protected void onToggle(String str) {
......@@ -245,7 +248,7 @@ class UIFlyerConfiguration extends UIWindow {
String[] pipeOptions = {"0".intern(), "1".intern(), "2".intern(), "3".intern(), "4".intern(), "5".intern(), "6".intern(), "7".intern()};
pipeToggle.setOptions(pipeOptions);
}
float labelRow(float yPos, String label, UI2dComponent obj) {
new UILabel(4, yPos, 50, 20)
.setLabel(label)
......@@ -257,7 +260,7 @@ class UIFlyerConfiguration extends UIWindow {
yPos += ROW_HEIGHT;
return yPos;
}
void setFlyer() {
FlyerConfig config = flyerConfigurations[flyerHighlighter.flyerIndex.getValuei()];
xSlider.getParameter().setValue(config.faceConfig().x);
......@@ -268,4 +271,3 @@ class UIFlyerConfiguration extends UIWindow {
text.setLabel(config.metadata().text);
}
}
class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
final float[] VBAR_OFFSETS;
final float[] HBAR_OFFSETS;
final float[] BACK_WALL_OFFSETS;
FlightModel model;
UIFlightDisplay() {
UIFlightDisplay(FlightModel model) {
super();
this.model = model;
VBAR_OFFSETS = new float[GeometryConstants.FRONT_WINDOW_VBAR_SPACINGS.length];
float xPos = 0.0;
for (int i = 0; i < GeometryConstants.FRONT_WINDOW_VBAR_SPACINGS.length; i++) {
......@@ -48,9 +50,6 @@ class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
// drawing it, then popping the tranformation. This allows the
// draw code to just operate in a normalized coordinate space. -pal
for (Flyer flyer : model.getFlyers()) {
int c = flyer.getBodyLightPoint().getColor();
pg.fill(c);
pg.pushMatrix();
float x = flyer.getX();
float y = flyer.getY();
......@@ -78,8 +77,8 @@ class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
pg.endShape(CLOSE);
// Left wing
LightSamplePoint[] leftLights = flyer.getLeftWing().getLightPoints();
pg.fill(leftLights[0].getColor()); // Just use point 0 for the wing for now
List<LightSamplePoint> leftLights = model.getFlyerLeftWingLights(flyer.getIndex());
pg.fill(leftLights.get(0).getColor()); // Just use point 0 for the wing for now
pg.beginShape();
pg.vertex(4.01, 0, 4.96);
pg.vertex(9.12, 0, 11.17);
......@@ -87,8 +86,8 @@ class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
pg.endShape(CLOSE);
// Right wing
LightSamplePoint[] rightLights = flyer.getRightWing().getLightPoints();
pg.fill(rightLights[0].getColor()); // Just use point 0 for the wing for now
List<LightSamplePoint> rightLights = model.getFlyerRightWingLights(flyer.getIndex());
pg.fill(rightLights.get(0).getColor()); // Just use point 0 for the wing for now
pg.beginShape();
pg.vertex(4.01, 0, -4.96);
pg.vertex(9.12, 0, -11.17);
......@@ -96,8 +95,8 @@ class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
pg.endShape(CLOSE);
// Body shell
LightSamplePoint light = flyer.getBodyLightPoint();
pg.fill(light.getColor());
LightSamplePoint bodyLight = model.getFlyerBodyLight(flyer.getIndex());
pg.fill(bodyLight.getColor());
pg.beginShape();
pg.vertex(0, 0, 0);
......@@ -126,11 +125,11 @@ class UIFlightDisplay extends UI3dComponent implements GeometryConstants {
private void computeFlyerLightsAndWings() {
//Wing[] wings = (Wing[]) model.getAllWings().toArray();
for (LightSamplePoint l: model.getLightsOfAllWings()) {
for (LightSamplePoint l: model.getAllWingsLights()) {
//l.setColor(LXColor.RED);
}
for (LightSamplePoint l: model.getLightsOfAllBodies()) {
for (LightSamplePoint l: model.getAllBodyLights()) {
//l.setColor(LXColor.BLUE);
}
......
File mode changed from 100644 to 100755
......@@ -3,5 +3,4 @@ final class Config {
public static final String FLYER_CONFIG_FILE = "data/flyers.json";
public static final String OUTPUT_NAMES_FILE = "data/outputs.json";
public static final String[] FACE_NAMES = {"C", "F", "I", "E"};
}
import java.util.List;
interface Flight extends GeometryConstants {
/*
* The naming scheme for the pattern getter functions are as follows:
* get [required]
* all flyers or one flyer (All vs Flyer) [required]
* part specifier if applicable (LeftWing(s), RightWing(s), Wings, Body) [optional]
* light specifier if applicable (PositionIndexed) [optional]
* Light/Lights
*/
abstract interface Flight extends GeometryConstants {
/**
* for movement pattern
* pattern getters for all flyers
*/
List<Wing> getLeftWings();
List<Wing> getRightWings();
/* ------------- all flyers, motion ------------- */
List<Wing> getAllWings();
List<Wing> getAllLeftWings();
List<Wing> getAllRightWings();
/**
* for light pattern
*/
List<LightSamplePoint> getLightsOfLeftWings();
List<LightSamplePoint> getLightsOfRightWings();
List<LightSamplePoint> getLightsOfAllWings();
List<LightSamplePoint> getHeadLightOfLeftWings();
List<LightSamplePoint> getHeadLightOfRightWings();
/* ------------- all flyers, lights ------------- */
List<LightSamplePoint> getAllLights();
List<LightSamplePoint> getHeadLightOfAllWings();
List<LightSamplePoint> getAllBodyLights();
List<LightSamplePoint> getAllWingsLights();
List<LightSamplePoint> getAllWingsPositionIndexedLights(int positionIndex); // head
List<LightSamplePoint> getSideLightOfLeftWings();
// left wings
List<LightSamplePoint> getAllLeftWingLights();
List<LightSamplePoint> getAllLeftWingPositionIndexedLights(int positionIndex);
List<LightSamplePoint> getSideLightOfRightWings();
// right wings
List<LightSamplePoint> getAllRightWingLights();
List<LightSamplePoint> getAllRightWingPositionIndexedLights(int positionIndex);
List<LightSamplePoint> getSideLightOfAllWings();
List<LightSamplePoint> getTailLightOfLeftWings();
/**
* pattern getters for individual flyers
*/
/* ------------- one flyer, motion ------------- */
Wing getFlyerLeftWing(int flyerIndex);
Wing getFlyerRightWing(int flyerIndex);
List<Wing> getFlyerWings(int flyerIndex);
List<LightSamplePoint> getTailLightOfRightWings();
/* ------------- one flyer, lights ------------- */
List<LightSamplePoint> getFlyerLights(int flyerIndex);
List<LightSamplePoint> getTailLightOfAllWings();
LightSamplePoint getFlyerBodyLight(int flyerIndex);
List<LightSamplePoint> getFlyerWingsLights(int flyerIndex);
List<LightSamplePoint> getFlyerWingsPositionIndexedLights(int flyerIndex, int positionIndex);
List<LightSamplePoint> getLightsOfAllBodies();
List<LightSamplePoint> getFlyerLeftWingLights(int flyerIndex);
LightSamplePoint getFlyerLeftWingPositionIndexedLights(int flyerIndex, int positionIndex);
List<LightSamplePoint> getAllLights();
List<LightSamplePoint> getFlyerRightWingLights(int flyerIndex);
LightSamplePoint getFlyerRightWingPositionIndexedLights(int flyerIndex, int positionIndex);
FlyerConfig[] getFlyerConfigs();
/**
* flyer config getters
*/
Flyer getFlyer(int i);
Flyer[] getFlyers();
/**
* This defines the positions of the flyers, which are
* index,
* x (left to right), y (front to back), z (bottom to top),
* rotation in degrees, and tilt (3 options)
*/
/**
* This defines the positions of the flyers, which are
* index,
* x (left to right), y (front to back), z (bottom to top),
* rotation in degrees, and tilt (3 options)
*/
FlyerConfig[] getFlyerConfigs();
List<Flyer> getFlyers();
}
\ No newline at end of file
interface Flyer extends GeometryConstants {
public final static int PIXELS_PER_BODY =
LightSamplePoint.LightCorners.BODY.numPixels;
import java.util.List;
public final static int PIXELS_PER_FLYER =
NUM_WINGS_PER_FLYER *
(LightSamplePoint.LightCorners.HEAD.numPixels +
LightSamplePoint.LightCorners.SIDE.numPixels +
LightSamplePoint.LightCorners.TAIL.numPixels) +
import heronarts.lx.model.LXModel;
import heronarts.lx.model.LXPoint;
abstract interface Flyer extends GeometryConstants {
public final static int PIXELS_PER_BODY =
LightSamplePoint.LightCorners.BODY.numPixels;
int getIndex();
......@@ -21,16 +19,18 @@ interface Flyer extends GeometryConstants {
float getTilt();
Wing[] getWings();
LXModel[] getWings();
Wing getLeftWing();
Wing getRightWing();
LightSamplePoint getBodyLightPoint();
LightSamplePoint[] getLightPoints();
LXPoint getBodyLightPoint();
List<? extends LXPoint> getLightPoints();
FlyerConfig getConfig();
}
class FlyerConfig {
......@@ -49,6 +49,7 @@ class FlyerConfig {
float mountPoint;
float hangDistance;
@Override
public String toString() {
String s = "Face: \"" + face + "\"\n";
s += "x: " + x + "\n";
......@@ -59,7 +60,7 @@ class FlyerConfig {
s += "hangDistance: " + hangDistance + "\n";
return s;
}
}
static class FlyerMetadata {
......@@ -69,6 +70,7 @@ class FlyerConfig {
String department;
int year;
@Override
public String toString() {
String s = "Name: " + name + "\n";
s += "Text: " + text + "\n";
......@@ -87,6 +89,7 @@ class FlyerConfig {
return metadata;
}
@Override
public String toString() {
String s = "Index: " + index + "\n";
s += metadata.toString();
......
import java.util.List;
import heronarts.lx.LX;
import heronarts.lx.LXLayer;
import heronarts.lx.color.LXColor;
import heronarts.lx.effect.LXEffect;
import heronarts.lx.modulator.SinLFO;
import heronarts.lx.parameter.BooleanParameter;
import heronarts.lx.parameter.DiscreteParameter;
import heronarts.lx.parameter.LXParameter;
......@@ -31,7 +27,7 @@ class FlyerHighlighter extends Effect {
addModulator(strobe).start();
addLayer(new HighlightLayer());
}
FlyerConfig getConfig() {
return flyerConfigurations[flyerIndex.getValuei()];
}
......@@ -39,7 +35,7 @@ class FlyerHighlighter extends Effect {
Flyer getFlyer() {
return model.getFlyer(flyerIndex.getValuei());
}
void reloadModel() {
lx.setModel(new FlightModel(flyerConfigurations));
}
......@@ -47,10 +43,10 @@ class FlyerHighlighter extends Effect {
void trigger() {
strobe.trigger();
}
void highlight() {
if (isEnabled()) {
for (LightSamplePoint point: getFlyer().getLightPoints()) {
for (LightSamplePoint point: model.getFlyerLights(getFlyer().getIndex())) {
int oldColor = point.getColor();
float val = strobe.getValuef();
int highlightColor = lx.hsb(0, 0, val);
......@@ -61,19 +57,21 @@ class FlyerHighlighter extends Effect {
}
}
}
public void run(double deltaMs) {}
@Override
public void run(double deltaMs, double foo) {}
class HighlightLayer extends LXLayer {
HighlightLayer() {
super(FlyerHighlighter.this.lx);
}
@Override
public void run(double deltaMs) {
if (isEnabled()) {
for (LightSamplePoint point: getFlyer().getLightPoints()) {
for (LightSamplePoint point: ((FlightModel) model).getFlyerLights(getFlyer().getIndex())) {
int oldColor = point.getColor();
float val = strobe.getValuef();
int highlightColor = lx.hsb(0, 0, val);
......
......@@ -6,10 +6,10 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import heronarts.lx.LX;
import heronarts.lx.model.LXPoint;
import heronarts.lx.output.LXOutput;
import java.awt.Color;
......@@ -21,7 +21,7 @@ import java.awt.Color;
*/
public class Generator extends LXOutput implements GeometryConstants {
final Flight flight;
final Flyer[] flyers;
final List<Flyer> flyers;
final DataInput[] in;
final PrintStream[] out;
......@@ -40,10 +40,10 @@ public class Generator extends LXOutput implements GeometryConstants {