home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Windows 95.com 1996 December
/
WIN95_DEC_1996_1.ISO
/
vrml
/
cp2b2x.exe
/
DATA.Z
/
clock.java
< prev
next >
Wrap
Text File
|
1996-06-21
|
4KB
|
161 lines
// clock.java
//
// (c)Copyright 1996 Sony Corporation. All rights reserved.
//
import vrml.*;
import java.util.*;
public class clock extends Script{
SFRotation setMin = (SFRotation) getEventOut("setMin");
SFRotation setHour = (SFRotation) getEventOut("setHour");
SFRotation rotation = (SFRotation) getEventOut("rotation");
float aRad = (float)(Math.PI/180.0);
float clockRotation[] = {0.0f,1.0f,0.0f,0.0f} ;
float rotDgr = 0.0f ;
boolean rotating = false ;
/* second parts*/
int secondsMax = 60;
SFColor seconds[] = new SFColor[secondsMax];
String secondsName[] =
{"sec0","sec1","sec2","sec3","sec4","sec5",
"sec6","sec7","sec8","sec9","sec10","sec11",
"sec12","sec13","sec14","sec15","sec16","sec17",
"sec18","sec19","sec20","sec21","sec22","sec23",
"sec24","sec25","sec26","sec27","sec28","sec29",
"sec30","sec31","sec32","sec33","sec34","sec35",
"sec36","sec37","sec38","sec39","sec40","sec41",
"sec42","sec43","sec44","sec45","sec46","sec47",
"sec48","sec49","sec50","sec51","sec52","sec53",
"sec54","sec55","sec56","sec57","sec58","sec59"} ;
float secColors[][] = ((MFColor)getField("secColors")).getValue();
/* quarter min parts */
SFColor Ss[]=new SFColor[4];
String sName[] = { "s0","s15","s30","s45" };
float sColors[][] = ((MFColor)getField("sColors")).getValue();
// rotation parameters.
float rotate[];
public int min, hour, sec;
boolean doReset = true ;
// constructor.
public clock(){
int i ;
// get time
Date currentDate = new Date();
/* get second panels */
for(i=0;i<secondsMax;i++){
seconds[i] = (SFColor) getEventOut(secondsName[i]);
}
for(i=0;i<4;i++){
Ss[i] = (SFColor) getEventOut(sName[i]);
}
// rotation axle's direction.
rotate = new float[4];
rotate[0] = 0.0f;
rotate[1] = 0.0f;
rotate[2] = 1.0f;
sec = currentDate.getSeconds();
min = currentDate.getMinutes();
hour = currentDate.getHours();
System.out.println( "min,hour:" + min + " " + hour);
resetSec();
// rotation axle's position.
setMin( min );
setHour( hour, min );
}
public void tick(ConstSFTime arg, ConstSFTime ts){
// get time
Date currentDate = new Date();
sec = currentDate.getSeconds();
min = currentDate.getMinutes();
hour = currentDate.getHours();
if ( sec == 0 ) {
// rotation axle's position.
setMin( min );
setHour( hour, min );
}
setSec ( sec ) ;
if(rotating) {
rotDgr += 10.0f;
if (rotDgr > 360.0f) {
rotDgr -= 360.0f;
}
clockRotation[3] = (aRad * rotDgr) ;
rotation.setValue(clockRotation);
}
}
void setMin ( int min ){
rotate[3] = (-6.0f * min)*aRad;
setMin.setValue(rotate);
}
void setHour ( int hour, int min ) {
rotate[3] = ((-30.0f * hour) +(-30.0f *(min/60.0f))) * aRad;
setHour.setValue(rotate);
}
int last = 0 ;
void setSec(int sec){
if(last > sec){
resetSec();
}
for(int i=last;i<=sec;i++){
secColors[i][0]=1.0f;
seconds[i].setValue(secColors[i]);
if(i==0||i==15||i==30||i==45){
int j = i/15;
sColors[j][0]=1.0f;
Ss[j].setValue(sColors[j]);
}
}
last = sec ;
}
void resetSec(){
int i ;
for(i=0;i<secondsMax;i++){
secColors[i][0]=0.0f;
secColors[i][2]=0.5f;
seconds[i].setValue(secColors[i]);
}
for(i=0;i<4;i++){
sColors[i][0]=0.0f;
sColors[i][2]=0.5f;
Ss[i].setValue(sColors[i]);
}
last = 0 ;
}
public void clicked ( ConstSFBool arg, ConstSFTime now ) {
if ( arg.getValue() ) return ;
if (rotating) {
rotDgr = 0.0f;
clockRotation[3] = 0.0f;
rotation.setValue(clockRotation);
rotating = false ;
}
else {
rotating = true ;
}
String s[] = new String[1] ;
s[0] = "html/clock.html";
Browser.loadWorld ( s ) ;
}
}