We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › with with a clock program
Page Index Toggle Pages: 1
with with a clock program (Read 1555 times)
with with a clock program
May 6th, 2005, 6:42am
 
Hi..i am a student of pitaru. the programmer who wrote the sonia plugin for processing. i am having a bit of trouble with the clock i am making..basically i want to introduce some kinda of fog or alpha channel that would lighten the text as it is being rotated to the back so that the front can be read more easily.

thanks for your help



PFont f;
float ang;
float cubeSize = 80;
String [] timeZone = new String[4];

void setup(){
 size(400,400);
 f = loadFont("Bauhaus-Heavy-Bold-48.vlw");
 textFont(f, 24);
 textMode(ALIGN_CENTER);
 rectMode(CENTER);
 smooth();

 timeZone[0] = "New York";

 timeZone[1] = "California";
 timeZone[2] = "Lebanon";
 timeZone[3] = "Beijing";
}

void draw(){
 background(255);

 //ang += 0.01;
 ang %= TWO_PI; // loop ang value between 0 and two_pi

 // rotate the cube
 translate(width/2, height/2);
 rotateY(ang + Xnorm());
// rotateX(ang + Ynorm());
 for(int i = 0; i < 4; i++) {
   drawWall(i);
 }

}

//if (mousePressed = "false") {mouseX = 0;}

 // mpas range of mouseX to 0->two-pi
 float Xnorm() {
   float x_0_to_1 = mouseX/float(width);
   float x_0_to_2PI = x_0_to_1 * TWO_PI;
   return x_0_to_2PI;
 }

//   float Ynorm(){
//   float y_0_to_1 = mouseY/float(height);
//    float y_0_to_2PI = y_0_to_1 * TWO_PI;
//   return y_0_to_2PI;
//  }



 // draws one face of our cube
 void drawWall(int i){
   int s = second();    // Values from 1 - 31
   int m = minute();  // Values from 1 - 12
   int h = hour();   // 2003, 2004, 2005, etc.
   int g = 3;
   push();
   rotateY(HALF_PI*i);
   translate(0,0,cubeSize);
   //fill(255);
   //rect(0,0,cubeSize*2,cubeSize*2);
   fill(0);

   translate(-115,0);
   String c = String.valueOf(h);
   textMode(ALIGN_LEFT);
   text(c, 40, 0, 1);
   text(":", 70, -2, 1);
   c = String.valueOf(m);
   text(c, 80, 0, 1);
   text(":", 110, -2, 1);
   c = String.valueOf(s);
   text(c, 120, 0, 1);
   if (h<12)
   {
     text("AM", 150,0,1);
   }
   else
   {text("PM", 150,0,1);
   }
   //textMode(ALIGN_LEFT);
   text(timeZone[i],60,30,1);
   pop();
 }

Re: with with a clock program
Reply #1 - May 6th, 2005, 1:04pm
 
textMode is now textAlign.
push is now pushMatrix.
pop is now popMatrix.
you will have to call size(400,400,P3D); at the beginning of your sketch.

It's nice to note that I downloaded P87 on to a G5 on one of our school networks to show a friend what I was doing and it worked fine. Doesn't need any proper installation to work (so there's no excuse for using the old version except for un-updated libraries Wink)

I've almost got a working example of how to do what you want (it's fine for one plane of rotation). However, play around with it and you'll notice it goes a little screwy when the box intersects z = 0. Anybody have the solution?
Code:

float x,y,z;
void setup(){
size (400,400,P3D);
x = 0;
y = 0;
z = 0;
}
void draw(){
background(50,100,150);
translate(200,200,0);
pushMatrix();
rotateX(x);
rotateY(y);
rotateZ(z);
translate(0,0,100);
/*
the box will be furthest away when it's rotation is closest to PI
on the X and Y rotations. So, logically - setting the alpha to be
relative to the median delta of X and Y to PI should give us distance
fog.
*/
float xDelta = abs(x-PI);
float yDelta = abs(y-PI);
//this is where my math gets sloppy - could someone clean this up please?
float fog = 255-((255/PI) * (abs(xDelta-yDelta)));
fill(255,255,255,fog);
box(50,50,50);
popMatrix();
}
void keyPressed(){
switch (key){
case '1':
x = (x+0.1)%TWO_PI;
//println("x"+x);
break;
case '2':
y = (y+0.1)%TWO_PI;
//println("y"+y);
break;
case '3':
z = (z-0.1)%TWO_PI;
break;
}
}
Page Index Toggle Pages: 1