/* * df6.java - revised 20 Dec 2010 - width 321, height 241 * @author jackord@kw.igs.net * Transmitted and Reflected X-ray diffraction patterns from a face-centred * cubic crystal structure. * Huygens' wavelets are superimposed from an nxnxn close-packed rhombohedral * array where n is scanned from = 2 to 256. * The incident beam is normal to a close-packed plane, and the wavelength * is set to the cube edge divided by the root of 3 to enhance diffraction * from (200) and (220) planes. */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class df6 extends Applet implements ActionListener { int kk=0; int first=0; // Declarations String b1s="Transmit"; Button b1=new Button(b1s); String b2s="Reflect"; Button b2=new Button(b2s); Image bim; Graphics bgr; public void init() { add(b1); b1.addActionListener(this); add(b2); b2.addActionListener(this); setBackground(new Color(211, 211, 211)); setFont(new Font("TimesRoman", Font.PLAIN, 12)); } public void paint(Graphics g) { // Main Program b1.setBounds(10, 5, 60, 20); b2.setBounds(10, 28, 60, 20); int c, di, ni, x0, y0, del; long tt; double a, b, d, dx, dy, dz, lam, z, zz, r0, qr, qi, rr, ri, sr, si, t, sc, sn; double la; if (first==0) { bim=createImage(240, 240); bgr=bim.getGraphics(); first=1; } a=3.615E-7; x0=120; y0=120; z=30.; zz=z*z; // Cu lattice parameter d=a/Math.sqrt(2.); la=a/Math.sqrt(3); double pi=Math.PI; g.setColor(Color.black); // Initial screen g.drawRect(0, 0, 320, 240); if (kk==1) di=1; else di=-1; // Transmit / Reflect if (kk>0) { for (int n=1; n<=8; n=n+1) { for (int ny=-120; ny<=120; ny=ny+1) { // Screen Y loop for (int nx=-120; nx<=120; nx=nx+1) { // Screen X loop r0=Math.sqrt(zz+nx*nx+ny*ny); b=2*pi/r0/la; sr=1; si=0; ni=1; sn=1.0; dx=d; for (int i=1; i<=n; i=i+1) { // Array X loop t=b*ni*dx*nx; rr=Math.cos(t); ri=Math.sin(t); qr=sr+rr*sr-ri*si; si=si+rr*si+ri*sr; sr=qr; ni=2*ni; sn=2*sn; } ni=1; dx=d/2; dy=d*Math.sqrt(3.)/2; // Array Y loop for (int i=1; i<=n; i=i+1) { t=ni*b*(dx*nx+dy*ny); rr=Math.cos(t); ri=Math.sin(t); qr=sr+rr*sr-ri*si; si=si+rr*si+ri*sr; sr=qr; ni=2*ni; sn=2*sn; } ni=1; dy=d/2/Math.sqrt(3.); dz=d/Math.sqrt(1.5); for (int i=1; i<=n; i=i+1) { // Array Z loop t=ni*b*(dx*nx+dy*ny+dz*(di*z-r0)); rr=Math.cos(t); ri=Math.sin(t); qr=sr+rr*sr-ri*si; si=si+rr*si+ri*sr; sr=qr; ni=2*ni; sn=2*sn; } sc=2550/sn/sn; // Intensity scale c=(int)((sr*sr+si*si)*sc); if (c>255) { c=255; } Color col=new Color(0, c, 0); bgr.setColor(col); bgr.drawLine(x0+nx, y0-ny, x0+nx, y0-ny); // Plot intensity } } bgr.setColor(Color.white); bgr.drawString("FCC n = "+(int)(Math.pow(2, n)), 5, 235); g.drawImage(bim, 80, 0, null); // Show plot buffer tt=System.currentTimeMillis(); while ((System.currentTimeMillis()-tt)<1000) { } } } kk=0; } public void actionPerformed(ActionEvent e) { // Buttons String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { kk=1; } if (b2s.equals(tst)) { kk=2; } repaint(); } }