FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Responsive Form, Games
(Moderator: REAS)
   cubefield
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: cubefield  (Read 1058 times)
mawend

Email
cubefield
« on: Jan 21st, 2003, 5:06am »

First simple P5 program. Clunky code, to be sure, but a fun result in a very short amount of time.
 
Mark
 
----------
 
// cubefield
// by Mark Wendell
// silly little 3d exercise, but fun
 
void setup()
{
  size(500, 500);
  colorMode(HSB,1);
  background(.2);
  noStroke();
  lights();
 
  // add another light, according to the trick in the
  // suggestions forum. Needed because the cubes are
  // pushed back in space, past the reach of the  
  // default lights.
  g.lightKind[2] = DIFFUSE;
  g.lightX[2] = 1.0;
  g.lightY[2] = 20.0;
  g.lightZ[2] = -20.5;
  g.lightR[2] = 1.0;
  g.lightG[2] = 1.0;
  g.lightB[2] = 1.0;
}
 
void loop()
{
  float box_size = 50;
  float ah = (width+height)/2;
  translate (width/2, height/2, -200);
  rotateX(PI/3);
  rotateZ(millis() * .0002);  // spin
  for (int i = -width/2; i <= width/2; i=i+(int)box_size) {
    push();
    for (int j = -height/2; j <= height/2; j=j+(int)box_size) {
 push();
 float md = 1-distance(mouseX,mouseY,i+width/2,j+width/2)/ah;
 translate (i, j, 0);
 rotateZ(8*md);
 fill (pow(md,6) * .3 + .7, 1-md, pow(md,2)*.5 + .5 );
 box(box_size*.5+md*10,box_size*.5+md*10, pow(md,6) * 300 + 10);
 pop();
    }
    pop();
  }
}
 
// 2D Distance by REAS <http://www.groupc.net>
float distance(float x1, float y1, float x2, float y2) {
  return sqrt(sq(x1-x2) + sq(y1-y2));
}
 
REAS


WWW
Re: cubefield
« Reply #1 on: Jan 21st, 2003, 8:15pm »

The light information in the forum is here:  
 
http://proce55ing.net/discourse/yabb/board_Proce55ing_Software__action_display_num_1039496510.html  
 
The lighting API may change in the future.  
 
Pages: 1 

« Previous topic | Next topic »