import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.geom.*; import java.math.*; /*This class draws some of the objects for the hexagrid demo*/ public class HexagridDemo { public static GeneralPath hexParallelogramPlus(double A,double lambda) { float a=(float)(A); float b1=(float)(2*a-lambda); float b2=(float)(a-lambda); GeneralPath gp=new GeneralPath(); gp.moveTo(2*a,0); gp.lineTo(a,1); gp.lineTo(b2,1); gp.lineTo(b1,0); gp.closePath(); return(gp); } public static GeneralPath hexParallelogramMinus(double A,double lambda) { AffineTransform AT=AffineTransform.getTranslateInstance(-A,0); GeneralPath gp=hexParallelogramPlus(A,lambda); gp.transform(AT); return(gp); } public static GeneralPath hexRectanglePlus1(double A,double mu) { float a=(float)(A); float b1=(float)(mu); GeneralPath gp=new GeneralPath(); gp.moveTo(2*a,0); gp.lineTo(2*a,a); gp.lineTo(b1,a); gp.lineTo(b1,0); gp.closePath(); return(gp); } public static GeneralPath hexRectangleMinus1(double A,double mu) { AffineTransform AT=AffineTransform.getTranslateInstance(-A,0); GeneralPath gp=hexRectanglePlus1(A,mu); gp.transform(AT); return(gp); } public static GeneralPath hexRectanglePlus2(double A,double mu) { float a=(float)(A); float b1=(float)(mu); GeneralPath gp=new GeneralPath(); gp.moveTo(2*a,a); gp.lineTo(2*a,1); gp.lineTo(b1,1); gp.lineTo(b1,a); gp.closePath(); return(gp); } public static GeneralPath hexRectangleMinus2(double A,double mu) { AffineTransform AT=AffineTransform.getTranslateInstance(-A,0); GeneralPath gp=hexRectanglePlus2(A,mu); gp.transform(AT); return(gp); } public static double mu(int i,int j,double A) { if((i== 0)&&(j==1)) return(-A); if((i==-1)&&(j==-1)) return(-1+2*A); if((i==-1)&&(j==0)) return(-1); if((i==-1)&&(j==1)) return(-1-2*A); return(0); } public static double lambda(int i,int j,double A) { if((i== 0)&&(j==1)) return(2*A); if((i==-1)&&(j==-1)) return(1-0*A-A*A); if((i==-1)&&(j==0)) return(1+2*A-A*A); if((i==-1)&&(j==1)) return(1+4*A-A*A); return(0); } public static GeneralPath hexParallelogramPlus(int i,int j,double A) { double d=lambda(i,j,A); return(hexParallelogramPlus(A,d)); } public static GeneralPath hexParallelogramMinus(int i,int j,double A) { double d=lambda(i,j,A); return(hexParallelogramMinus(A,d)); } public static GeneralPath hexRectanglePlus1(int i,int j,double A) { double d=mu(i,j,A); return(hexRectanglePlus1(A,d)); } public static GeneralPath hexRectangleMinus1(int i,int j,double A) { double d=mu(i,j,A); return(hexRectangleMinus1(A,d)); } public static GeneralPath hexRectanglePlus2(int i,int j,double A) { double d=mu(i,j,A); if((i!=0)||(j!=1)) d=d-A; return(hexRectanglePlus2(A,d)); } public static GeneralPath hexRectangleMinus2(int i,int j,double A) { double d=mu(i,j,A); if((i!=0)||(j!=1)) d=d-A; return(hexRectangleMinus2(A,d)); } }