// stokes1.java Gardner wave simulation // Programed by H.Tasaka 1997/12/2/Tue import java.applet.Applet; import java.awt.*; import java.io.*; import java.net.URL; import java.util.StringTokenizer; public class gardner1 extends Applet { final static int SIZE_X=300; final static int SIZE_Y=225; final static double RAD=Math.PI/180.; private Wave_Simulate1 wave_sim; private double v_inc_r=0.0,v_inc_the=5.0,v_inc_phi=0.0; private Gardner_Wave gadn_wave; private Point prev; private double amp0,xfreq0,yfreq0,xphase0,yphase0,col_thresh; private int max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b; private Label l_smal_wx,l_smal_wy,l_larg_wx,l_larg_wy, l_smal_phix,l_smal_phiy,l_larg_phix,l_larg_phiy, l_amp0; private Scrollbar s_smal_wx,s_smal_wy,s_larg_wx,s_larg_wy, s_smal_phix,s_smal_phiy,s_larg_phix,s_larg_phiy, s_amp0; private Button b_reset,b_texture,b_3d,b_color,b_func,b_ok, b_reset2,b_texture2,b_3d2; private Panel funPanel = new Panel(); private Panel colPanel = new Panel(); private Panel inpPanel = new Panel(); private Choice c_samp_pat,c_samp_col; private TextField tf_mcol_r,tf_mcol_b,tf_mcol_g, tf_scol_r,tf_scol_b,tf_scol_g,tf_thresh; final static void gbcon(GridBagLayout gridbag, GridBagConstraints c, Component cp, Panel p) { gridbag.setConstraints(cp, c); p.add(cp); } public void init(){ resize(380,500); setBackground(Color.gray); gadn_wave = new Gardner_Wave(); wave_sim = new Wave_Simulate1(gadn_wave); wave_sim.resize(SIZE_X,SIZE_Y); add(wave_sim); GridBagLayout gridbag = new GridBagLayout(); funPanel.setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; c.weightx = 1.0; c.ipady = 0; c.gridwidth = 2; Label l_samp = new Label("[sample pattern] "); l_samp.setForeground(Color.blue); gbcon(gridbag, c,add(l_samp), funPanel); c.gridwidth = GridBagConstraints.REMAINDER; c_samp_pat = new Choice(); c_samp_pat.addItem("sky1"); c_samp_pat.addItem("sky2"); c_samp_pat.addItem("fire"); c_samp_pat.addItem("wood"); c_samp_pat.addItem("sample"); gbcon(gridbag,c,add(c_samp_pat),funPanel); Insets insets1 = new Insets(0, 3, 0, 0); Insets insets2 = new Insets(0, 0, 0, 3); c.gridwidth = 3; c.ipadx = 7; c.insets = insets1; Label l_smal_w=new Label("[w small scale (0.0~0.1)*2PI]"); l_smal_w.setForeground(Color.blue); gbcon(gridbag, c, add(l_smal_w), funPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), funPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; l_smal_wx = new Label("wx1: "+(float)xfreq0); gbcon(gridbag, c, add(l_smal_wx), funPanel); s_smal_wx = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_smal_wx), funPanel); c.ipadx = 1;c.insets = insets1; l_smal_wy = new Label("wy1: "+(float)yfreq0); gbcon(gridbag, c, add(l_smal_wy), funPanel); s_smal_wy = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_smal_wy), funPanel); c.gridwidth = 3; c.ipadx = 7; c.insets = insets1; Label l_larg_w=new Label("[w large scale (0.0~2.0)*2PI]"); l_larg_w.setForeground(Color.blue); gbcon(gridbag, c,add(l_larg_w), funPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), funPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; l_larg_wx = new Label("wx1: "+(float)xfreq0); gbcon(gridbag, c, add(l_larg_wx), funPanel); s_larg_wx = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_larg_wx), funPanel); c.ipadx = 1;c.insets = insets1; l_larg_wy = new Label("wy1: "+(float)yfreq0); gbcon(gridbag, c, add(l_larg_wy), funPanel); s_larg_wy = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_larg_wy), funPanel); c.gridwidth = 3; c.ipadx = 7; c.insets = insets1; Label l_smal_phi=new Label("[phi small scale (0.0~0.1)*2PI]"); l_smal_phi.setForeground(Color.blue); gbcon(gridbag, c,add(l_smal_phi), funPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), funPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; l_smal_phix = new Label("phi_x1: "+(float)xphase0); gbcon(gridbag, c, add(l_smal_phix), funPanel); s_smal_phix = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_smal_phix), funPanel); c.ipadx = 1;c.insets = insets1; l_smal_phiy = new Label("phi_y1: "+(float)yphase0); gbcon(gridbag, c, add(l_smal_phiy), funPanel); s_smal_phiy = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_smal_phiy), funPanel); c.gridwidth = 3; c.ipadx = 7; c.insets = insets1; Label l_larg_phi=new Label("[phi large scale (0.0~2.0)*2PI]"); l_larg_phi.setForeground(Color.blue); gbcon(gridbag, c,add(l_larg_phi), funPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), funPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; l_larg_phix = new Label("phi_x1: "+(float)xphase0); gbcon(gridbag, c, add(l_larg_phix), funPanel); s_larg_phix = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_larg_phix), funPanel); c.ipadx = 1;c.insets = insets1; l_larg_phiy = new Label("phi_y1: "+(float)yphase0); gbcon(gridbag, c, add(l_larg_phiy), funPanel); s_larg_phiy = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_larg_phiy), funPanel); c.gridwidth = 2; c.gridwidth = 2; c.ipadx = 7; c.insets = insets1; Label l_amp = new Label("[amplitude (0.0~40.0)]"); l_amp.setForeground(Color.blue); gbcon(gridbag, c,add(l_amp),funPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; l_amp0 = new Label("amp0: "+(float)amp0); gbcon(gridbag, c, add(l_amp0), funPanel); s_amp0= new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,1000); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 20;c.insets = insets2; gbcon(gridbag, c, add(s_amp0), funPanel); c.gridwidth = 1; c.ipadx = 10;c.insets = insets1; b_texture = new Button("Texture"); gbcon(gridbag, c, add(b_texture), funPanel); b_3d = new Button(" 3d "); gbcon(gridbag, c, add(b_3d), funPanel); b_color = new Button(" Color "); gbcon(gridbag, c, add(b_color), funPanel); b_reset = new Button(" Reset "); gbcon(gridbag, c, add(b_reset), funPanel); colPanel.setLayout(gridbag); c.gridwidth = 3; Label l_col_samp = new Label("[sample color]"); l_col_samp.setForeground(Color.blue); gbcon(gridbag, c,add(l_col_samp), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; c_samp_col = new Choice(); c_samp_col.addItem("sky1,2 1"); c_samp_col.addItem("sky1,2 2"); c_samp_col.addItem("fire"); c_samp_col.addItem("wood"); c_samp_col.addItem("smaple"); gbcon(gridbag,c,add(c_samp_col),colPanel); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 1; c.insets = insets1; Label l_cmax = new Label("[MAX point color(RGB 0~255)]"); l_cmax.setForeground(Color.blue); gbcon(gridbag, c,add(l_cmax), colPanel); c.gridwidth = 1; c.ipadx = 1; Label l_cmax_r = new Label("RED : "); l_cmax_r.setForeground(Color.red); gbcon(gridbag, c,add(l_cmax_r), colPanel); c.gridwidth = 1; tf_mcol_r = new TextField("",3); c.ipadx = 5; gbcon(gridbag, c, add(tf_mcol_r), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; Label l_cmax_g = new Label("GREEN: "); l_cmax_g.setForeground(Color.green); gbcon(gridbag, c,add(l_cmax_g), colPanel); c.ipadx = 5; c.gridwidth = 1; tf_mcol_g = new TextField("",3); gbcon(gridbag, c, add(tf_mcol_g), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; Label l_cmax_b = new Label("BLUE : "); l_cmax_b.setForeground(Color.blue); gbcon(gridbag, c,add(l_cmax_b), colPanel); tf_mcol_b = new TextField("",3); c.gridwidth = 1; c.ipadx = 5; c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, add(tf_mcol_b), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 1; c.insets = insets1; Label l_cmin = new Label("[MIN point color(RGB 0~255)]"); l_cmin.setForeground(Color.blue); gbcon(gridbag, c,add(l_cmin), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; Label l_cmin_r = new Label("RED : "); l_cmin_r.setForeground(Color.red); gbcon(gridbag, c, add(l_cmin_r), colPanel); tf_scol_r = new TextField("",3); c.gridwidth = 1; c.ipadx = 5; gbcon(gridbag, c, add(tf_scol_r), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; Label l_cmin_g = new Label("GREEN: "); l_cmin_g.setForeground(Color.green); gbcon(gridbag, c,add(l_cmin_g), colPanel); tf_scol_g = new TextField("",3); c.gridwidth = 1; c.ipadx = 5; gbcon(gridbag, c, add(tf_scol_g), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; Label l_cmin_b = new Label("BLUE : "); l_cmin_b.setForeground(Color.blue); gbcon(gridbag, c,add(l_cmin_b), colPanel); tf_scol_b = new TextField("",3); c.gridwidth = 1; c.ipadx = 5; c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, add(tf_scol_b), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 7; c.insets = insets1; Label l_th = new Label("[color threshold(0.0~1.0]"); l_th.setForeground(Color.blue); gbcon(gridbag, c,add(l_th), colPanel); c.gridwidth = 1; gbcon(gridbag, c, new Label("THRESH:"), colPanel); tf_thresh = new TextField("",5); c.gridwidth = 2; c.ipadx = 5;c.insets = insets1; gbcon(gridbag, c, add(tf_thresh), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), colPanel); c.gridwidth = 1; c.ipadx = 1;c.insets = insets1; b_texture2 = new Button("Texture"); gbcon(gridbag, c, add(b_texture2), colPanel); b_3d2 = new Button("3d"); gbcon(gridbag, c, add(b_3d2), colPanel); b_func = new Button("Func"); gbcon(gridbag, c, add(b_func), colPanel); b_reset2 = new Button("Reset"); gbcon(gridbag, c, add(b_reset2), colPanel); gbcon(gridbag, c, new Label(""), colPanel); b_ok = new Button(" OK "); gbcon(gridbag, c, add(b_ok), colPanel); c.gridwidth = GridBagConstraints.REMAINDER; gbcon(gridbag, c, new Label(""), colPanel); inpPanel.setLayout(new CardLayout()); inpPanel.add("fun",funPanel); inpPanel.add("col",colPanel); add(inpPanel); set_func_default(); set_col_default(); wave_sim.start(); } private void set_func_default(){ amp0=15.0; xfreq0=0.01;yfreq0=0.021; xphase0=0.0599;yphase0=0.11; set_s_all(); set_Text_all(); gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); } private void set_func_samp2(){ amp0=15.0; xfreq0=1.124;yfreq0=1.586; xphase0=0.0468;yphase0=0.0767; set_s_all(); set_Text_all(); gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); } private void set_func_samp3(){ amp0=15.0; xfreq0=0.09;yfreq0=0.096; xphase0=0.278;yphase0=0.035; set_s_all(); set_Text_all(); gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); } private void set_func_samp4(){ amp0=15.0; xfreq0=0.0624;yfreq0=1.124; xphase0=0.0968;yphase0=1.062; set_s_all(); set_Text_all(); gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); } private void set_func_samp5(){ amp0=15.0; xfreq0=1.023;yfreq0=1.021; xphase0=0.9;yphase0=0.7; set_s_all(); set_Text_all(); gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); } private void set_col_default(){ max_col_r=150;max_col_g=150;max_col_b=255; min_col_r=0;min_col_g=0;min_col_b=100; col_thresh=0.4; set_TextField_all(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } private void set_col_samp2(){ max_col_r=150;max_col_g=150;max_col_b=255; min_col_r=0;min_col_g=0;min_col_b=100; col_thresh=0.0; set_TextField_all(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } private void set_col_samp3(){ max_col_r=160;max_col_g=90;max_col_b=0; min_col_r=255;min_col_g=0;min_col_b=0; col_thresh=0.0; set_TextField_all(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } private void set_col_samp4(){ max_col_r=0;max_col_g=0;max_col_b=0; min_col_r=64;min_col_g=40;min_col_b=0; col_thresh=0.0; set_TextField_all(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } private void set_col_samp5(){ max_col_r=255;max_col_g=0;max_col_b=255; min_col_r=0;min_col_g=255;min_col_b=0; col_thresh=0.0; set_TextField_all(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } private void set_Text_all(){ l_amp0.setText("amp0: "+(float)amp0); l_smal_wx.setText("wx1: "+(float)xfreq0); l_larg_wx.setText("wx1: "+(float)xfreq0); l_smal_wy.setText("wy1: "+(float)yfreq0); l_larg_wy.setText("wy1: "+(float)yfreq0); l_smal_phix.setText("phi_x1: "+(float)xphase0); l_smal_phiy.setText("phi_y1: "+(float)yphase0); l_larg_phix.setText("phi_x1: "+(float)xphase0); l_larg_phiy.setText("phi_y1: "+(float)yphase0); } private void set_TextField_all(){ tf_mcol_r.setText(""+max_col_r); tf_mcol_g.setText(""+max_col_g); tf_mcol_b.setText(""+max_col_b); tf_scol_r.setText(""+min_col_r); tf_scol_g.setText(""+min_col_g); tf_scol_b.setText(""+min_col_b); tf_thresh.setText(""+(float)col_thresh); } private void set_s_all(){ set_s_smal_wx();set_s_smal_wy(); set_s_larg_wx();set_s_larg_wy(); set_s_smal_phix();set_s_smal_phiy(); set_s_larg_phix();set_s_larg_phiy(); set_s_amp0(); } private void set_s_smal_wx(){ s_smal_wx.setValue((int)(xfreq0*10000.)); // 10000.=1000./0.1 } private void set_s_smal_wy(){ s_smal_wy.setValue((int)(yfreq0*10000.)); // 10000.=1000./0.1 } private void set_s_larg_wx(){ s_larg_wx.setValue((int)(xfreq0*500.)); // 500.=1000./2.0 } private void set_s_larg_wy(){ s_larg_wy.setValue((int)(yfreq0*500.)); // 500.=1000./2.0 } private void set_s_smal_phix(){ s_smal_phix.setValue((int)(xphase0*10000.)); // 10000.=1000./0.1 } private void set_s_smal_phiy(){ s_smal_phiy.setValue((int)(yphase0*10000.)); // 10000.=1000./0.1 } private void set_s_larg_phix(){ s_larg_phix.setValue((int)(xphase0*500.)); // 500.=1000./2.0 } private void set_s_larg_phiy(){ s_larg_phiy.setValue((int)(yphase0*500.)); // 500.=1000./2.0 } private void set_s_amp0(){ s_amp0.setValue((int)(amp0*25.)); // 25.=1000./40. } private void get_tf_col(){ max_col_r = Integer.valueOf(tf_mcol_r.getText()).intValue(); max_col_g = Integer.valueOf(tf_mcol_g.getText()).intValue(); max_col_b = Integer.valueOf(tf_mcol_b.getText()).intValue(); min_col_r = Integer.valueOf(tf_scol_r.getText()).intValue(); min_col_g = Integer.valueOf(tf_scol_g.getText()).intValue(); min_col_b = Integer.valueOf(tf_scol_b.getText()).intValue(); col_thresh = Double.valueOf(tf_thresh.getText()).doubleValue(); wave_sim.set_col(max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b,col_thresh); } public boolean mouseDown(Event ev, int x, int y) { prev = new Point(x, y); return true; } public boolean handleEvent(Event evt){ if(evt.target instanceof Scrollbar){ double value = (double)(((Scrollbar)evt.target).getValue()); if(evt.target.equals(s_amp0)){ amp0=0.04*value; //amp0 = 40.*(value/1000.) l_amp0.setText("amp0: "+(float)amp0); } else if(evt.target.equals(s_smal_wx)){ xfreq0 = 0.0001*value; // = 0.1*(value/1000.) l_smal_wx.setText("wx1: "+(float)xfreq0); l_larg_wx.setText("wx1: "+(float)xfreq0); set_s_larg_wx(); } else if(evt.target.equals(s_smal_wy)){ yfreq0 = 0.0001*value; // = 0.1*(value/1000.) l_smal_wy.setText("wy1: "+(float)yfreq0); l_larg_wy.setText("wy1: "+(float)yfreq0); set_s_larg_wy(); } else if(evt.target.equals(s_larg_wx)){ xfreq0 = 0.002*value; // = 2.0*(value/1000.) l_smal_wx.setText("wx1: "+(float)xfreq0); l_larg_wx.setText("wx1: "+(float)xfreq0); set_s_smal_wx(); } else if(evt.target.equals(s_larg_wy)){ yfreq0 = 0.002*value; // = 2.0*(value/1000.) l_smal_wy.setText("wy1: "+(float)yfreq0); l_larg_wy.setText("wy1: "+(float)yfreq0); set_s_smal_wy(); } else if(evt.target.equals(s_smal_phix)){ xphase0 = 0.0001*value; // = 0.1*(value/1000.) l_smal_phix.setText("phi_x1: "+(float)xphase0); l_larg_phix.setText("phi_x1: "+(float)xphase0); set_s_larg_phix(); } else if(evt.target.equals(s_smal_phiy)){ yphase0 = 0.0001*value; // = 0.1*(value/1000.) l_smal_phiy.setText("phi_y1: "+(float)yphase0); l_larg_phiy.setText("phi_y1: "+(float)yphase0); set_s_larg_phiy(); } else if(evt.target.equals(s_larg_phix)){ xphase0 = 0.002*value; // = 2.0*(value/1000.) l_smal_phix.setText("phi_x1: "+(float)xphase0); l_larg_phix.setText("phi_x1: "+(float)xphase0); set_s_smal_phix(); } else if(evt.target.equals(s_larg_phiy)){ yphase0 = 0.002*value; // = 2.0*(value/1000.) l_larg_phiy.setText("phi_y1: "+(float)yphase0); set_s_smal_phiy(); } //if(evt.target.equals() gadn_wave.set_val(amp0,xfreq0,yfreq0,xphase0,yphase0); wave_sim.start(); return true; } //if(evt.target instanceof Scrollbar) return super.handleEvent(evt); } public boolean action(Event evt,Object obj){ String si; if(evt.target instanceof Button){ if(evt.target == b_reset){ wave_sim.stop(); wave_sim.setView1(); si = c_samp_pat.getSelectedItem(); if(si == "sky1") set_func_default(); else if(si == "sky2") set_func_samp2(); else if(si == "fire") set_func_samp3(); else if(si == "wood") set_func_samp4(); else if(si == "sample") set_func_samp5(); wave_sim.start(); } else if(evt.target == b_texture){ wave_sim.stop(); wave_sim.setTexture(1); wave_sim.start(); } else if(evt.target == b_3d){ wave_sim.stop(); wave_sim.setTexture(0); wave_sim.start(); } else if(evt.target == b_color){ ((CardLayout)inpPanel.getLayout()).show(inpPanel,"col"); } else if(evt.target == b_func){ ((CardLayout)inpPanel.getLayout()).show(inpPanel,"fun"); } else if(evt.target == b_reset2){ wave_sim.stop(); wave_sim.setView1(); si = c_samp_col.getSelectedItem(); if(si == "sky1") set_col_default(); else if(si == "sky2") set_col_default(); else if(si == "fire") set_col_samp3(); else if(si == "wood") set_col_samp4(); else if(si == "smaple") set_col_samp5(); wave_sim.start(); } else if(evt.target == b_texture2){ wave_sim.stop(); get_tf_col(); wave_sim.setTexture(1); wave_sim.start(); } else if(evt.target == b_3d2){ wave_sim.stop(); get_tf_col(); wave_sim.setTexture(0); wave_sim.start(); } else if(evt.target == b_ok){ wave_sim.stop(); get_tf_col(); wave_sim.start(); } return true; } else if(evt.target instanceof Choice){ if(evt.target == c_samp_pat){ si = c_samp_pat.getSelectedItem(); if(si == "sky1"){ wave_sim.stop(); wave_sim.setView1(); set_func_default(); c_samp_col.select("sky1,2 1"); set_col_default(); wave_sim.start(); } else if(si == "sky2"){ wave_sim.stop(); wave_sim.setView1(); set_func_samp2(); c_samp_col.select("sky1,2 1"); set_col_default(); wave_sim.start(); } else if(si == "fire"){ wave_sim.stop(); wave_sim.setView1(); set_func_samp3(); c_samp_col.select("fire"); set_col_samp3(); wave_sim.start(); } else if(si == "wood"){ wave_sim.stop(); wave_sim.setView1(); set_func_samp4(); c_samp_col.select("wood"); set_col_samp4(); wave_sim.start(); } else if(si == "sample"){ wave_sim.stop(); wave_sim.setView1(); set_func_samp5(); c_samp_col.select("sample"); set_col_samp5(); wave_sim.start(); } } else if(evt.target == c_samp_col){ si = c_samp_col.getSelectedItem(); if(si == "sky1,2 1"){ wave_sim.stop(); set_col_default(); wave_sim.start(); } else if(si == "sky1,2 2"){ wave_sim.stop(); set_col_samp2(); wave_sim.start(); } else if(si == "fire"){ wave_sim.stop(); set_col_samp3(); wave_sim.start(); } else if(si == "wood"){ wave_sim.stop(); set_col_samp4(); wave_sim.start(); } else if(si == "smaple"){ wave_sim.stop(); set_col_samp5(); wave_sim.start(); } } return true; } return super.action(evt,obj); } public boolean mouseDrag(Event ev, int x, int y) { wave_sim.changeView1(0.0,(double)(x-prev.x),(double)(y-prev.y)); wave_sim.start(); prev.move(x, y); return true; } public boolean mouseUp(Event ev, int x, int y) { prev = null; return true; } } class Wave_Simulate1 extends Canvas implements Runnable { final static double RD=Math.PI/180.; final static int SIZE_X=300; final static int SIZE_Y=225; private double px_g,py_g; private int dvx_g,dvy_g,out0_g; private double mark_xmin,mark_xmax,mark_xstp,mark_ymin,mark_ymax,mark_ystp, mark_zmin,mark_zmax,mark_zstp; private double viewp_xf,viewp_yf,viewp_zf,viewp_r,viewp_the,viewp_phi, viewp_vthx,viewp_vthy,v_inc_r,v_inc_the,v_inc_phi,rand_vel; private int viewp_dwnx,viewp_dwny,v_dispx,v_dispy; private byte vmove_sw,mark_sw=1; private double wv_time,wx1,wx2,wy1,wy2,sth,cth,cfi,sfi; private Gardner_Wave gadn_wave; private double wv_xmin,wv_xmax,wv_ymin,wv_ymax; private int max_col_r,max_col_g,max_col_b, min_col_r,min_col_g,min_col_b; private double col_thresh,func_thmin; private double func_zmin,col_stp_r,col_stp_g,col_stp_b; /* --- time_parm --- */ private double start_t,play_t,t_div; private double end_t,stp_t; /* ^^^ Parm_time ^^^ */ private Image doubleBuffer; private Graphics myGC; private Thread kick=null; private byte draw_type=0,col_r_flg,col_g_flg,col_b_flg; Wave_Simulate1(){ } Wave_Simulate1(Gardner_Wave stkw){ gadn_wave = new Gardner_Wave(); gadn_wave = stkw; mark_xmin=-10.0;mark_xmax=10.0;mark_xstp=2.0; mark_ymin=-10.0;mark_ymax=10.0;mark_ystp=2.0; mark_zmin= -4.0;mark_zmax= 4.0;mark_zstp=2.0; setView1(); wv_xmin=-10.0;wv_xmax=10.0;wv_ymin=-10.0;wv_ymax=10.0; start_t=0.0;play_t=60.0;t_div=60; end_t=start_t+play_t;stp_t=play_t/t_div; v_dispx=20; v_dispy=10; } public void setView1(){ viewp_xf=0.0;viewp_yf=0.0;viewp_zf=0.0; viewp_r=40.0;viewp_the=-30.0;viewp_phi=30.0; viewp_vthx=40.0;viewp_vthy=30.0; viewp_dwnx=SIZE_X;viewp_dwny=SIZE_Y; } public void set_col(int r1,int g1,int b1,int r2,int g2,int b2,double t){ double stp_x,stp_y; if (r1 < 0) r1=0; else if(r1 > 255) r1=255; if (g1 < 0) g1=0; else if(g1 > 255) g1=255; if (b1 < 0) b1=0; else if(b1 > 255) b1=255; if (r2 < 0) r2=0; else if(r2 > 255) r2=255; if (g2 < 0) g2=0; else if(g2 > 255) g2=255; if (b2 < 0) b2=0; else if(b2 > 255) b2=255; max_col_r=r1;max_col_g=g1;max_col_b=b1; min_col_r=r2;min_col_g=g2;min_col_b=b2; col_thresh=t; } public void changeView1(double r,double the,double phi){ viewp_r+=r;viewp_the+=the;viewp_phi-=phi; if(viewp_r < 0.) viewp_r =0.0; if(viewp_the >= 360.) viewp_the=0.0; else if(viewp_the < 0.0) viewp_the=360.0; if(viewp_phi >= 360.) viewp_phi=0.0; else if(viewp_phi < 0.0) viewp_phi=360.0; } public void start(){ if(kick == null){ doubleBuffer = createImage(SIZE_X,SIZE_Y); myGC = doubleBuffer.getGraphics(); kick = new Thread(this); kick.start(); } } public void stop(){ if(kick != null){ kick.stop(); kick = null; } } public void update(Graphics g){ g.drawImage(doubleBuffer,0,0,this); } public void paint(Graphics g){ update(g); } public void setTexture(int i){ draw_type = (byte)i; } public void run(){ int zmin[],zmax[]; int col_r,col_g,col_b; double a,x,y,z,stp_x,stp_y,ox,oy,oz; myGC.setColor(Color.black); myGC.fillRect(0,0,SIZE_X,SIZE_Y); if(draw_type == 0){ setscrn_size(); a=viewp_the*RD;sth=Math.sin(a);cth=Math.cos(a); a=viewp_phi*RD;cfi=Math.cos(a);sfi=Math.sin(a); write_marking(); wv_time=1.0; zmin = new int[SIZE_X]; zmax = new int[SIZE_X]; myGC.setColor(Color.black); myGC.fillRect(0,0,SIZE_X,SIZE_Y); myGC.setColor(Color.white); myGC.drawString("view point (r,the,phi) ="+viewp_r+","+viewp_the+ ","+viewp_phi,v_dispx,v_dispy); stp_x=(wv_xmax-wv_xmin)/5.; stp_y=(wv_ymax-wv_ymin)/50.; calc_col_rng(stp_x,stp_y); stp_x=(wv_xmax-wv_xmin)/50.; //System.out.println("rng ="+cmax+" "+cmin+" "+rng); setscrn_size(); a=viewp_the*RD;sth=Math.sin(a);cth=Math.cos(a); a=viewp_phi*RD;cfi=Math.cos(a);sfi=Math.sin(a); write_marking(); for(x=wv_xmin;x maxc) col=maxc; }else{ if(col > minc) col=minc; else if(col < maxc) col=maxc; } return(col); } private void calc_col_rng(double stp_x,double stp_y){ double func_zmax,func_zrng,x,y,z; func_zmax=-10000.;func_zmin=10000.; for(y=wv_ymin;yfunc_zmax) func_zmax=z; if(z= 0) col_r_flg=(byte)0; else col_r_flg=(byte)1; if((max_col_g-min_col_g) >= 0) col_g_flg=(byte)0; else col_g_flg=(byte)1; if((max_col_b-min_col_b) >= 0) col_b_flg=(byte)0; else col_b_flg=(byte)1; } private void usline3d(double x0,double y0,double z0,double x1,double y1, double z1,int col_r,int col_g,int col_b){ int xx0,yy0,xx1,yy1,out0,out1; out0_g=0; turntrs(x0,y0,z0); convert(); xx0=dvx_g;yy0=dvy_g;out0=out0_g; turntrs(x1,y1,z1); convert(); xx1=dvx_g;yy1=dvy_g;out1=out0_g; /* if((out0 == 0)&&(out1 == 0)){ usline(xx0,yy0,xx1,yy1,col_r,col_g,col_b); } */ myGC.setColor(new Color(col_r,col_g,col_b)); myGC.drawLine(xx0,SIZE_Y-yy0,xx1,SIZE_Y-yy1); } private void uspset3d(double x0,double y0,double z0, int col_r,int col_g,int col_b) { out0_g=0; turntrs(x0,y0,z0); convert(); if(out0_g == 0){ myGC.setColor(new Color(col_r,col_g,col_b)); myGC.drawLine(dvx_g,SIZE_Y-dvy_g,dvx_g,SIZE_Y-dvy_g); } } private void setscrn_size() { /* -- output viewp_dwny -- */ double a,b,px,py; a=viewp_r*Math.tan(viewp_vthx*.5*RD); b=viewp_r*Math.tan(viewp_vthy*.5*RD); turntrs_vf0(viewp_xf,viewp_yf,viewp_zf,0.0,0.0,0.0,viewp_r); wx1=px_g-a;wx2=py_g+a;wy1=py_g-b;wy2=py_g+b; viewp_dwny=(int)((double)viewp_dwnx*b/a); } private void turntrs(double xx1,double yy1,double zz1) { // output px_g,py_g double x,y,z,a,b,c; x=xx1-viewp_xf; y=yy1-viewp_yf; z=zz1-viewp_zf; a=x*cth+y*sth; b=viewp_r-a*cfi-z*sfi; c=viewp_r/b; px_g=(y*cth-x*sth)*c; py_g=(z*cfi-a*sfi)*c; } private void turntrs_vf0(double xx1,double yy1,double zz1, double xf,double yf,double zf,double r) { // output px_g,py_g double x,y,z,a,b,c; x=xx1-xf; y=yy1-yf; z=zz1-zf; a=x*cth+y*sth; b=r-a*cfi-z*sfi; c=r/b; px_g=(y*cth-x*sth)*c; py_g=(z*cfi-a*sfi)*c; } private void convert() { // input px_g,py_g // output dvx_g,dvy_g,out0_g double a; a=(px_g-wx1)/(wx2-wx1); dvx_g=(int)(.5+(double)viewp_dwnx*a); a=(py_g-wy1)/(wy2-wy1); dvy_g=(int)(.5+(double)viewp_dwny*a); /* printf("dvx = %d,%d\n",*dvx,*dvy); */ out0_g=0; if ((dvx_g < 0) || (dvx_g >= viewp_dwnx)) out0_g=1; if ((dvy_g < 0) || (dvy_g >= viewp_dwny)) out0_g=1; } private void write_marking(){ double memr_x,memr_y,memr_z; int col_r,col_g,col_b,isw; if(mark_sw > 0){ if(mark_sw == 1) isw = 1; else isw = 3; memr_z=0.0; for(int i=0;i 0) { usline3d(mark_xmin,0.0,0.0,0.0,0.0,0.0,155,0,0); usline3d(0.0,0.0,0.0,mark_xmax,0.0,0.0,255,100,100); usline3d(0.0,mark_ymin,0.0,0.0,0.0,0.0,0,100,0); usline3d(0.0,0.0,0.0,0.0,mark_ymax,0.0,100,255,100); usline3d(0.0,0.0,mark_zmin,0.0,0.0,0.0,100,100,0); usline3d(0.0,0.0,0.0,0.0,0.0,mark_zmax,255,255,100); } myGC.setColor(Color.white); turntrs(mark_xmin,0.0,0.0);convert(); myGC.drawString("-x",dvx_g,SIZE_Y-dvy_g); turntrs(mark_xmax,0.0,0.0);convert(); myGC.drawString("+x",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,mark_ymin,0.0);convert(); myGC.drawString("-y",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,mark_ymax,0.0);convert(); myGC.drawString("+y",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,0.0,mark_zmin);convert(); myGC.drawString("-z",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,0.0,mark_zmax);convert(); myGC.drawString("+z",dvx_g,SIZE_Y-dvy_g); } } class Gardner_Wave{ final static double PI0p5=Math.PI/2.; final static double PI2=Math.PI*2.; private double amp0,xfreq0,yfreq0,xphase0,yphase0; private int NTERMS = 5; Gardner_Wave(){ } public void set_val(double a,double xp,double yp,double xf,double yf){ amp0 = a; xphase0 = PI2*xp; yphase0 = PI2*yp; xfreq0 = PI2*xf; yfreq0 = PI2*yf; } public double get_z(double x,double y,double wv_time){ double i,amplitude,f; double fx,xphase,xfreq; double fy,yphase,yfreq; double offset = 0.5; double xoffset = 13; double yoffset = 96; x = x+xoffset; y = y+yoffset; xphase = xphase0; yphase = yphase0; xfreq = xfreq0; yfreq = yfreq0; amplitude = 0.3; f = 0.; for (i = 0; i< NTERMS;i+=1){ fx = amplitude * (offset + Math.cos(xfreq * (x + xphase ))); fy = amplitude * (offset + Math.cos(yfreq * (y + yphase ))); f += fx * fy; xphase = PI0p5 * 0.9 * Math.cos(yfreq * y ) ; yphase = PI0p5 * 1.1 * Math.cos(xfreq * x ) ; /* xphase = PAI/2 * 0.9 * cos(yfreq * y + omg*wv_time ) ; */ /* yphase = PAI/2 * 1.1 * cos(xfreq * x + omg*wv_time ) ; */ xfreq *= 1.9 + i * 0.1; yfreq *= 2.2 - i * 0.08; amplitude *= 0.707; } f = amp0 * f; return (f); } }