/********************************************************************************* inout_wave_eqns_1d_src.java A one dimensional simulation of a standalone electron wave-center and its in- and out-waves using the actual electron in- and out-wave equations from the Wave Structure of Matter (WSM) model. It is the highly simplified in that there are no outside influences and no spherical rotation going on at the wave center. Steven Dufresne - February 18, 2010 **********************************************************************************/ import java.applet.*; import java.awt.*; public class inout_wave_eqns_1d_src extends Applet implements Runnable { int width, height; int i = 0; Thread thread = null; boolean threadSuspended; Image backbuffer; Graphics backg; int spacelen = 400; // the length of space[] int wavecenterloc; // location in space of the wave center, for 1/r calculations double pi; double lambda = 2.4263102175e-12; // units - m, Compton wavelength double k = 2.589604676e12; // units - (1/m), (2xpi)/lambda double w = 7.763439511e20; // units - radians/s, (2xpixc)/lambda = kc double c = 299792458; // units - m/s double t = 3.5e-18; // units - s double dt = 1e-22; // delta t, added to t each time double amp_max = 1e-12; // maximum amplitude // Executed when the applet is first created. public void init() { int i; //System.out.println("init(): begin"); width = getSize().width; height = getSize().height; setBackground(Color.black); pi = Math.PI; backbuffer = createImage(width, height); backg = backbuffer.getGraphics(); wavecenterloc = spacelen / 2; } // Executed when the applet is destroyed. public void destroy() { } // Executed after the applet is created; and also whenever // the browser returns to the page containing the applet. public void start() { if (thread == null) { thread = new Thread(this); threadSuspended = false; thread.start(); } else { if (threadSuspended) { threadSuspended = false; synchronized(this) { notify(); } } } } // Executed whenever the browser leaves the page containing the applet. public void stop() { thread = null; } // Executed within the thread that this applet created. public void run() { try { while (Thread.currentThread() == thread) { t+=dt; draw_space(backg); // Now the thread checks to see if it should suspend itself if (threadSuspended) { synchronized(this) { while (threadSuspended) { wait(); } } } repaint(); thread.sleep(50); // interval given in milliseconds } } catch (InterruptedException e) {} } void draw_space(Graphics g) { int x, first = 1; int base_y = 100; double r; double amp_scalar; int amp_scalar_y, amp_scalar_yprev; double amp_in; int amp_in_y, amp_in_yprev; double amp_out; int amp_out_y, amp_out_yprev; String s_in = "in-wave"; String s_out = "out-wave"; String s_scalar_ln1 = "scalar"; String s_scalar_ln2 = "(in-wave -"; String s_scalar_ln3 = " out-wave)"; // erase everything that was there before g.setColor(Color.white); g.fillRect(0, 0, width-1, height-1); amp_scalar_yprev = 0; amp_in_yprev = 0; amp_out_yprev = 0; for (x = 0; x < spacelen; x++) { // work out 1/r as a function of distance from the wavecenter if (x < wavecenterloc) r = (double) (wavecenterloc - x)/2; // the /2 spreads out the wave else r = (double) (x - wavecenterloc)/2; r = r * 0.25e-12; if (r != 0) { amp_out = (amp_max/r) * ((Math.cos(w*t)*Math.cos(k*r)+Math.sin(w*t)*Math.sin(k*r))/ (Math.cos(k*r)*Math.cos(k*r)+Math.sin(k*r)*Math.sin(k*r))); amp_in = (amp_max/r) * (Math.cos(w*t)*Math.cos(k*r)-Math.sin(w*t)*Math.sin(k*r)); amp_scalar = amp_in - amp_out; // scale the wave's heights to fit the display amp_out_y = (int) (amp_out*15); amp_in_y = (int) (amp_in*15); amp_scalar_y = (int) (amp_scalar*15); if (first == 0) { // draw the out wave g.setColor(Color.green); g.drawLine(x-1, (int) base_y-amp_out_yprev, x, base_y-amp_out_y); g.setColor(Color.black); g.drawString(s_out, (spacelen/2)+17, base_y-15); // draw the in wave g.setColor(Color.red); g.drawLine(x-1, (int) 75+base_y-amp_in_yprev, x, 75+base_y-amp_in_y); g.setColor(Color.black); g.drawString(s_in, (spacelen/2)+17, 75+base_y-15); // draw the scalar/standing wave g.setColor(Color.black); g.drawLine(x-1, (int) 175+base_y-amp_scalar_yprev, x, 175+base_y-amp_scalar_y); g.setColor(Color.black); g.drawString(s_scalar_ln1, (spacelen/2)+17, 175+base_y-45); g.drawString(s_scalar_ln2, (spacelen/2)+17, 175+base_y-30); g.drawString(s_scalar_ln3, (spacelen/2)+17, 175+base_y-15); } first = 0; amp_scalar_yprev = amp_scalar_y; amp_in_yprev = amp_in_y; amp_out_yprev = amp_out_y; } } } public void update(Graphics g) { g.drawImage(backbuffer, 0, 0, this); } public void paint(Graphics g) { update(g); } }