/* * dff7.java - revised 4 Oct 09 - width 321, height 241 * @author jackord@kw.igs.net * X-ray diffraction patterns for cubic crystals generated by superimposing * Huygens' wavelets from an nxnxn array of single atoms (SC) or a basis of * two (BCC) or four (FCC) atoms, where n=8, 12, 16, or 20. * The wavelength can be chosen to enhance diffraction from * (111), (201), or (211) planes. * The pattern from the basis is displayed first (for 2 seconds), * then frames 1 to n show the development of the pattern as a row is formed, * frames n+1 to 2*n as rows are added to form a layer, * and finally frames 2*n+1 to 3*n as layers are added to form a cube. */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class dff7 extends Applet implements ActionListener { int kk=0; int first=0; // Declarations String b1s="SC"; Button b1=new Button(b1s); String b2s="BCC"; Button b2=new Button(b2s); String b3s="FCC"; Button b3=new Button(b3s); Choice chla=new Choice(); Choice chnb=new Choice(); Choice chex=new Choice(); Image bim; Graphics bgr; public void init() { setBackground(new Color(211, 211, 211)); chla.setBackground(getBackground()); chnb.setBackground(getBackground()); chex.setBackground(getBackground()); setFont(new Font("Helvetica", Font.PLAIN, 12)); add(b1); b1.addActionListener(this); add(b2); b2.addActionListener(this); add(b3); b3.addActionListener(this); chla.addItem("la=2a/3"); chla.addItem("la=2a/5"); chla.addItem("la=2a/6"); add(chla); chnb.addItem("n=8"); chnb.addItem("n=12"); chnb.addItem("n=16"); chnb.addItem("n=20"); add(chnb); chex.addItem("expX1"); chex.addItem("expX10"); chex.addItem("expX100"); add(chex); chla.select(0); chnb.select(3); chex.select(0); } public void paint(Graphics g) { // Main Program if (first==0) { bim=createImage(241, 241); // Animation buffer bgr=bim.getGraphics(); first=1; } b1.setBounds(20, 5, 40, 20); b2.setBounds(20, 30, 40, 20); b3.setBounds(20, 55, 40, 20); chla.setBounds(5, 80, 70, 20); chnb.setBounds(5, 105, 70, 20); chex.setBounds(5, 130, 70, 20); int c, cg, im, n, ne, ni, x0, y0, del; int [] nb=new int[4]; int [] ex=new int[3]; double a, b, d, z, zz, r0, qr, qi, rr, ri, sr, si, t, sc, sn; double [] la=new double[3]; long tt; a=3.615E-7; x0=120; y0=120; z=30.; zz=z*z; // Cu lattice parameter nb[0]=8; nb[1]=12; nb[2]=16; nb[3]=20; ex[0]=1; ex[1]=10; ex[2]=100; la[0]=2*a/3; la[1]=2*a/5; la[2]=2*a/6; double pi=Math.PI; g.setColor(Color.black); // Initial screen g.drawRect(0, 0, 320, 240); n=nb[chnb.getSelectedIndex()]; // Row length ne=ex[chex.getSelectedIndex()]; // Overexposure // Row length if (kk>0) { // Default Simple Cubic for (int nf=0; nf<=3*n; nf=nf+1) { if ((nf==0)||(nf==n)||(nf==2*n)) { del=2000; } else { del=250; } bgr.setColor(Color.black); bgr.fillRect(0, 0, 241, 241); for (int ny=-119; ny<=119; ny=ny+1) { // Screen Y loop for (int nx=-119; nx<=119; nx=nx+1) { // Screen X loop r0=Math.sqrt(zz+nx*nx+ny*ny); b=2*pi*a/r0/la[chla.getSelectedIndex()]; sr=1; si=0; ni=1; sn=1.0; if (kk==2) { // Body-Centred Cubic t=b/2*(nx+ny+z-r0); rr=Math.cos(t); ri=Math.sin(t); qr=sr+rr*sr-ri*si; si=si+rr*si+ri*sr; sr=qr; } if (kk==4) { // Face-Centred Cubic t=b/2*(nx+ny); rr=Math.cos(t); ri=Math.sin(t); qr=sr+rr*sr-ri*si; qi=si+rr*si+ri*sr; t=b/2*(nx+z-r0); rr=Math.cos(t); ri=Math.sin(t); qr=qr+rr*sr-ri*si; qi=qi+rr*si+ri*sr; t=b/2*(ny+z-r0); rr=Math.cos(t); ri=Math.sin(t); qr=qr+rr*sr-ri*si; qi=qi+rr*si+ri*sr; sr=qr; si=qi; } if (nf>0) { if (nf<=n) { im=nf; } else { im=n; } for (int i=1; i<=im; i=i+1) { // Array X loop t=b*ni*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; } } if (nf>n) { if (nf<=2*n) { im=nf-n; } else { im=n; } ni=1; // Array Y loop for (int i=1; i<=im; i=i+1) { t=ni*b*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; } } if (nf>2*n) { ni=1; for (int i=1; i<=nf-2*n; i=i+1) { // Array Z loop t=ni*b*(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=ne*1000./sn/kk; // 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 } } g.setColor(getBackground()); g.fillRect(5, 190, 70, 48); g.setColor(Color.black); g.drawString("Frame "+nf, 10, 235); if (nf==0) { g.drawString("Basis", 10, 215); } if (nf==n) { g.drawString("Row", 10, 215); } if (nf==2*n) { g.drawString("Layer", 10, 215); } if (nf==3*n) { g.drawString("Cube", 10, 215); } g.drawImage(bim, 80, 0, null); tt=System.currentTimeMillis()+del; while (tt>System.currentTimeMillis()) { } } 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; } if (b3s.equals(tst)) { kk=4; } repaint(); } }