import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class test1 extends Applet { AllCanvas P; public void init() { setBackground(Color.black); P=new AllCanvas(); P.resize(1180,960); P.setBackground(Color.black); this.add(P); } } class DBCanvas extends Canvas { public void update(Graphics g) { Graphics g2; Image offscreen = null; offscreen = createImage(size().width, size().height); g2 = offscreen.getGraphics(); paint(g2); g.drawImage(offscreen, 0, 0, this); offscreen.flush(); } } class AllCanvas extends DBCanvas implements MouseListener, MouseMotionListener { int w1,w2,w3,w4; int SIZE; int near; ViewInteger v1,v2,v3; ListenSquare L[]=new ListenSquare[10]; MarkedBox[] M=new MarkedBox[2200]; int box; int color; AllCanvas() { addMouseListener(this); addMouseMotionListener(this); w1=7; w2=w1; w3=1; w4=0; SIZE=340; color=1; box=3; for(int i=0;i<=2199;++i) M[i]=new MarkedBox(); M[1].t1.x=0; M[1].t1.y=0; M[1].t1.z=1; M[1].t2.x=.45; M[1].t2.y=0; M[1].t2.z=1; M[1].t3.x=1; M[1].t3.y=0; M[1].t3.z=1; M[1].b1.x=0; M[1].b1.y=1; M[1].b1.z=1; M[1].b2.x=.55; M[1].b2.y=1; M[1].b2.z=1; M[1].b3.x=1; M[1].b3.y=1; M[1].b3.z=1; M[1].live=0; M[1].level=0; M[1].t=2; M[1].b=3; M[2]=M[1].top(); M[3]=M[1].bot(); M[2].live=1; M[3].live=1; M[2].level=1; M[3].level=1; L[1]=new ListenSquare(10,35,15,15,Color.blue,"",1); L[2]=new ListenSquare(10,55,15,15,Color.blue,"",2); L[3]=new ListenSquare(10,75,15,15,Color.blue,"",3); L[4]=new ListenSquare(10,95,15,15,Color.blue,"",4); L[5]=new ListenSquare(10,115,15,15,Color.blue,"",5); L[6]=new ListenSquare(10,135,15,15,Color.blue,"",6); L[7]=new ListenSquare(10,155,15,15,Color.blue,"",7); L[8]=new ListenSquare(10,175,15,15,Color.blue,"",8); v1=new ViewInteger(w1); v2=new ViewInteger(w2); } public void paint(Graphics gfx) { Graphics2D g=(Graphics2D) gfx; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.red); g.setFont(new Font("TimesRoman",Font.PLAIN,28)); g.drawString("Rich: Applet 33",5,25); g.setFont(new Font("TimesRoman",Font.PLAIN,12)); g.setColor(Color.red); g.setColor(Color.white); g.drawString("symmetric position",30,50); g.drawString("refine",30,70); g.drawString("color scheme",30,90); g.drawString("reset",30,110); g.drawString("decrease size",30,130); g.drawString("increase size",30,150); g.drawString("1. Click on the quadrilaterals to ",10,200); g.drawString("subdivide them, according to a",10,220); g.drawString("rule derived from Pappus' theorem",10,240); g.drawString("or, use the refine button",10,260); g.drawString("2. Click above or below the square",10,280); g.drawString("to move the control points.",10,300); g.drawString("Alternately, drag the little white",10,320); g.drawString("line segments with the mouse",10,340); g.drawString("3. To see a cool picture right away",10,360); g.drawString("Click the refine button about 10",10,380); g.drawString("times and then choose the all blue",10,400); g.drawString("Color scheme.",10,420); g.drawString("4. To learn more about this applet",10,440); g.drawString("check out my paper called Pappus'",10,460); g.drawString("Theorem and the Modular Group",10,480); for(int i=1;i<=6;++i) L[i].render(g); g.translate(230,50); g.drawLine((int)(SIZE*M[1].t2.x),-20,(int)(SIZE*M[1].t2.x),0); g.drawLine((int)(SIZE*M[1].b2.x),SIZE+20,(int)(SIZE*M[1].b2.x),SIZE); for(int i=1;i<=box;++i) M[i].render(g,SIZE,color); } void recompute(double x,double y) { M[1].t2.x=x; M[1].b2.x=y; MarkedBox Wt=new MarkedBox(); MarkedBox Wb=new MarkedBox(); for(int i=1;i<=box;++i) { Wt=M[i].top(); Wb=M[i].bot(); M[M[i].t]=M[M[i].t].absorb(Wt); M[M[i].b]=M[M[i].b].absorb(Wb); } } void refine() { int count=box; for(int test=1;test<=box;++test) { if(M[test].live==1) { M[test].live=0; M[count+1]=M[test].top(); M[count+2]=M[test].bot(); M[count+1].live=1; M[count+2].live=1; M[test].t=count+1; M[test].b=count+2; M[count+1].level=M[test].level+1; M[count+2].level=M[test].level+1; count=count+2; } } box=count; } void reset() { box=3; M[2].live=1; M[3].live=1; } public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseClicked(MouseEvent e) { e.consume(); Point p=new Point(); p.x=e.getX(); p.y=e.getY(); int test=0; for(int i=1;i<=6;++i) { if(L[i].inside(p)==1) test=i; } if(test==1) recompute(.5,.5); if((box<1024)&&(test==2)) {refine();repaint();} int temp=0; if((test==3)&&(color<5)) {temp=color+1;} if((test==3)&&(color==5)) {temp=1;} if(test==3) {color=temp;repaint();} if(test==4) {reset();repaint();} if((test==5)&&(SIZE>180)) SIZE=SIZE-20; if((test==6)&&(SIZE<800)) SIZE=SIZE+20; if(test>0) repaint(); double x,y; x=p.x-230; y=p.y-50; x=x/SIZE; y=y/SIZE; if((p.x>230)&&(p.x<230+SIZE)&&(p.y>30)&&(p.y<50)) { recompute(x,M[1].b2.x); repaint(); } if((p.x>230)&&(p.x<230+SIZE)&&(p.y>SIZE+50)&&(p.y0)) { M[test].live=0; M[box+1]=M[test].top(); M[box+2]=M[test].bot(); M[box+1].live=1; M[box+2].live=1; M[test].t=box+1; M[test].b=box+2; M[box+1].level=M[test].level+1; M[box+2].level=M[test].level+1; box=box+2; repaint(); } } public void mouseMoved(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { e.consume(); Point p=new Point(); p.x=e.getX(); p.y=e.getY(); double x,y; x=p.x-230; y=p.y-50; x=x/SIZE; y=y/SIZE; if((p.x>230)&&(p.x<230+SIZE)&&(p.y>30)&&(p.y<50)) { recompute(x,M[1].b2.x); repaint(); } if((p.x>230)&&(p.x<230+SIZE)&&(p.y>SIZE+50)&&(p.y255) temp=255; g.setColor(new Color(0,0,temp)); } if(choice==5) { int temp=50+20*level; if(temp>255) temp=255; g.setColor(new Color(temp,0,0)); } if(choice==2) { g.setColor(Color.black); } int[] x={(int)(SIZE*t1.x/t1.z), (int)(SIZE*t3.x/t3.z), (int)(SIZE*b3.x/b3.z), (int)(SIZE*b1.x/b1.z)}; int[] y={(int)(SIZE*t1.y/t1.z), (int)(SIZE*t3.y/t3.z), (int)(SIZE*b3.y/b3.z), (int)(SIZE*b1.y/b1.z)}; if(choice!=2) { g.fillPolygon(x,y,4); g.drawPolygon(x,y,4); } if(choice==1) { if(live==0) g.setColor(Color.red); if(live==1) g.setColor(Color.blue.darker()); } if(choice==2) { g.setColor(Color.white); } if(choice<=2) { x1=(int)(SIZE*t1.x/t1.z); y1=(int)(SIZE*t1.y/t1.z); x2=(int)(SIZE*b3.x/b3.z); y2=(int)(SIZE*b3.y/b3.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t1.x/t1.z); y1=(int)(SIZE*t1.y/t1.z); x2=(int)(SIZE*b2.x/b2.z); y2=(int)(SIZE*b2.y/b2.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t2.x/t2.z); y1=(int)(SIZE*t2.y/t2.z); x2=(int)(SIZE*b3.x/b3.z); y2=(int)(SIZE*b3.y/b3.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t2.x/t2.z); y1=(int)(SIZE*t2.y/t2.z); x2=(int)(SIZE*b1.x/b1.z); y2=(int)(SIZE*b1.y/b1.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t3.x/t3.z); y1=(int)(SIZE*t3.y/t3.z); x2=(int)(SIZE*b2.x/b2.z); y2=(int)(SIZE*b2.y/b2.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t3.x/t3.z); y1=(int)(SIZE*t3.y/t3.z); x2=(int)(SIZE*b1.x/b1.z); y2=(int)(SIZE*b1.y/b1.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*t3.x/t3.z); y1=(int)(SIZE*t3.y/t3.z); x2=(int)(SIZE*t1.x/t1.z); y2=(int)(SIZE*t1.y/t1.z); g.drawLine(x1,y1,x2,y2); x1=(int)(SIZE*b3.x/b3.z); y1=(int)(SIZE*b3.y/b3.z); x2=(int)(SIZE*b1.x/b1.z); y2=(int)(SIZE*b1.y/b1.z); g.drawLine(x1,y1,x2,y2); v1=new Vector(); v2=new Vector(); v1=v1.cross(v1.cross(t1,b2),v1.cross(t2,b1)); v2=v2.cross(v2.cross(t3,b2),v2.cross(t2,b3)); x1=(int)(SIZE*v1.x/v1.z); y1=(int)(SIZE*v1.y/v1.z); x2=(int)(SIZE*v2.x/v2.z); y2=(int)(SIZE*v2.y/v2.z); g.drawLine(x1,y1,x2,y2); } } MarkedBox top() { MarkedBox t=new MarkedBox(); t.t1=t1; t.t2=t2; t.t3=t3; t.b1=t2.cross(t2.cross(t1,b2),t2.cross(t2,b1)); t.b2=t2.cross(t2.cross(t1,b3),t2.cross(t3,b1)); t.b3=t2.cross(t2.cross(t2,b3),t2.cross(t3,b2)); t.b1=t.b1.normalize(); t.b2=t.b2.normalize(); t.b3=t.b3.normalize(); t.live=live; return(t); } MarkedBox bot() { MarkedBox b=new MarkedBox(); b.b1=b1; b.b2=b2; b.b3=b3; b.t1=t2.cross(t2.cross(t1,b2),t2.cross(t2,b1)); b.t2=t2.cross(t2.cross(t1,b3),t2.cross(t3,b1)); b.t3=t2.cross(t2.cross(t2,b3),t2.cross(t3,b2)); b.t1=b.t1.normalize(); b.t2=b.t2.normalize(); b.t3=b.t3.normalize(); b.live=live; return(b); } MarkedBox absorb(MarkedBox B) { MarkedBox K=this; K.t1=B.t1; K.t2=B.t2; K.t3=B.t3; K.b1=B.b1; K.b2=B.b2; K.b3=B.b3; return(K); } int inside(double x,double y) { ListenTriangle T1,T2; T1=new ListenTriangle(); T2=new ListenTriangle(); T1.x1=t1.x/t1.z; T1.y1=t1.y/t1.z; T1.x2=t3.x/t3.z; T1.y2=t3.y/t3.z; T1.x3=b1.x/b1.z; T1.y3=b1.y/b1.z; T2.x1=b3.x/b3.z; T2.y1=b3.y/b3.z; T2.x2=t3.x/t3.z; T2.y2=t3.y/t3.z; T2.x3=b1.x/b1.z; T2.y3=b1.y/b1.z; int test=0; test=T1.inside(x,y)+T2.inside(x,y); if(test>0) test=1; return(test); } } class ListenSquare { int x,y,w,h; Color C; String S; int v; ListenSquare(int x,int y,int w,int h,Color C,String S,int v) { this.x=x; this.y=y; this.h=h; this.w=w; this.C=C; this.S=S; this.v=v; } void render(Graphics g) { g.setColor(C); g.drawRect(x,y,w,h); g.setColor(Color.white); g.setFont(new Font("TimesRoman",Font.PLAIN,13)); g.drawString(S,x+5,y+13); } int inside(Point p) { int test=0; if((p.x>x)&&(p.xy)&&(p.y0) { int z=y-10*(y/10); g.setColor(C); char ch=(char)(z+48); Character CH1=new Character(ch); g.drawString(CH1.toString(),u-place,v); place=place+8; y=(y-z)/10; } if(x==0) g.drawString("0",u,v); } } class ListenTriangle { double x1,x2,x3; double y1,y2,y3; int dead; Color C; ListenTriangle() { this.x1=x1; this.x2=x2; this.x3=x3; this.y1=y1; this.y2=y2; this.y3=y3; this.C=C; this.dead=dead; } int inside(double x,double y) { double v1x,v1y,v2x,v2y; double A1,A2,A3; int val; v1x=x-this.x1; v1y=y-this.y1; v2x=x-this.x2; v2y=y-this.y2; A3=v1x*v2y-v1y*v2x; v1x=x-this.x2; v1y=y-this.y2; v2x=x-this.x3; v2y=y-this.y3; A1=v1x*v2y-v1y*v2x; v1x=x-this.x3; v1y=y-this.y3; v2x=x-this.x1; v2y=y-this.y1; A2=v1x*v2y-v1y*v2x; val=0; if((A1<0)&&(A2<0)&&(A3<0)) val=1; if((A1>0)&&(A2>0)&&(A3>0)) val=1; return(val); } }