home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-24 | 4.8 KB | 190 lines |
- // clock.java
- //
- // Copyright(C) 1996,1997 Sony Corporation. All rights reserved.
- //
- import vrml.*;
- import vrml.field.*;
- import vrml.node.*;
- import java.util.*;
-
- public class clock extends Script{
-
- SFRotation setMin ;
- SFRotation setHour ;
- SFRotation 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[][] ;
-
- /* quarter min parts */
- SFColor Ss[]=new SFColor[4];
- String sName[] = { "s0","s15","s30","s45" };
- float sColors[][] ;
-
- boolean initialized = false ;
- // rotation parameters.
- float rotate[];
- public int min, hour, sec;
-
- boolean doReset = true ;
-
- public void initialize(){
- setMin = (SFRotation) getEventOut("setMin");
- setHour = (SFRotation) getEventOut("setHour");
- rotation = (SFRotation) getEventOut("rotation");
-
- MFColor c = (MFColor)getField("secColors");
- int s = c.getSize();
- secColors = new float[s][3];
- c.getValue(secColors);
-
- c = (MFColor)getField("sColors");
- s = c.getSize();
- sColors = new float[s][3] ;
- c.getValue(sColors);
-
- 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 processEvent(Event e){
- String name = e.getName();
-
- if(name.equals("tick")){
- tick((ConstSFTime)e.getValue(), e.getTimeStamp());
- }
- if(name.equals("clicked")){
- clicked ( (ConstSFBool)e.getValue(), e.getTimeStamp());
- }
- }
-
- public void tick(ConstSFTime arg, double ts){
- // get time
- Date currentDate = new Date();
-
- sec = currentDate.getSeconds();
- min = currentDate.getMinutes();
- hour = currentDate.getHours();
-
- if ( sec == 0 || ! initialized ) {
- // rotation axle's position.
- setMin( min );
- setHour( hour, min );
- initialized = true ;
-
- }
- 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, double 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";
- String t[] = new String[1] ;
- t[0] = "target=info_frame";
- getBrowser().loadURL ( s , t ) ;
- }
- }
-
-
-