Browse files

Revert "initial"

This reverts commit 1e3de10.
  • Loading branch information...
1 parent 1e3de10 commit 0cf0bd91f5b9a26d26e5e8715832964b3f471f3a @cibomahto cibomahto committed Oct 18, 2012
Showing with 364 additions and 195 deletions.
  1. +187 −0 BlinkeyDomeSimulator.pde
  2. +30 −0 BlinkeyLight.pde
  3. +42 −0 BlinkeyLights.pde
  4. +0 −99 DaftPunkSimulator.pde
  5. +40 −0 Dome.pde
  6. +26 −0 Hud.pde
  7. +39 −0 ImageHUD.pde
  8. +0 −17 Pattern.pde
  9. +0 −28 PhysicalRailSegment.pde
  10. +0 −15 Rail.pde
  11. +0 −18 RailSegmentPattern.pde
  12. +0 −18 VirtualRailSegment.pde
View
187 BlinkeyDomeSimulator.pde
@@ -0,0 +1,187 @@
+import peasy.org.apache.commons.math.*;
+import peasy.*;
+import peasy.org.apache.commons.math.geometry.*;
+import processing.opengl.*;
+import javax.media.opengl.GL;
+import hypermedia.net.*;
+
+import java.util.concurrent.*;
+
+int DOME_RADIUS = 8;
+int strips = 25; // Number of strips around the circumference of the sphere
+int lights_per_strip = 32*5; // Number of lights along the strip
+int packet_length = strips*lights_per_strip*3 + 1;
+
+Boolean demoMode = true;
+BlockingQueue newImageQueue;
+
+DemoTransmitter demoTransmitter;
+
+UDP udp;
+
+PeasyCam pCamera;
+BlinkeyLights blinkeyLights;
+Dome dome;
+Hud hud;
+ImageHud imageHud;
+
+PFont font;
+PImage groundTexture;
+
+void setup() {
+ size(1024, 850, OPENGL);
+ colorMode(RGB,255);
+ frameRate(60);
+
+ // Turn on vsync to prevent tearing
+ PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; //processing graphics object
+ GL gl = pgl.beginGL(); //begin opengl
+ gl.setSwapInterval(2); //set vertical sync on
+ pgl.endGL(); //end opengl
+
+ //size(1680, 1000, OPENGL);
+ pCamera = new PeasyCam(this, 0, 0, 0, 200);
+ pCamera.setMinimumDistance(.2);
+ pCamera.setMaximumDistance(150*10);
+ pCamera.setSuppressRollRotationMode();
+ pCamera.rotateX(.6);
+
+ pCamera.setWheelScale(0.05);
+
+ newImageQueue = new ArrayBlockingQueue(2);
+
+ udp = new UDP( this, 58082 );
+ udp.listen( true );
+
+ font = loadFont("Serif-24.vlw");
+ hud = new Hud();
+ dome = new Dome(DOME_RADIUS);
+ blinkeyLights = new BlinkeyLights(DOME_RADIUS, strips, lights_per_strip);
+ imageHud = new ImageHud(20, height-160-20, strips, lights_per_strip);
+
+ groundTexture = loadImage("Lost Lake.jpg");
+
+ demoTransmitter = new DemoTransmitter();
+ demoTransmitter.start();
+}
+
+int animationStep = 0;
+
+int maxConvertedByte = 0;
+
+int convertByte(byte b) {
+ int c = (b<0) ? 256+b : b;
+
+ if (c > maxConvertedByte) {
+ maxConvertedByte = c;
+ println("Max Converted Byte is now " + c);
+ }
+
+ return c;
+}
+
+void receive(byte[] data, String ip, int port) {
+ //println(" new datas!");
+ if (demoMode) {
+ println("Started receiving data from " + ip + ". Demo mode disabled.");
+ demoMode = false;
+ }
+
+ if (data[0] == 2) {
+ // We got a new mode, so copy it out
+ String modeName = new String(data);
+ hud.setHudText(modeName);
+ return;
+ }
+
+ if (data[0] != 1) {
+ println("Packet header mismatch. Expected 1, got " + data[0]);
+ return;
+ }
+
+ if (data.length != packet_length) {
+ println("Packet size mismatch. Expected "+packet_length+", got " + data.length);
+ return;
+ }
+
+ if (newImageQueue.size() > 0) {
+ println("Buffer full, dropping frame!");
+ return;
+ }
+
+ color[] newImage = new color[strips*lights_per_strip];
+
+ for (int i=0; i< strips*lights_per_strip; i++) {
+ // Processing doesn't like it when you call the color function while in an event
+ // go figure
+ newImage[i] = (int)(0xff<<24 | convertByte(data[i*3 + 1])<<16) |
+ (convertByte(data[i*3 + 2])<<8) |
+ (convertByte(data[i*3 + 3]));
+ }
+ try {
+ newImageQueue.put(newImage);
+ }
+ catch( InterruptedException e ) {
+ println("Interrupted Exception caught");
+ }
+}
+
+void drawGround() {
+ stroke(92, 51);
+ fill(92, 51);
+
+ int tilefactor = 10;
+ float bound = DOME_RADIUS*10*4;
+
+ for (int x = 0; x < tilefactor; x++) {
+ for (int y = 0; y < tilefactor; y++) {
+ pushMatrix();
+ translate(0, 0.5, 0);
+
+ translate(bound/tilefactor*x-bound/2, 0, bound/tilefactor*y-bound/2);
+
+ beginShape();
+ texture(groundTexture);
+ textureMode(NORMALIZED);
+
+ vertex(0, .5, 0, 0, 0);
+ vertex(bound/tilefactor, .5, 0, 1, 0);
+ vertex(bound/tilefactor, .5, bound/tilefactor, 1, 1);
+ vertex(0, .5, bound/tilefactor, 0, 1);
+ endShape();
+ popMatrix();
+ }
+ }
+}
+
+void drawFPS() {
+ pCamera.beginHUD();
+ noLights();
+ fill(255, 255, 255);
+ textFont(font);
+ textAlign(CENTER);
+ text(int(frameRate), width - 50, height - 50);
+ pCamera.endHUD();
+}
+
+void draw() {
+ background(0);
+ lights();
+
+ drawGround();
+
+ dome.draw();
+ blinkeyLights.draw();
+
+ hud.draw();
+ imageHud.draw();
+
+ drawFPS();
+
+ if (newImageQueue.size() > 0) {
+ color[] newImage = (color[])newImageQueue.remove();
+ blinkeyLights.update(newImage);
+ imageHud.update(newImage);
+ }
+}
+
View
30 BlinkeyLight.pde
@@ -0,0 +1,30 @@
+import processing.opengl.*;
+
+class BlinkeyLight {
+ float rad = .5;
+ float x = 0;
+ float y = 0;
+ float z = 0;
+ color c = color(1,1,1);
+
+ BlinkeyLight(float x_, float y_, float z_) {
+ x = x_;
+ y = y_;
+ z = z_;
+ }
+
+ void setColor(color c_) {
+ c = c_;
+ }
+
+ void draw() {
+ pushMatrix();
+ translate(x, y, z);
+ stroke(c);
+ fill(c);
+ //scale(rad);
+ //ellipse(0,0,1.5,1.5);
+ point(0,0);
+ popMatrix();
+ }
+}
View
42 BlinkeyLights.pde
@@ -0,0 +1,42 @@
+
+class BlinkeyLights {
+ ArrayList<BlinkeyLight> blinkeyLights;
+
+ BlinkeyLights( int radius_, int strips_, int lights_per_strip_) {
+ blinkeyLights = new ArrayList<BlinkeyLight>();
+
+ radius_ = radius_ * 10;
+
+ for (int light = lights_per_strip_ -1; light > 0; light--) {
+ for (int strip = 0; strip < strips_; strip++) {
+
+
+ float inclination = HALF_PI + (HALF_PI)*((float)light/lights_per_strip_);
+ float azimuth = (2*PI)*((float)strip/strips_);
+
+ float x = radius_ * cos(azimuth) * sin(inclination);
+ float z = radius_ * sin(azimuth) * sin(inclination);
+ float y = radius_ * cos(inclination);
+
+ blinkeyLights.add(new BlinkeyLight(x, y, z));
+ }
+ }
+ }
+
+ int size() {
+ return blinkeyLights.size();
+ }
+
+ void update(color[] imageData) {
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ blinkeyLights.get(i).setColor(imageData[i]);
+ }
+ }
+
+ void draw() {
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ (blinkeyLights.get(i)).draw();
+ }
+ }
+}
+
View
99 DaftPunkSimulator.pde
@@ -1,99 +0,0 @@
-import hypermedia.net.*;
-import java.util.concurrent.*;
-
-int lights_per_strip = 32*5; // Number of lights along the strip
-int strips = 8;
-int packet_length = strips*lights_per_strip*3 + 1;
-
-Boolean demoMode = true;
-BlockingQueue newImageQueue;
-
-UDP udp;
-List<VirtualRailSegment> leftRail; // Rail segment mapping
-
-int animationStep = 0;
-int maxConvertedByte = 0;
-
-void setup() {
- size(1024, 850);
- colorMode(RGB,255);
- frameRate(60);
- newImageQueue = new ArrayBlockingQueue(2);
-
- udp = new UDP( this, 58082 );
- udp.listen( true );
-
- leftRail = Collections.synchronizedList(new LinkedList<VirtualRailSegment>());
- leftRail.add(new VirtualRailSegment("A2", 0, 29, 24));
- leftRail.add(new VirtualRailSegment("A3", 0, 55, 24));
- leftRail.add(new VirtualRailSegment("A4", 0, 81, 25));
- leftRail.add(new VirtualRailSegment("A5", 0, 107, 25));
- leftRail.add(new VirtualRailSegment("A6", 0, 132, 25));
-
-}
-
-
-int convertByte(byte b) {
- int c = (b<0) ? 256+b : b;
-
- if (c > maxConvertedByte) {
- maxConvertedByte = c;
- println("Max Converted Byte is now " + c);
- }
-
- return c;
-}
-
-void receive(byte[] data, String ip, int port) {
- //println(" new datas!");
- if (demoMode) {
- println("Started receiving data from " + ip + ". Demo mode disabled.");
- demoMode = false;
- }
-
- if (data[0] == 2) {
- // We got a new mode, so copy it out
- String modeName = new String(data);
-
- return;
- }
-
- if (data[0] != 1) {
- println("Packet header mismatch. Expected 1, got " + data[0]);
- return;
- }
-
- if (data.length != packet_length) {
- println("Packet size mismatch. Expected "+packet_length+", got " + data.length);
- return;
- }
-
- if (newImageQueue.size() > 0) {
- println("Buffer full, dropping frame!");
- return;
- }
-
- color[] newImage = new color[strips*lights_per_strip];
-
- for (int i=0; i< strips*lights_per_strip; i++) {
- // Processing doesn't like it when you call the color function while in an event
- // go figure
- newImage[i] = (int)(0xff<<24 | convertByte(data[i*3 + 1])<<16) | (convertByte(data[i*3 + 2])<<8) | (convertByte(data[i*3 + 3]));
- }
- try {
- newImageQueue.put(newImage);
- }
- catch( InterruptedException e ) {
- println("Interrupted Exception caught");
- }
-}
-
-
-void draw() {
- background(0);
-
- if (newImageQueue.size() > 0) {
- color[] newImage = (color[])newImageQueue.remove();
- }
-}
-
View
40 Dome.pde
@@ -0,0 +1,40 @@
+import processing.opengl.*;
+
+
+
+class Dome {
+ float rho;
+ float factor;
+
+ Dome(float radius_) {
+
+ rho = radius_*10;
+ factor = TWO_PI / 20.0;
+ }
+
+ void draw() {
+ stroke(255,100,100,50);
+ strokeWeight(1);
+ noFill();//fill(200,50,50,0);
+
+ for (float phi = 0.0; phi < HALF_PI; phi += factor) {
+ beginShape(QUAD_STRIP);
+ for (float theta = 0.0; theta < TWO_PI + factor; theta += factor) {
+ float x = rho * sin(phi) * cos(theta);
+ float z = rho * sin(phi) * sin(theta);
+ float y = -rho * cos(phi);
+
+ vertex(x, y, z);
+
+ x = rho * sin(phi + factor) * cos(theta);
+ z = rho * sin(phi + factor) * sin(theta);
+ y = -rho * cos(phi + factor);
+
+ vertex(x, y, z);
+ }
+ endShape(CLOSE);
+ }
+ }
+
+}
+
View
26 Hud.pde
@@ -0,0 +1,26 @@
+class Hud {
+
+ int boxHeight = 155;
+ String hudText = new String("Dome Shit");
+
+ void setHudText(String newText) {
+ hudText = newText;
+ }
+
+ void draw() {
+ pCamera.beginHUD();
+ noLights();
+ strokeWeight(0);
+ fill(255,255,255,200);
+ rect(10,10,width-20,30);
+ textFont(font);
+ fill(0,0,0);
+ textAlign(CENTER);
+ text(hudText, width/2-20, 32);
+ fill(255,255,255,100);
+ rectMode(CORNER);
+ rect(10, height-boxHeight-10, 45,boxHeight);
+ pCamera.endHUD();
+ }
+
+}
View
39 ImageHUD.pde
@@ -0,0 +1,39 @@
+class ImageHud {
+ PImage img;
+ float x;
+ float y;
+
+ ImageHud(float x_, float y_, int w_, int h_) {
+ x = x_;
+ y = y_;
+ img = new PImage(w_,h_);
+ }
+
+ void update(color[] imageData) {
+ img.loadPixels();
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ img.pixels[i] = imageData[i];
+ }
+ img.updatePixels();
+ }
+
+ void draw() {
+ pCamera.beginHUD();
+ image(img, x, y);
+ pCamera.endHUD();
+
+// pushMatrix();
+// translate(0, 0.5, 0);
+//
+// beginShape();
+// texture(groundTexture);
+// textureMode(NORMALIZED);
+//
+// vertex(w_, h_, 0, 0, 0);
+// vertex(bound, .5, -bound, 1, 0);
+// vertex(bound, .5, bound, 1, 1);
+// vertex(-bound, .5, bound, 0, 1);
+// endShape();
+// popMatrix();
+ }
+}
View
17 Pattern.pde
@@ -1,17 +0,0 @@
-class Pattern {
- public boolean m_isDone = false;
- public int m_channel;
- public int m_pitch;
- public int m_velocity;
-
- Pattern(int channel, int pitch, int velocity) {
- m_channel = channel;
- m_pitch = pitch;
- m_velocity = velocity;
- }
-
- void draw() {
- }
-
-}
-
View
28 PhysicalRailSegment.pde
@@ -1,28 +0,0 @@
-class VirtualRailSegment {
- String m_name;
- int m_len;
- PVector m_start;
- PVector m_end;
-
- VirtualRailSegment(String name, PVector start, PVector end, int len) {
- m_name = name;
- m_len = len;
- m_start = start;
- m_end = end;
- }
-
- void draw(color c) {
- stroke(c);
-
- for (int i; i < m_len; i++) {
-
- amt = (1.0 / len) * i;
-
- int x = lerp(m_start.x, m_end.x, amt);
- int y = lerp(m_start.y, m_end.y, amt);
-
- rect(x, y, 5, 5);
- }
-
- }
-}
View
15 Rail.pde
@@ -1,15 +0,0 @@
-class Rail {
-
- private LinkedList<RailSegment> rail_list;
-
- Rail(LinkedList<RailSegment> _rail_list) {
- rail_list = _rail_list;
- }
-
-
- void draw() {
-
-
-
- }
-}
View
18 RailSegmentPattern.pde
@@ -1,18 +0,0 @@
-class RailSegmentPattern extends Pattern {
- RailSegment m_segment;
-
-
- RailSegmentPattern(RailSegment segment, int channel, int pitch, int velocity) {
- super(channel, pitch, velocity);
- m_segment = segment;
- }
-
-
- void draw() {
- // Display one flash of color, then end.
- m_segment.draw(color(0,0,255));
-
- m_isDone = true;
- }
-}
-
View
18 VirtualRailSegment.pde
@@ -1,18 +0,0 @@
-class VirtualRailSegment {
- String m_name;
- int m_strip;
- int m_offset;
- int m_length;
-
- VirtualRailSegment(String name, int strip, int offset, int length) {
- m_name = name;
- m_strip = strip;
- m_offset = offset;
- m_length = length;
- }
-
- void draw(color c) {
- stroke(c);
- line(m_strip, m_offset, m_strip, m_offset + m_length);
- }
-}

0 comments on commit 0cf0bd9

Please sign in to comment.