nick /224 /floatingboxes

import processing.opengl.*;

squiggle[] s = new squiggle[200];

float a;
void setup(){
  size(800,600, OPENGL);
  smooth();
  for(int i = 0; i < s.length; i++){
    s[i] = new squiggle();
  }

  //  for(int i = 0; i < s2.length; i++){
  //  s2[i] = new squiggle2();
 // }
  //fill(0,20);
  noStroke();
  //fill(0);
}


void draw(){
  background(255);
  //translate(mouseX,mouseY);

  pointLight(150, 0, 0,   // Color
             200, -150, 0); // Position

  // Blue directional light from the left
  directionalLight(0, 102, 255, // Color
                   1, 0, 0);    // The x-, y-, z-axis direction

  // Yellow spotlight from the front
  spotLight(255, 255, 0,  // Color
            0, 40, 200,     // Position
            0, -0.5, -0.5,  // Direction
            PI / 2, 2);     // Angle, concentration

  translate(width/2,height/2,-200);
  sphere(50 + 50 * sin(a));
  rotateX(a);
  rotateY(a);

  for(int i = 0; i < s.length; i++){
    s[i].draw();
  }

  //stroke(0);
  //strokeWeight(1);
  //fill(0);
  /*pushMatrix();
  beginShape(TRIANGLE_FAN);
    for(int i = 2; i < s.length; i++){
      vertex(s[i-2].x, s[i-2].y, s[i-2].z);
    vertex(s[i-1].x, s[i-1].y, s[i-1].z);
    vertex(s[i].x, s[i].y, s[i].z);
  }
  endShape();
  popMatrix();*/

  /*pushMatrix();
  translate(0,0,-2500);
  stroke(0);
    for(int i = 0; i < 50; i++){
      rotate(a/100);
    line(i * 10, 0,0,i*10,500,5000);
  }
      for(int i = 0; i < 50; i++){
        rotate(-a/100);
    line(0, i * 10,0,500,i * 10,5000);
  }
  popMatrix();*/
  //noStroke();
  a+=.01;
}

class squiggle{
  float rad;
  float x,y;
  //----
  float z;
  float z_rot;

  ///---
  float rand_turn;
  boolean turn = false;
  float speed;
  squiggle(){
    x = 0;
    y = 0;
    rad = random(0,2*PI);
    z_rot = random(0,2*PI);
    speed = random(.5,2);
  }
  void draw(){
    //line(x,y,cos(rad) * speed + x, sin(rad) * speed + y);
    //ellipse(x,y,rad,rad);
    pushMatrix();
    translate(x,y,z);
    //rotate(rad);
    box(10);
    popMatrix();
    x = cos(rad) * speed + x;
    y = sin(rad) * speed + y;

    z = cos(z_rot) * speed + z;
    if(sqrt(sq(z - 0) + sq(y - 0)) > 200){
      z_rot +=.1;
    }
    if(sqrt(sq(x - (0)) + sq(y - (0))) < 200){
      rad += random(-.25,.25);
      turn = false;
    }
    else {
      if(turn == false){
        rand_turn = random(.1,.3);
        turn = true;
      }
      rad += rand_turn;
    }
  }
}


Page Details
Contact DANM  |  Digital Arts and New Media  |  Arts Division  |  Grad Division
login