//spiral3.java // a real memory hog, spins a 3 ring spiral //ababian //to do: //compressed frames (?)-probably won't do import java.awt.*; import java.awt.image.*; import java.applet.*; public class spiral3 extends Applet implements Runnable {//display spiral figure /*display diagram of 3 rings (one circle, two rings) of spirals alternating direction formula for spiral in polar coords,: th=a*r+b */ //command-line parameters: //spiralconstant=20, how windy the spiral gets int numarms=5; //number of spiral arms int numframes=5; // number of frames to store int frametime=100; // how long per frame, interacts with numframes to give rotation speed double delr=.2; // (increment for radius in plotting) smaller is slower startup /better graphics double ringoffset=0; //angle offset between rings Color color1=new Color(255,255,255); //background color (white) input from command line as hex, Color color2=new Color(0,0,0); //spiral color, black default //other variables static double pi2=java.lang.Math.PI*2; double delth; //( angle width of arm ) int rmax; // maximum radius double a; //spiral multiplier global Dimension size; int cur=0; //current frame buffer Image frames[]; Thread cotton; boolean frozen=false; public void init() { int ac; String s; size=size(); if ((s = getParameter("numframes")) != null) numframes= Integer.parseInt(s); //else numframes=10; if ((s = getParameter("numarms")) != null) numarms= Integer.parseInt(s); //else numarms=5; if ((s = getParameter("spiralconstant")) != null) ac= Integer.parseInt(s); else ac=20; if ((s = getParameter("frametime")) != null) frametime= Integer.parseInt(s); //else frametime=10; if ((s = getParameter("color1")) != null) try { color1= new Color(Integer.parseInt(s,16)); } catch (Exception e) { System.out.println("error with param color1 "+e); color1=new Color(255,255,255);} //background color, white default //else color1=new Color(255,255,255); if ((s = getParameter("color2")) != null) try { color2= new Color(Integer.parseInt(s,16)); } catch (Exception e) { System.out.println("error with param color2 "+e); color1=new Color(0,0,0);} //foreground color, black default //else color2=new Color(0,0,0); if ((s = getParameter("delr")) != null) try {delr= (new Double(s)).doubleValue();} catch (Exception e) { System.out.println("error with param delr "+e); delr=1.0;} setBackground(color1); setForeground(color2); rmax=java.lang.Math.min(size.width,size.height)/2-1; // maximum radius a=(ac/10)*pi2/rmax; //spiral multiplier global (r=rmax, th=2*pi, th=a*r, a=th/r=6pi/rmax delth=pi2/numarms; //( angle width of 2 arms (black and white)), =pi/numarms ringoffset=2*a*(rmax/3); frames=new Image[numframes]; cur=0; for (int i=0;ir1;r-=delr) { //down other side of spiral arm th=a*r+newb; paul.addPoint(xfrompolar(r,th),yfrompolar(r,th));} g.fillPolygon(paul);} public int xfrompolar(double r,double th){ // xcoord from polar return (int) java.lang.Math.round(r*java.lang.Math.cos(th))+rmax+1;} public int yfrompolar(double r,double th){ // xcoord from polar return (int) java.lang.Math.round(r*java.lang.Math.sin(th))+rmax+1;} }