/* spirolateral 10/22/99 JDK 1.0 */ /* thick lines */ /* include list of possible schemes */ /* sprolat6 */ import java.awt.*; import java.awt.Graphics; import java.awt.Color; import java.applet.*; import java.util.Random; import java.lang.String; import java.lang.Math; /* -------------------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------------------- */ class Point2d6 { float x, y; Point2d6() { x = 0f; y = 0f; } Point2d6(float x0, float y0) { x = x0; y = y0; } } /* ---------------------------------------------------------------------------- */ class DrawSpirolat6 extends Canvas { /* turning angle, number of steps, number of repeats */ float tangle; int nsteps, nrepeat; String nlefts; boolean clrepeat, clstep; boolean drwfill, drwcenter, drwedges, drwcorner; double widfact; Color BackColor; int pxtrans, pytrans; float xtrans, ytrans, pscale; public void paint(Graphics g) { float walllen = 10; int numlines = 0; int irepeat, istep; int count = 0, ncount = 0; int into, inti; int docont = 0; int npts = 0; float xmin = 10000, ymin = 10000, xmax = -10000, ymax = -10000; float totalangle = 0; float itotalangle; int iturn, niturn; int nlen; float xdim, ydim; int i; int pxpt = 0, pypt = 0, clxpt = 0, clypt = 0; int ilxpt = 0, ilypt = 0, olxpt = 0, olypt = 0; String cstep, ctemp; Point2d6 pt1 = new Point2d6(0,0), pt2 = new Point2d6(0,0); Point2d6 fpt1 = new Point2d6(0,0); Point2d6 fipt = new Point2d6(0,0), fopt = new Point2d6(0,0); Point2d6 ipt1 = new Point2d6(0,0), opt1 = new Point2d6(0,0); Point2d6 ipt2 = new Point2d6(0,0), opt2 = new Point2d6(0,0); Point2d6 ipt3 = new Point2d6(0,0), opt3 = new Point2d6(0,0); Point2d6 ipt4 = new Point2d6(0,0), opt4 = new Point2d6(0,0); float cdist = 0f; Point2d6 cpts[] = new Point2d6[2000]; Point2d6 ipts[] = new Point2d6[2000]; Point2d6 opts[] = new Point2d6[2000]; int polyx[] = new int[4]; int polyy[] = new int[4]; float wfact = (float)widfact/2; float islope, cslope, oslope; /* System.out.println("next"); */ pt1 = new Point2d6(0,0); numlines = 0; npts = 0; ctemp = "0,"+nlefts; for (irepeat = 1; irepeat <= nrepeat; irepeat++) { nlen = 10; count = 1; for (istep = 1; istep <= nsteps; istep++) { /* check for left turn */ cstep = ","+String.valueOf(istep); iturn = -1; if (ctemp.indexOf(cstep) > 0) iturn = 1; /* inc angle */ totalangle = totalangle + (float)((180.0 - tangle) * iturn); pt2 = Polar(pt1.x, pt1.y, totalangle, (float)nlen); /* first inside/outside point */ if (numlines==0) { cstep = ","+String.valueOf(2); niturn = -1; if (ctemp.indexOf(cstep) > 0) niturn = 1; itotalangle = totalangle - 90; if (niturn==1) itotalangle = totalangle + 90; fpt1 = pt1; ipt1 = Polar(fpt1.x,fpt1.y,itotalangle,(walllen * wfact)); opt1 = Polar(fpt1.x,fpt1.y,(itotalangle+180),(walllen * wfact)); npts = npts + 1; cpts[npts] = pt1; if (niturn==1) { ipt2 = ipt1; ipt1 = opt1; opt1 = ipt2; } fipt = ipt1; fopt = opt1; } /* distance to next point */ cdist = Distance(fpt1,pt2); /* check for last point */ if ((numlines == ((nrepeat*nsteps)-1)) && (cdist > 0.1)) { /* edges on current line */ ipt2 = Polar(ipt1.x,ipt1.y,totalangle,(nlen*5)); opt2 = Polar(opt1.x,opt1.y,totalangle,(nlen*5)); itotalangle = totalangle; ipt3 = pt2; ipt4 = Polar(ipt3.x,ipt3.y,(itotalangle+90),(nlen*5)); opt3 = pt2; opt4 = Polar(opt3.x,opt3.y,(itotalangle-90),(nlen*5)); /* compute intersection */ ipt2 = xyint(ipt1,ipt2,ipt3,ipt4); opt2 = xyint(opt1,opt2,opt3,opt4); } /* check for not last point */ if ((numlines != ((nrepeat*nsteps)-1)) || (cdist < 0.1)) { /* edges on current line */ ipt2 = Polar(ipt1.x,ipt1.y,totalangle,(nlen*5)); opt2 = Polar(opt1.x,opt1.y,totalangle,(nlen*5)); /* edges on next line */ ncount = count+1; if (ncount > nsteps) ncount=1; cstep = ","+String.valueOf(ncount); niturn = -1; if (ctemp.indexOf(cstep) > 0) niturn = 1; itotalangle = (totalangle + ((180 - tangle) * niturn)); ipt3 = Polar(pt2.x,pt2.y,(itotalangle-90),(walllen*wfact)); ipt4 = Polar(ipt3.x,ipt3.y,itotalangle,(nlen*5)); opt3 = Polar(pt2.x,pt2.y,(itotalangle+90),(walllen*wfact)); opt4 = Polar(opt3.x,opt3.y,(itotalangle+180),(nlen*5)); /* compute intersection */ ipt2 = xyint(ipt1,ipt2,ipt3,ipt4); opt2 = xyint(opt1,opt2,opt3,opt4); /* check for intersection on outside edge */ opt3 = Polar(opt2.x,opt2.y,itotalangle,(nlen*5)); into = ifint(ipt1,ipt2,opt2,opt3); /* check for intersection on inside edge */ ipt3 = Polar(ipt2.x,ipt2.y,itotalangle,(nlen*5)); inti = ifint(ipt2,ipt3,opt1,opt2); /* check intersections - flip inside and outside */ if ((into == 1) || (inti == 1)) { /* edges on current line */ ipt2 = Polar(ipt1.x,ipt1.y,totalangle,(nlen*5)); opt2 = Polar(opt1.x,opt1.y,totalangle,(nlen*5)); /* edges on next line */ ncount = count+1; if (ncount > nsteps) ncount=1; cstep = ","+String.valueOf(ncount); niturn = -1; if (ctemp.indexOf(cstep) > 0) niturn = 1; itotalangle = totalangle+((180-tangle)*niturn); ipt3 = Polar(pt2.x,pt2.y,(itotalangle+90),(walllen*wfact)); ipt4 = Polar(ipt3.x,ipt3.y,(itotalangle+180),(nlen*5)); opt3 = Polar(pt2.x,pt2.y,(itotalangle-90),(walllen*wfact)); opt4 = Polar(opt3.x,opt3.y,itotalangle,(nlen*5)); /* compute intersection */ ipt2 = xyint(ipt1,ipt2,ipt3,ipt4); opt2 = xyint(opt1,opt2,opt3,opt4); } } /* check if closed */ if (cdist < 0.1) { if (widfact < 1.0) { fipt = ipt2; fopt = opt2; } docont = 1; } npts = npts + 1; ipts[npts] = ipt2; opts[npts] = opt2; cpts[npts] = pt2; /* min/max */ if (pt2.x > xmax) xmax = pt2.x; if (pt2.x < xmin) xmin = pt2.x; if (pt2.y > ymax) ymax = pt2.y; if (pt2.y < ymin) ymin = pt2.y; if (ipt2.x > xmax) xmax = ipt2.x; if (ipt2.x < xmin) xmin = ipt2.x; if (ipt2.y > ymax) ymax = ipt2.y; if (ipt2.y < ymin) ymin = ipt2.y; if (opt2.x > xmax) xmax = opt2.x; if (opt2.x < xmin) xmin = opt2.x; if (opt2.y > ymax) ymax = opt2.y; if (opt2.y < ymin) ymin = opt2.y; cslope = (pt2.y-pt1.y)/(pt2.x-pt1.x); islope = (ipt2.y-ipt1.y)/(ipt2.x-ipt1.x); oslope = (opt2.y-opt1.y)/(opt2.x-opt1.x); /* System.out.println(npts+" "+"Slope "+islope+" "+cslope+" "+oslope); System.out.println(" "+Distance(pt1,pt2)+" "+Distance(ipt1,ipt2)+" "+Distance(opt1,opt2)); if (Distance(ipt1,ipt2) > Distance(opt1,opt2)) System.out.println("Ignore: "+widfact+" "+tangle+" "+nsteps+" "+nrepeat); */ nlen = nlen + 10; ipt1 = ipt2; opt1 = opt2; pt1 = pt2; numlines = numlines+1; /* check for points */ if ((npts == 1999) || (docont == 1)) { istep = nsteps + 1; irepeat = nrepeat + 1; } count = count + 1; } } /* set first point */ ipts[1] = fipt; opts[1] = fopt; System.out.println(cdist+" "+tangle+" "+nsteps+" "+nrepeat); /* compute scale to canvas size */ xdim = xmax - xmin; ydim = ymax - ymin; pscale = Math.min((size().width-90) / xdim, (size().height-90) / ydim); xtrans = (float) (0 - xmin); ytrans = (float) (0 - ymin); pxtrans = (((size().width-90) - (int)(xdim * pscale))/2)+40; pytrans = (((size().height-90) - (int)(ydim * pscale))/2)+40; /* clear screen */ g.clipRect(10,10,size().width-20,size().height-20); g.setColor(BackColor); g.fillRect(10,10,size().width-10,size().height-10); /* draw spirolateral */ if (drwfill) { g.setColor(Color.black); for (i = 1; i <= npts; i++) { polyx[3] = Math.round( (((ipts[i].x+xtrans)*pscale)+pxtrans) ); polyy[3] = Math.round( (((ipts[i].y+ytrans)*pscale)+pytrans) ); polyx[2] = Math.round( (((opts[i].x+xtrans)*pscale)+pxtrans) ); polyy[2] = Math.round( (((opts[i].y+ytrans)*pscale)+pytrans) ); if (i != 1) g.fillPolygon(polyx, polyy, 4); polyx[0] = polyx[3]; polyy[0] = polyy[3]; polyx[1] = polyx[2]; polyy[1] = polyy[2]; }} if (drwfill) g.setColor(BackColor); else g.setColor(Color.black); for (i = 1; i <= npts; i++) { if (drwcenter) { pxpt = Math.round( (((cpts[i].x+xtrans)*pscale)+pxtrans) ); pypt = Math.round( (((cpts[i].y+ytrans)*pscale)+pytrans) ); if (i != 1) g.drawLine(clxpt,clypt,pxpt,pypt); clxpt = pxpt; clypt = pypt; } if (drwedges) { pxpt = Math.round( (((ipts[i].x+xtrans)*pscale)+pxtrans) ); pypt = Math.round( (((ipts[i].y+ytrans)*pscale)+pytrans) ); if (i != 1) g.drawLine(ilxpt,ilypt,pxpt,pypt); ilxpt = pxpt; ilypt = pypt; pxpt = Math.round( (((opts[i].x+xtrans)*pscale)+pxtrans) ); pypt = Math.round( (((opts[i].y+ytrans)*pscale)+pytrans) ); if (i != 1) g.drawLine(olxpt,olypt,pxpt,pypt); olxpt = pxpt; olypt = pypt; } } if (drwcorner) { Corners(numlines, ipts, opts, g); } } /* ---------------------------------------------------------------------------- */ public void Corners(int numlines, Point2d6 ipts[], Point2d6 opts[], Graphics g) { float hdiff = 0f, hdist = 0f, idist = 0f, odist = 0f; float harea, farea; float iang, oang; int ilxpt = 0, ilypt = 0, olxpt = 0, olypt = 0; int i; float walllen = 10; float wfact = (float)widfact/2; Point2d6 ipt1 = new Point2d6(0,0), opt1 = new Point2d6(0,0); Point2d6 ipt2 = new Point2d6(0,0), opt2 = new Point2d6(0,0); Point2d6 iflpt = new Point2d6(0,0), iblpt = new Point2d6(0,0); Point2d6 oflpt = new Point2d6(0,0), oblpt = new Point2d6(0,0); Point2d6 cflpt = new Point2d6(0,0), cblpt = new Point2d6(0,0); hdiff = 0f; for (i = 1; i <= numlines; i++) { ipt1 = ipts[i]; ipt2 = ipts[i+1]; idist = Distance(ipt1,ipt2); opt1 = opts[i]; opt2 = opts[i+1]; odist = Distance(opt1,opt2); hdist = (float)(Math.abs(odist-idist) / 2f); if (hdist > hdiff) hdiff = hdist; } /* hdiff = Math.round(hdiff*1000)/1000; */ harea = (hdiff * ((walllen * wfact) * 2f)) / 2f; System.out.println("hdiff,harea="+hdiff+" "+harea); for (i = 1; i <= numlines; i++) { iflpt = ipts[i]; oflpt = opts[i]; iblpt = ipts[i+1]; oblpt = opts[i+1]; idist = Distance(iflpt,iblpt); odist = Distance(oflpt,oblpt); /* idist = Math.round(Distance(iflpt,iblpt)*1000)/1000; odist = Math.round(Distance(oflpt,oblpt)*1000)/1000; */ iang = Angle(iflpt,iblpt); oang = Angle(oflpt,oblpt); if (Math.round(idist*100) == Math.round(odist*100)) { cflpt = Polar(iflpt.x,iflpt.y,iang,hdiff); cblpt = Polar(oflpt.x,oflpt.y,iang,(idist-hdiff)); farea = (Distance(cflpt,iflpt) * Distance(cflpt,oflpt)) / 2f; if (Math.round(farea*100) != Math.round(harea*100)) { cflpt = Polar(oflpt.x,oflpt.y,iang,hdiff); cblpt = Polar(iflpt.x,iflpt.y,iang,(idist-hdiff)); } /* bottom */ ilxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((iflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((iflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((oflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((oflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((iblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((iblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((oblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((oblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); } if (idist > odist) { cflpt = Polar(iflpt.x,iflpt.y,iang,hdiff); cblpt = Polar(iflpt.x,iflpt.y,iang,(idist-hdiff)); /* bottom */ ilxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((oflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((oflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((iflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((iflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((iblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((iblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((oblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((oblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); } if (odist > idist) { cflpt = Polar(oflpt.x,oflpt.y,oang,hdiff); cblpt = Polar(oflpt.x,oflpt.y,oang,(odist-hdiff)); /* bottom */ ilxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((oflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((oflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((iflpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((iflpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cflpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cflpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((iblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((iblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); ilxpt = Math.round( (((oblpt.x+xtrans)*pscale)+pxtrans) ); ilypt = Math.round( (((oblpt.y+ytrans)*pscale)+pytrans) ); olxpt = Math.round( (((cblpt.x+xtrans)*pscale)+pxtrans) ); olypt = Math.round( (((cblpt.y+ytrans)*pscale)+pytrans) ); g.drawLine(ilxpt,ilypt,olxpt,olypt); } } } /* ---------------------------------------------------------------------------- */ public float Angle(Point2d6 p1, Point2d6 p2) { float xoff, yoff, ang; xoff = p2.x - p1.x; yoff = p2.y - p1.y; ang = 0f; if (Math.round(xoff*100) == 0) { if (yoff < 0f) ang = 270f; ang = 90f; } { ang = (float)(Math.atan(yoff / xoff) * 180f / 3.14156); if (xoff < 0f) ang = ang + 180f; ang = 360f + ang; } return ang; } /* ---------------------------------------------------------------------------- */ public float Distance(Point2d6 p1, Point2d6 p2) { return (float)Math.sqrt((float)Math.pow(p1.x-p2.x,2)+(float)Math.pow(p1.y-p2.y,2)); } /* ---------------------------------------------------------------------------- */ public Point2d6 Polar(float xpt, float ypt, float ang, float dist) { return (new Point2d6( (float) (xpt + (dist * Math.cos((double)ang * (3.14156/180)))), (float) (ypt + (dist * Math.sin((double)ang * (3.14156/180)))))); } /* ---------------------------------------------------------------------------- */ public Point2d6 xyint(Point2d6 p1, Point2d6 p2, Point2d6 p3, Point2d6 p4) { double a, b, e, c, d, f; double xk, yk, xl, yl, xm, ym, xn, yn; /* first, check to see if the segments intersect by parameterization on s and t; if s and t are both between [0,1], then the segments intersect */ xk = (double)p1.x; yk = (double)p1.y; xl = (double)p2.x; yl = (double)p2.y; xm = (double)p3.x; ym = (double)p3.y; xn = (double)p4.x; yn = (double)p4.y; /* check to see if the segments have any endpoints in common. If they do, then return the endpoints as the intersection point */ if ((xk==xm) && (yk==ym)) { return (new Point2d6((float)xk, (float)yk)); } if ((xk==xn) && (yk==yn)) { return (new Point2d6((float)xk, (float)yk)); } if ((xl==xm) && (yl==ym)) { return (new Point2d6((float)xl, (float)yl)); } if ((xl==xn) && (yl==yn)) { return (new Point2d6((float)xl, (float)yl)); } /* check to see if they intersect */ a = -(yl-yk); b = xl-xk; c = -(yn-ym); d = xn-xm; e = -(a*xk)-(b*yk); f = -(c*xm)-(d*ym); /* they intersect, so compute the intersection point using ax+by+e = 0 and cx+dy+f = 0 */ return (new Point2d6((float)(-(e*d-b*f)/(a*d-c*b)), (float)(-(a*f-c*e)/(a*d-c*b)))); } /* ---------------------------------------------------------------------------- */ public int ifint(Point2d6 p1, Point2d6 p2, Point2d6 p3, Point2d6 p4) { double xk, yk, xl, yl, xm, ym, xn, yn; double s, t; /* first, check to see if the segments intersect by parameterization on s and t; if s and t are both between [0,1], then the segments intersect */ xk = (double)p1.x; yk = (double)p1.y; xl = (double)p2.x; yl = (double)p2.y; xm = (double)p3.x; ym = (double)p3.y; xn = (double)p4.x; yn = (double)p4.y; s = (double)(((xn-xm)*(ym-yk)-(yn-ym)*(xm-xk))/((xn-xm)*(yl-yk)-(yn-ym)*(xl-xk))); t = (double)(((xl-xk)*(ym-yk)-(yl-yk)*(xm-xk))/((xn-xm)*(yl-yk)-(yn-ym)*(xl-xk))); if (((s < 1) && (s > 0)) && ((t < 1) && (t > 0))) return 1; return 0; } /* ---------------------------------------------------------------------------- */ public float testdist() { float walllen = 10; int irepeat, istep; float totalangle = 0; int iturn, niturn; int nlen; String cstep, ctemp; Point2d6 pt1 = new Point2d6(0,0), pt2 = new Point2d6(0,0); Point2d6 fpt1 = new Point2d6(0,0); float cdist = 0f; ctemp = "0,"+nlefts; for (irepeat = 1; irepeat <= nrepeat; irepeat++) { nlen = 1; for (istep = 1; istep <= nsteps; istep++) { /* check for left turn */ cstep = ","+String.valueOf(istep); iturn = -1; if (ctemp.indexOf(cstep) > 0) iturn = 1; /* inc angle */ totalangle = totalangle + (float)((180.0 - tangle) * iturn); pt2 = Polar(pt1.x, pt1.y, totalangle, (float)nlen); /* distance to next point */ cdist = Distance(fpt1,pt2); nlen = nlen + 1; pt1 = pt2; } } return cdist; } /* ---------------------------------------------------------------------------- */ } /* -------------------------------------------------------------------------------------- */ public class sprolat6 extends java.applet.Applet { Panel opt1, opt2, opt3, opt4, opt8, optn, opts; DrawSpirolat6 pict; TextField tangle, nsteps, nrepeat, nlefts, widfact; Button anextbutton, aprevbutton, rnextbutton, rprevbutton; Button drawbutton, blankbutton; Checkbox cboxfill,cboxcenter,cboxedges,cboxcorner; Scrollbar swidfact; Label anumrev; float demoang[] = { 18f, 18f, 18f, 20f, 20f, 20f, 20f, 22.5f, 22.5f, 22.5f, 22.5f, 25.714f,25.714f,25.714f, 30f, 30f, 30f, 30f, 30f, 30f, 36f, 36f, 36f, 36f, 36f, 40f, 40f, 40f, 40f, 40f, 45f, 45f, 45f, 45f, 45f, 45f, 45f, 54f, 54f, 60f, 60f, 60f, 60f, 60f, 60f, 60f, 72f, 72f, 72f, 75f, 75f, 75f, 84f, 84f, 90f, 90f, 90f, 90f, 90f, 90f, 96f, 100f, 100f, 105f, 108f, 108f, 108f, 120f, 120f, 120f, 126f, 132f, 132f, 135f }; int demostep[] = { 2, 4, 5, 1, 2, 3, 6, 2, 4, 6, 8, 1, 2, 4, 2, 3, 4, 6, 8, 9, 1, 2, 3, 4, 7, 2, 3, 4, 6, 8, 1, 2, 3, 4, 6, 7, 10, 4, 5, 1, 2, 4, 5, 7, 8, 10, 2, 4, 6, 4, 6, 8, 3, 5, 3, 5, 6, 7, 9, 10, 10, 3, 6, 8, 2, 3, 6, 4, 8, 10, 10, 5, 10, 6 }; int demorepeat[] = { 10, 5, 4, 9, 9, 3, 3, 8, 4, 8, 2, 7, 7, 7, 6, 4, 3, 2, 3, 4, 5, 5, 5, 5, 5, 9, 6, 9, 3, 9, 8, 4, 8, 2, 4, 8, 4, 5, 4, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 6, 4, 3, 5, 3, 4, 4, 2, 4, 4, 2, 3, 3, 3, 3, 5, 5, 5, 3, 3, 3, 2, 3, 3, 4 }; int demomax, demonum; String demorevs[] = new String[520]; int demorevnum,demorevmax; float widsang[] = { 18f, 20f, 22.5f, 25.714f, 30f, 36f, 40f, 45f, 180f }; float widsmax[] = { 0.32f, 0.36f, 0.41f, 0.48f, 0.57f, 0.72f, 0.83f, 0.99f, 0.99f }; boolean fromlist = true; public void init() { demomax = demoang.length - 1; demonum = 0; demorevnum = 0; fromlist = true; pict = new DrawSpirolat6(); /* Color ColorBeige = new Color(156,123,75); Color ColorBeige = new Color(255,255,255); Color ColorBeige = new Color(221,206,178); */ Color ColorBeige = new Color(221,206,178); this.setBackground(ColorBeige); pict.BackColor = ColorBeige; pict.setBackground(ColorBeige); pict.tangle = demoang[0]; pict.nsteps = demostep[0]; pict.nrepeat = demorepeat[0]; pict.drwfill = true; pict.drwcenter = true; pict.drwedges = true; pict.drwcorner = false; pict.widfact = 0.20; buildrevs(pict.nsteps); pict.nlefts = demorevs[0]; opt1 = new Panel(); opt1.setLayout( new GridLayout(3,2,10,10) ); opt1.add(new Label("Angle:",Label.RIGHT)); tangle = new TextField(String.valueOf(pict.tangle),6); opt1.add(tangle); opt1.add(new Label("Turns:",Label.RIGHT)); nsteps = new TextField(String.valueOf(pict.nsteps),4); opt1.add(nsteps); opt1.add(new Label("Repeat:",Label.RIGHT)); nrepeat = new TextField(String.valueOf(pict.nrepeat),4); opt1.add(nrepeat); /* nsteps.setEditable(false); tangle.setEditable(false); nrepeat.setEditable(false); */ opt2 = new Panel(); opt2.setLayout( new GridLayout(4,1,0,0) ); opt2.add(new Label("Reverse at steps: ",Label.LEFT)); nlefts = new TextField(String.valueOf(pict.nlefts),10); opt2.add(nlefts); nlefts.setEditable(false); opt2.add(new Label(" ",Label.LEFT)); anumrev = new Label(String.valueOf(demorevmax)+" possible reverses",Label.LEFT); opt2.add(anumrev); opt3 = new Panel(); opt3.setLayout( new GridLayout(3,4,0,0) ); aprevbutton = new Button("<<"); opt3.add(aprevbutton); rprevbutton = new Button("<"); opt3.add(rprevbutton); rnextbutton = new Button(">"); opt3.add(rnextbutton); anextbutton = new Button(">>"); opt3.add(anextbutton); opt3.add(new Label(" Ang ",Label.LEFT)); opt3.add(new Label(" Rev",Label.LEFT)); opt3.add(new Label(" Rev",Label.LEFT)); opt3.add(new Label(" Ang ",Label.LEFT)); opt3.add(new Label(" ",Label.LEFT)); opt3.add(new Label(" ",Label.LEFT)); opt3.add(new Label(" ",Label.LEFT)); opt3.add(new Label(" ",Label.LEFT)); opt4 = new Panel(); opt4.setLayout( new GridLayout(3,2,10,0) ); drawbutton = new Button("Draw"); opt4.add(drawbutton); blankbutton = new Button(" "); opt4.add(blankbutton); opt4.add(new Label(" ",Label.LEFT)); opt4.add(new Label(" ",Label.LEFT)); opt4.add(new Label(" ",Label.LEFT)); opt4.add(new Label(" ",Label.LEFT)); opt8 = new Panel(); opt8.setLayout( new GridLayout(2,9,5,5) ); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); opt8.add(new Label(" ",Label.LEFT)); cboxfill = new Checkbox ("Fill"); opt8.add(cboxfill); cboxfill.setState(true); cboxcenter = new Checkbox ("Center"); cboxcenter.setState(true); opt8.add(cboxcenter); cboxedges = new Checkbox ("Edges"); opt8.add(cboxedges); cboxedges.setState(true); cboxcorner = new Checkbox ("Corners"); opt8.add(cboxcorner); cboxcorner.setState(false); opt8.add(new Label("Thickness:",Label.RIGHT)); widfact = new TextField("0.20",5); opt8.add(widfact); swidfact = new Scrollbar(Scrollbar.HORIZONTAL, 20, 0, 1, 99); opt8.add(swidfact); /* opt8.add(new Label(" ",Label.LEFT)); */ /* optn = new Panel(); optn.setLayout( new GridLayout(1,1,0,0) ); optn.add(new Label("Spirolateral 1.2",Label.LEFT)); */ opts = new Panel(); opts.setLayout( new GridLayout(0,1,10,5) ); opts.add(opt1); opts.add(opt2); opts.add(opt3); opts.add(opt4); Panel p = new Panel(); p.add(opts); setLayout(new BorderLayout() ); add("East", p); add("Center", pict); add("South", opt8); } public Insets insets() { return new Insets(10,10,10,10); } public void paint(Graphics g) { /* pict.paint(g); */ } public void update(Graphics g) { paint(g); } public boolean action(Event evt, Object arg) { boolean redraw = false; double dvalue; float maxwid = 0.99f; int nvalue; /* next/prev spirolaterals */ if (">>".equals(arg) || "<<".equals(arg)) { if (">>".equals(arg)) { demonum = demonum + 1; if (demonum > demomax) demonum = 0; demorevnum = 0; redraw=true; pict.tangle = demoang[demonum]; pict.nsteps = demostep[demonum]; pict.nrepeat = demorepeat[demonum]; buildrevs(demostep[demonum]); fromlist = true; } else { demonum = demonum - 1; if (demonum < 0) demonum = demomax; demorevnum = 0; redraw=true; pict.tangle = demoang[demonum]; pict.nsteps = demostep[demonum]; pict.nrepeat = demorepeat[demonum]; buildrevs(demostep[demonum]); fromlist = true; } } /* next/prev reverse */ if (">".equals(arg) || "<".equals(arg)) { if (">".equals(arg)) { demorevnum = demorevnum + 1; if (demorevnum > demorevmax) demorevnum = 0; redraw=true; } else { demorevnum = demorevnum - 1; if (demorevnum < 0) demorevnum = demorevmax; redraw=true; } } if ("Draw".equals(arg)) { if (tangle.getText() != null) { try { dvalue = Double.valueOf(tangle.getText()).doubleValue(); if (dvalue <= 0.0) dvalue = 1.0; if (dvalue > 360.0) dvalue = 90.0; pict.tangle = (float)dvalue; tangle.setText(String.valueOf(dvalue)); } catch (Exception e) { } } if (nsteps.getText() != null) { try { nvalue = Integer.valueOf(nsteps.getText()).intValue(); if (nvalue <= 0) nvalue = 1; if (nvalue > 50) nvalue = 50; pict.nsteps = nvalue; nsteps.setText(String.valueOf(nvalue)); } catch (Exception e) { } } if (nrepeat.getText() != null) { try { nvalue = Integer.valueOf(nrepeat.getText()).intValue(); if (nvalue <= 0) nvalue = 1; if (nvalue > 100) nvalue = 100; pict.nrepeat = nvalue; nrepeat.setText(String.valueOf(nvalue)); } catch (Exception e) { } } demorevnum = 0; redraw=true; buildrevs(pict.nsteps); fromlist = false; } if (evt.target == cboxfill) { pict.drwfill=cboxfill.getState(); redraw=true; } if (evt.target == cboxcenter) { pict.drwcenter=cboxcenter.getState(); redraw=true; } if (evt.target == cboxedges) { pict.drwedges=cboxedges.getState(); redraw=true; } if (evt.target == cboxcorner) { pict.drwcorner=cboxcorner.getState(); redraw=true; } /* check drw settings */ if ((pict.drwfill==false) && (pict.drwedges==false)) { pict.drwcenter = true; cboxcenter.setState(true); } if (widfact.getText() != null) { try { dvalue = Double.valueOf(widfact.getText()).doubleValue(); if (dvalue <= 0.0) dvalue = 0.01; if (dvalue >= 1.0) dvalue = 0.99; pict.widfact = (float)dvalue; widfact.setText(String.valueOf(dvalue)); redraw=true; } catch (Exception e) { } } if ((redraw) && (fromlist)) { pict.tangle = demoang[demonum]; tangle.setText(String.valueOf(pict.tangle)); pict.nsteps = demostep[demonum]; nsteps.setText(String.valueOf(pict.nsteps)); pict.nrepeat = demorepeat[demonum]; nrepeat.setText(String.valueOf(pict.nrepeat)); pict.nlefts = demorevs[demorevnum]; nlefts.setText(pict.nlefts); anumrev.setText(String.valueOf(demorevmax)+" possible reverses"); for (int i = 0; i < widsang.length; i++) { if (pict.tangle <= widsang[i]) { maxwid = widsmax[i]; i = widsang.length + 1; } } if (pict.widfact > maxwid) { pict.widfact = maxwid; widfact.setText(String.valueOf(pict.widfact)); } pict.repaint(); repaint(); return true; } if ((redraw) && (fromlist==false)) { pict.nlefts = demorevs[demorevnum]; nlefts.setText(pict.nlefts); anumrev.setText(String.valueOf(demorevmax)+" possible reverses"); pict.repaint(); repaint(); return true; } return false; } public boolean handleEvent(Event evt) { double dvalue; boolean redraw = false; float maxwid = 0.99f; if (evt.target == swidfact) { dvalue = (double)swidfact.getValue() / 100; pict.widfact = (float)dvalue; widfact.setText(String.valueOf(dvalue)); for (int i = 0; i < widsang.length; i++) { if (pict.tangle <= widsang[i]) { maxwid = widsmax[i]; i = widsang.length + 1; } } if (pict.widfact > maxwid) { pict.widfact = maxwid; widfact.setText(String.valueOf(pict.widfact)); } redraw = true; } if (redraw) { pict.repaint(); repaint(); return true; } return super.handleEvent(evt); } public void buildrevs(int maxpos) { int revlist[] = { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; int nlefts; float cdist; int revpos = 1; int curpos = 1; int nrevs = 0; String revstr; demorevmax = 0; demorevs[0] = "0,0,0"; while ((curpos < 2) && (maxpos > 1)) { if (revlist[maxpos] != maxpos) { } nlefts = 0; nrevs = nrevs + 1; revstr = ""; for (int j=1; j < revlist.length; j++) { if (revlist[j] > 0) { if (j > 1) revstr = revstr + ","; revstr = revstr + String.valueOf(revlist[j]); nlefts = nlefts + 1; } } pict.nlefts = revstr; cdist = (pict.testdist()*100); if (((int)cdist == 0) && (nlefts != maxpos)) { demorevmax = demorevmax + 1; demorevs[demorevmax] = revstr; } System.out.println(demorevmax+"/"+revstr+"--"+cdist); curpos = revlist[revpos]; if (curpos < maxpos) { revpos = revpos + 1; revlist[revpos] = curpos + 1; } else { revlist[revpos] = 0; if (revpos > 1) { revpos = revpos - 1; curpos = revlist[revpos]; revlist[revpos] = curpos + 1; } } curpos = revlist[1]; } } public String getAppletInfo() { return "(sprolat6) Spirolateral 2.3 Copyright 2000 Robert J. Krawczyk\n" + "krawczyk@iit.edu"; } } /* -------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------*/