Permalink
Browse files

put blinkeylights array, dome into their own classes.

  • Loading branch information...
1 parent 93a2f04 commit 1083e78fe93b67f86228fcadbe7c9062f77dcb6a @cibomahto cibomahto committed Mar 19, 2012
Showing with 116 additions and 72 deletions.
  1. +29 −66 BlinkeyDomeSimulator.pde
  2. +7 −6 BlinkeyLight.pde
  3. +41 −0 BlinkyLights.pde
  4. +39 −0 Dome.pde
View
@@ -3,92 +3,55 @@ import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import processing.opengl.*;
-int PIXELS_PER_FOOT = 10;
int DOME_RADIUS = 8;
-float rho = DOME_RADIUS*10;
-float factor = TWO_PI / 20.0;
-float x, y, z;
+
+int strips = 25; // Number of strips around the circumference of the sphere
+int lights_per_strip = 45*3; // Number of lights along the strip
PeasyCam pCamera;
-ArrayList<BlinkeyLight> blinkeyLights;
+BlinkeyLights blinkeyLights;
+
+Dome dome;
void setup() {
- size(1024,1024,OPENGL);
- pCamera = new PeasyCam(this, 0,0,10,200);
+ size(1024, 1024, OPENGL);
+ pCamera = new PeasyCam(this, 0, 0, 10, 200);
pCamera.setMinimumDistance(1);
pCamera.setMaximumDistance(150*10);
pCamera.setSuppressRollRotationMode();
pCamera.rotateX(0.2);
- pCamera.lookAt(0,-10,-20);
+ pCamera.lookAt(0, -10, -20);
pCamera.setWheelScale(0.05);
- blinkeyLights = new ArrayList<BlinkeyLight>();
-
- int strips = 25; // Number of strips around the circumference of the sphere
- int lights_per_strip = 45*3; // Number of lights along the strip
- int r = 78; // Radius
-
- for (int strip = 0; strip < strips; strip++) {
- for (int light = 0; light < lights_per_strip; light++) {
+ dome = new Dome(DOME_RADIUS);
- float inclination = HALF_PI + (HALF_PI)*((float)light/lights_per_strip);
- float azimuth = (2*PI)*((float)strip/strips);
-
- float x = r * cos(azimuth) * sin(inclination);
- float z = r * sin(azimuth) * sin(inclination);
- float y = r * cos(inclination);
+ blinkeyLights = new BlinkeyLights(DOME_RADIUS, strips, lights_per_strip);
+}
+int animationStep = 0;
-
- blinkeyLights.add(new BlinkeyLight(x,y,z));
-
- // print("inc= " + inclination + ", azi=" + azimuth + "\n");
- print(x + ", " + y + ", " + z + "\n");
+void updateLights() {
+ // Blink the lights
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ if (animationStep == i) {
+ blinkeyLights.get(i).setColor(color(255, 255, 255));
+ }
+ else {
+ blinkeyLights.get(i).setColor(color(0, 0, 255));
}
}
+ animationStep = (animationStep+1)%blinkeyLights.size();
}
-int animationStep = 0;
-
void draw() {
+ updateLights();
+
background(0);
- stroke(255,100,100);
- fill(200,50,50);
lights();
-
- for(float phi = 0.0; phi < HALF_PI; phi += factor) {
- beginShape(QUAD_STRIP);
- for(float theta = 0.0; theta < TWO_PI + factor; theta += factor) {
- x = rho * sin(phi) * cos(theta);
- z = rho * sin(phi) * sin(theta);
- 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);
- }
-
- // Blink the lights
- for (int i = 0; i < blinkeyLights.size(); i++) {
- if (animationStep == i) {
- blinkeyLights.get(i).setColor(color(255,255,255));
- }
- else {
- blinkeyLights.get(i).setColor(color(0,0,255));
- }
- }
- animationStep = (animationStep+1)%blinkeyLights.size();
-
- // Draw the lights
- for (int i = 0; i < blinkeyLights.size(); i++) {
- BlinkeyLight light = blinkeyLights.get(i);
- light.draw();
- }
+
+ dome.draw();
+
+ blinkeyLights.draw();
}
+
View
@@ -19,12 +19,13 @@ class BlinkeyLight {
void draw() {
pushMatrix();
- translate(x, y, z);
- stroke(c);
- fill(c);
- scale(rad);
- box(1);
- //sphere(1);
+ translate(x, y, z);
+ stroke(c);
+ fill(c);
+ scale(rad);
+ // Sphere is too slow, useless.
+ box(1);
+ //sphere(1);
popMatrix();
}
}
View
@@ -0,0 +1,41 @@
+
+class BlinkeyLights {
+ ArrayList<BlinkeyLight> blinkeyLights;
+
+ BlinkeyLights( int radius_, int strips_, int lights_per_strip_) {
+ blinkeyLights = new ArrayList<BlinkeyLight>();
+
+ radius_ = radius_ * 10;
+
+ for (int strip = 0; strip < strips_; strip++) {
+ for (int light = 0; light < lights_per_strip_; light++) {
+
+ 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));
+
+ // print("inc= " + inclination + ", azi=" + azimuth + "\n");
+ print(x + ", " + y + ", " + z + "\n");
+ }
+ }
+ }
+
+ int size() {
+ return blinkeyLights.size();
+ }
+
+ BlinkeyLight get(int i) {
+ return blinkeyLights.get(i);
+ }
+
+ void draw() {
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ (blinkeyLights.get(i)).draw();
+ }
+ }
+}
View
@@ -0,0 +1,39 @@
+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);
+ fill(200,50,50);
+
+ 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);
+ }
+ }
+
+}
+

0 comments on commit 1083e78

Please sign in to comment.