import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class test1 extends Applet { PolyCanvas P; Manager M; public void init() { setBackground(Color.black); M=new Manager(); P=new PolyCanvas(M); P.resize(841,841); P.setBackground(Color.black); add(P); M.P=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); g2.dispose(); offscreen.flush(); } } class PolyData { int diag1,diag2,rotate,number,size,init,state,fudge; double radius; PolyData() {} PolyData select(int n) { PolyData X=new PolyData(); X.size=size; X.radius=radius; X.diag1=1; X.diag2=2; X.state=1; X.number=3*n-4; X.init= 7*n-20; X.rotate=6*n-7; X.fudge= 9*n-12; return(X); } void ratio() { double t1=diag1; double t2=diag2; if(t1>3*number/2) t1=3*number-t1; if(t2>3*number/2) t2=3*number-t2; double t3=0; if(t1>=t2) t3=t1/t2; if(t2>=t1) t3=t2/t1; System.out.println(t3); } } class PolyCanvas extends DBCanvas implements MouseListener, MouseMotionListener { Manager M; PolyVector[] P=new PolyVector[27]; int state,choice; ListenSquare[] S=new ListenSquare[100]; ListenTriangle[] T=new ListenTriangle[4]; PolyData X; int SIZE,lines; double radius; int color; PolyCanvas(Manager M) { this.M=M; state=-1; choice=1; SIZE=400; radius=200; X=new PolyData(); X.size=SIZE; X.radius=radius; X=X.select(3); lines=0; color=1; for(int i=0;i<=8;++i) P[i]=new PolyVector(); addMouseListener(this); addMouseMotionListener(this); SliderSetup(); } public void paint(Graphics g) { SliderRender(g); g.clipRect(22,23,2*X.size-4,2*X.size-5); g.translate(-2*S[1].state+20,-2*S[2].state+20); P[0]=P[0].regular(4,X.init,X.number,X.size,X.size,X.radius); P[4]=P[4].regular(4*X.number,X.fudge,3,X.size,X.size,X.radius); Color C=Color.white; if(color==1) C=Color.blue; if(color==2) C=new Color(0,0,150); if(state==1) { P[1].render(g,C,C); P[1].render2(g,Color.white); P[2]=P[1]; int x1=(int)(P[1].v[1].x); int y1=(int)(P[1].v[1].y); for(int i=1;i<=S[3].state+SIZE/2;++i) { P[2]=P[2].diag(X); int x2=(int)(P[2].v[1].x); int y2=(int)(P[2].v[1].y); if(lines==1) { g.setColor(Color.green.darker()); g.drawLine(x1,y1,x2,y2); } x1=x2;y1=y2; P[2].render2(g,Color.white); } } P[0].structure(g,Color.white,X); P[4].render4(g,Color.red); } void SliderSetup() { S[0]=new ListenSquare(20,20,2*SIZE,2*SIZE); S[1]=new ListenSquare(20,2*SIZE+20,2*SIZE,20); S[1].state=0; S[1].type=1; S[2]=new ListenSquare(0,20,21,2*SIZE); S[2].state=0; S[2].type=2; S[3]=new ListenSquare(2*SIZE+20,SIZE,20,SIZE+20); S[3].state=-SIZE/2+50; S[3].type=2; S[4]=new ListenSquare(0,2*SIZE+20,21,20); S[5]=new ListenSquare(2*SIZE+20,20,20,SIZE); S[6]=new ListenSquare(10,10,10,10); S[7]=new ListenSquare(0,10,10,10); S[8]=new ListenSquare(10,0,10,10); S[9]=new ListenSquare(0,0,10,10); S[10]=new ListenSquare(20,0,2*SIZE,20); for(int j=1;j<=6;++j) S[10+j]=new ListenSquare(2*SIZE+20,10*j-10,20,10); S[20]=new ListenSquare(2*SIZE+20,SIZE-10,10,10); S[21]=new ListenSquare(2*SIZE+30,SIZE-10,10,10); S[22]=new ListenSquare(2*SIZE+20,SIZE-20,10,10); S[23]=new ListenSquare(2*SIZE+30,SIZE-20,10,10); S[24]=new ListenSquare(2*SIZE+20,SIZE,20,20); S[25]=new ListenSquare(2*SIZE+20,2*SIZE+20,10,10); } void SliderRender(Graphics g) { S[10].render(g,new Color(0,0,100),Color.blue); S[1].render(g,new Color(0,0,100),Color.blue,Color.yellow); S[2].render(g,new Color(0,0,100),Color.blue,Color.yellow); S[3].render(g,new Color(0,0,100),Color.blue,Color.white); S[4].render(g,Color.yellow,Color.blue); S[5].render(g,new Color(0,0,100),Color.blue); S[6].render(g,Color.yellow,Color.blue); S[7].render(g,Color.orange,Color.blue); S[8].render(g,Color.orange,Color.blue); S[9].render(g,Color.yellow,Color.blue); S[10].render(g,Color.black,Color.blue); for(int j=1;j<=6;++j) S[10+j].render(g,new Color(180,0,0),Color.blue); S[20].render(g,Color.red,Color.blue); S[21].render(g,Color.yellow,Color.blue); S[22].render(g,Color.red,Color.blue); S[23].render(g,Color.yellow,Color.blue); S[24].render(g,Color.blue,Color.black); S[25].render(g,Color.green,Color.blue); } public void mouseExited(MouseEvent e) {} public void mouseMoved(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mousePressed(MouseEvent e) { e.consume(); Point pp=new Point(); pp.x=e.getX(); pp.y=e.getY(); int test=0; for(int i=0;i<=4;++i) { if(S[i].inside(pp)==1) test=i; } for(int j=20;j<=25;++j) { if(S[j].inside(pp)==1) test=j; } choice=test; } public void mouseDragged(MouseEvent e) { e.consume(); Point Z=new Point(); Point Y=new Point(); Z.x=e.getX(); Z.y=e.getY(); if(choice==0) { state=1; Y.x=Z.x+2*S[1].state-20; Y.y=Z.y+2*S[2].state-20; P[1]=P[0].convert(Y); repaint(); } if(state<2) { if(choice==1) S[1].state=Z.x-X.size-20; if(choice==2) S[2].state=Z.y-X.size-20; if((Z.y<2*SIZE+15)&&(Z.y>SIZE+25)&&(choice==3)) S[3].state=Z.y-3*X.size/2-10; if(choice==4) { S[1].state=0; S[2].state=0; } repaint(); } } public void mouseClicked(MouseEvent e) { e.consume(); Point Z=new Point(); Point Y=new Point(); Z.x=e.getX(); Z.y=e.getY(); if((SIZE>200)&&(S[9].inside(Z)==1)) { SIZE=SIZE-25; X.size=X.size-25; SliderSetup(); state=0; repaint(); } if((SIZE<400)&&(S[6].inside(Z)==1)) { SIZE=SIZE+25; X.size=X.size+25; SliderSetup(); state=0; repaint(); } if((radius>100)&&(S[7].inside(Z)==1)) { radius=radius-10; X.radius=X.radius-10; SliderSetup(); state=0; repaint(); } if((radius<400)&&(S[8].inside(Z)==1)) { radius=radius+10; X.radius=X.radius+10; SliderSetup(); state=0; repaint(); } /****number of points****/ for(int j=1;j<=6;++j) { if(S[10+j].inside(Z)==1) { X=X.select(2*j+1); state=0; repaint(); } } /************************/ if(choice==20) X.diag1=P[0].mod(X.diag1+3,3*X.number); if(choice==21) X.diag2=P[0].mod(X.diag2+3,3*X.number); if(choice==22) X.diag1=P[0].mod(X.diag1-3,3*X.number); if(choice==23) X.diag2=P[0].mod(X.diag2-3,3*X.number); if(choice==24) lines=1-lines; if(choice==25) ++color; if(color==3) color=color-2; if(S[0].inside(Z)==1) { state=1; Y.x=Z.x+2*S[1].state-20; Y.y=Z.y+2*S[2].state-20; P[1]=P[0].convert(Y); repaint(); } if(state<2) { if(S[1].inside(Z)==1) S[1].state=Z.x-X.size-20; if(choice==2) S[2].state=Z.y-X.size-20; if(choice==3) S[3].state=Z.y-3*X.size/2-10; if(S[4].inside(Z)==1) { S[1].state=0; S[2].state=0; } repaint(); } int temp=0; Z.x=Z.x+2*S[1].state; Z.y=Z.y+2*S[2].state; int aa=P[0].select(Z,X); if((aa>0)&&(X.state==1)) { temp=2; X.diag1=aa; repaint(); } if((aa>0)&&(X.state==2)) { temp=1; X.diag2=aa; repaint(); } if(aa>0) X.state=temp; } } class ListenTriangle { double x1,x2,x3; double y1,y2,y3; int state; 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.state=0; } int inside(Point p) { double v1x,v1y,v2x,v2y; double A1,A2,A3; int val; v1x=p.x-this.x1; v1y=p.y-this.y1; v2x=p.x-this.x2; v2y=p.y-this.y2; A3=v1x*v2y-v1y*v2x; v1x=p.x-this.x2; v1y=p.y-this.y2; v2x=p.x-this.x3; v2y=p.y-this.y3; A1=v1x*v2y-v1y*v2x; v1x=p.x-this.x3; v1y=p.y-this.y3; v2x=p.x-this.x1; v2y=p.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); } void render(Graphics g) { g.setColor(this.C); Polygon P=new Polygon(); int x[]={(int)(this.x1),(int)(this.x2),(int)(this.x3)}; int y[]={(int)(this.y1),(int)(this.y2),(int)(this.y3)}; P.xpoints=x; P.ypoints=y; P.npoints=3; if(state==1) g.fillPolygon(P); if(state==0) g.drawPolygon(P); } ListenTriangle reflect(ListenTriangle T,int j) { ListenTriangle S=new ListenTriangle(); Vector[] V=new Vector[4]; V[1]=new Vector(x1,y1,1); V[2]=new Vector(x2,y2,1); V[3]=new Vector(x3,y3,1); V[1]=V[1].reflect(T,j); V[2]=V[2].reflect(T,j); V[3]=V[3].reflect(T,j); S.x1=V[1].x; S.y1=V[1].y; S.x2=V[2].x; S.y2=V[2].y; S.x3=V[3].x; S.y3=V[3].y; S.C=C; S.state=state; return(S); } } class Complex { double x,y; Complex() {} Complex convert(Vector V,PolyData X) { Complex z=new Complex(); z.x=V.x-X.size; z.y=V.y-X.size; z.x=z.x/X.radius; z.y=z.y/X.radius; return(z); } Complex plus(Complex z1,Complex z2) { Complex w= new Complex(); w.x=z1.x+z2.x; w.y=z1.y+z2.y; return(w); } Complex minus(Complex z1,Complex z2) { Complex w= new Complex(); w.x=z1.x-z2.x; w.y=z1.y-z2.y; return(w); } Complex times(Complex z1,Complex z2) { Complex w= new Complex(); w.x=z1.x*z2.x-z1.y*z2.y; w.y=z1.x*z2.y+z1.y*z2.x; return(w); } Complex inverse(Complex z) { Complex w=new Complex(); double d; d=z.x*z.x+z.y*z.y; w.x=z.x/d; w.y=-z.y/d; return(w); } Complex divide(Complex z1,Complex z2) { Complex w= new Complex(); w=w.times(z1,w.inverse(z2)); return(w); } Complex conjugate(Complex z) { Complex w=new Complex(); w.x=x; w.y=-y; return(w); } Vector convert(PolyData X) { Vector W=new Vector(); W.x=X.radius*x+X.size; W.y=X.radius*y+X.size; W.z=1; return(W); } } class Vector { double x,y,z; Vector() { this.x=0; this.y=0; this.z=0; } Vector(double x,double y,double z) { this.x=x; this.y=y; this.z=z; } Vector cross(Vector V,Vector W) { Vector X=new Vector(); X.x=V.y*W.z-V.z*W.y; X.y=V.z*W.x-V.x*W.z; X.z=V.x*W.y-V.y*W.x; return(X); } Vector normalize() { Vector X=this; X.x=x/z; X.y=y/z; X.z=1.0; return(X); } double norm() { double d=0; d=x*x+y*y+z*z; d=Math.sqrt(d); return(d); } Vector unit() { Vector V=new Vector(); double d=this.norm(); V.x=x/d; V.y=y/d; V.z=z/d; return(V); } Vector rotate(double d) { Vector W=new Vector(); W.x=x*Math.cos(d)+y*Math.sin(d); W.y=-x*Math.sin(d)+y*Math.cos(d); W.z=1.0; return(W); } double dot(Vector V,Vector W) { double d=0; d=V.x*W.x+V.y*W.y+V.z*W.z; return(d); } Vector scale(double d) { Vector W=new Vector(); W.x=d*x; W.y=d*y; W.z=d*z; return(W); } Vector scale2(double d) { Vector W=new Vector(); W.x=d*x; W.y=d*y; W.z=1.0; return(W); } Vector add(Vector V,Vector W) { Vector X=new Vector(); X.x=V.x+W.x; X.y=V.y+W.y; X.z=V.z+W.z; return(X); } Vector sub(Vector V,Vector W) { Vector X=new Vector(); X.x=V.x-W.x; X.y=V.y-W.y; X.z=V.z-W.z; return(X); } Vector reflect(Vector W) { Vector X=new Vector(); double d=X.dot(this,W); X=X.sub(this.scale(2*d),W); return(X); } Vector reflect(ListenTriangle T,int j) { Vector[] V=new Vector[10]; Vector W=new Vector(x,y,0); if(j==1) { V[1]=new Vector(T.x1,T.y1,1.0); V[2]=new Vector(T.x2/2+T.x3/2,T.y2/2+T.y3/2.0,1.0); } if(j==2) { V[1]=new Vector(T.x2,T.y2,1.0); V[2]=new Vector(T.x1/2+T.x3/2,T.y1/2+T.y3/2.0,1.0); } if(j==3) { V[1]=new Vector(T.x3,T.y3,1); V[2]=new Vector(T.x2/2+T.x1/2,T.y2/2+T.y1/2.0,1.0); } V[3]=this.sub(V[1],V[2]); V[3]=V[3].unit(); V[4]=this.sub(W,V[2]); V[5]=V[3].reflect(V[4]); V[6]=V[5].add(V[5],V[2]); V[6].z=1; return(V[6]); } Vector reflect(Vector A,Vector B) { Vector[] V=new Vector[10]; V[1]=A; V[2]=B; V[1].z=1; V[2].z=1; V[3]=sub(V[1],V[2]); V[3]=V[3].unit(); V[4]=sub(this,V[2]); V[5]=V[3].reflect(V[4]); V[6]=add(V[5],V[2]); V[6].z=1; return(V[6]); } void print() { System.out.println(x+" "+y+ " " +z); } } class PolyVector { Vector[] v=new Vector[140]; int n; PolyVector() { for(int i=1;i<=138;++i) v[i]=new Vector(); } PolyVector(int n) { for(int i=1;i<=n+1;++i) v[i]=new Vector(); } PolyVector regular(int d,int k,int n,double x,double y,double r) { PolyVector P=new PolyVector(n); P.n=n; for(int i=1;i<=P.n;++i) { P.v[i].x=x+r*Math.cos(2*Math.PI*(d*i+k)/(d*n)); P.v[i].y=y+r*Math.sin(2*Math.PI*(d*i+k)/(d*n)); P.v[i].z=1; } return(P); } void render(Graphics g,Color C1,Color C2) { int[] X=new int[138]; int[] Y=new int[138]; for(int i=0;i<=n-1;++i) { X[i]=(int)(this.v[i+1].x/this.v[i+1].z); Y[i]=(int)(this.v[i+1].y/this.v[i+1].z); } g.setColor(C1); g.fillPolygon(X,Y,n); g.setColor(C2); g.drawPolygon(X,Y,n); } void render(Graphics g,Color C1) { int[] X=new int[138]; int[] Y=new int[138]; for(int i=0;i<=n;++i) { X[i]=(int)(this.v[i+1].x/this.v[i+1].z); Y[i]=(int)(this.v[i+1].y/this.v[i+1].z); } g.setColor(C1); g.drawPolygon(X,Y,n); } void render2(Graphics g,Color C1) { g.setColor(C1); int x=(int)(v[1].x); int y=(int)(v[1].y); g.fillOval(x-1,y-1,2,2); g.drawOval(x-1,y-1,2,2); } void structure(Graphics g,Color C1,PolyData X) { int x=0; int y=0; for(int i=1;i<=n;++i) { x=(int)(v[i].x); y=(int)(v[i].y); g.setColor(Color.black); g.fillOval(x-5,y-5,10,10); g.setColor(C1); g.drawOval(x-5,y-5,10,10); } int aa=X.diag1; int test=mod(X.diag1,3); if(test==2) aa=3*X.number-aa; aa=aa-1; aa=aa/3; aa=mod(aa+3,n); int xx=(int)(v[aa].x); int yy=(int)(v[aa].y); int bb=X.diag2; test=mod(X.diag2,3); if(test==2) bb=3*X.number-bb; bb=bb-1; bb=bb/3; bb=mod(bb+3,n); x=(int)(v[bb].x); y=(int)(v[bb].y); g.setColor(Color.yellow); g.fillOval(x-5,y-5,10,10); g.setColor(Color.black); g.drawOval(x-5,y-5,10,10); g.setColor(Color.red); g.fillOval(xx-5,yy-5,10,10); g.setColor(Color.black); g.drawOval(xx-5,yy-5,10,10); Circle C=new Circle(); Vector V=new Vector(); V.x=X.size; V.y=X.size; V.z=1; C=C.through(v[aa],V,v[bb]); C.render(1,g,Color.yellow); int temp=average(aa,bb); x=(int)(v[temp].x); y=(int)(v[temp].y); xx=(int)(10*X.size-9*x); yy=(int)(10*X.size-9*y); x=(int)(-9*X.size+10*x); y=(int)(-9*X.size+10*y); g.setColor(Color.cyan); g.drawLine(x,y,xx,yy); temp=n-aa-bb-2*mod(X.number-4,n); temp=mod(temp,n); x=(int)(v[temp].x); y=(int)(v[temp].y); xx=(int)(v[aa].x); yy=(int)(v[aa].y); int x2=10*xx-9*x; int y2=10*yy-9*y; int x3=10*x-9*xx; int y3=10*y-9*yy; g.drawLine(x2,y2,x3,y3); if(temp==aa) { g.drawLine(x,y,x-5*y+5*X.size,5*x+y-5*X.size); g.drawLine(x,y,x+5*y-5*X.size,-5*x+y+5*X.size); } xx=(int)(v[bb].x); yy=(int)(v[bb].y); int x4=10*xx-9*x; int y4=10*yy-9*y; int x5=10*x-9*xx; int y5=10*y-9*yy; g.drawLine(x4,y4,x5,y5); if(temp==bb) { g.drawLine(x,y,x-5*y+5*X.size,5*x+y-5*X.size); g.drawLine(x,y,x+5*y-5*X.size,-5*x+y+5*X.size); } Vector Q=farPoint(aa,bb,X); g.setColor(new Color(250,0,100)); int x6=(int)(Q.x)+2*x3-2*x2; int y6=(int)(Q.y)+2*y3-2*y2; int x7=(int)(Q.x)-2*x3+2*x2; int y7=(int)(Q.y)-2*y3+2*y2; g.drawLine(x6,y6,x7,y7); x6=(int)(Q.x)+2*x5-2*x4; y6=(int)(Q.y)+2*y5-2*y4; x7=(int)(Q.x)-2*x5+2*x4; y7=(int)(Q.y)-2*y5+2*y4; g.drawLine(x6,y6,x7,y7); } Vector farPoint(int a,int b,PolyData X) { Complex z=new Complex(); z=z.convert(v[a],X); Complex w=new Complex(); w=w.convert(v[b],X); Complex h=new Complex(); h=h.divide(h.times(z,w),h.plus(z,w)); h.x=2*h.x; h.y=2*h.y; Vector W=h.convert(X); return(W); } void render4(Graphics g,Color C1) { int x=0; int y=0; for(int i=1;i<=n;++i) { x=(int)(v[i].x); y=(int)(v[i].y); g.setColor(Color.black); g.fillOval(x-2,y-2,4,4); g.setColor(C1); g.drawOval(x-2,y-2,4,4); } } int average(int a,int b) { int k=a+b; if(mod(k,2)==1) k=k+n; k=mod(k/2,n); return(k); } Vector opposite(int j) { Vector V=new Vector(); V=V.add(v[mod(j+(n-1)/2,n)],v[mod(j+(n+1)/2,n)]); V=V.scale(.5); return(V); } int select(Point p,PolyData X) { int test=0; Vector V=new Vector(); Vector W=new Vector(); V.x=p.x-20; V.y=p.y-20; V.z=1; for(int i=1;i<=n;++i) { W=V.sub(V,v[i]); if(W.norm()<5) test=i; } if(test>0) test=mod(3*X.number+3*test-8,3*X.number); return(test); } PolyVector convert(Point P) { PolyVector W=new PolyVector(3*n+1); Vector A=new Vector(); Vector B=new Vector(); int k=0; W.v[1].x=P.x; W.v[1].y=P.y; W.v[1].z=1.0; for(int i=1;i<=n;++i) { k=mod(i+2,n); A=v[k]; B=opposite(k); W.v[3*i-1]=v[k]; W.v[3*i-0]=W.v[3*i-2].reflect(A,B); k=mod(i+2+(n+1)/2,n); A=v[k]; B=opposite(k); W.v[3*i+1]=W.v[3*i-0].reflect(A,B); } W.n=3*n; return(W); } int mod(int j,int n) { int k=j-n*(j/n); if(k<=0) k=k+n; return(k); } PolyVector diag(int h) { PolyVector P=new PolyVector(); for(int i=1;i<=n;++i) { P.v[i]=P.v[i].cross(v[mod(i,n)],v[mod(i+h,n)]); P.v[i]=P.v[i].normalize(); } P.n=n; return(P); } PolyVector diag(PolyData X) { PolyVector P=new PolyVector(); P=this.diag(X.diag1); P=P.diag(X.diag2); PolyVector Q=new PolyVector(); int shift=mod((X.diag1+X.diag2)*(3*X.number-1)/2,3*X.number); for(int i=1;i<=n;++i) { Q.v[i]=P.v[mod(i+shift,n)]; } Q.n=n; Q=Q.dilate(X); return(Q); } PolyVector diag2(PolyData Y) { PolyVector P=new PolyVector(); PolyData X=new PolyData(); X.size=Y.size; X.radius=Y.radius; X.diag1=Y.diag1; X.diag2=Y.diag2+3; X.state=Y.state; X.number=Y.number; X.init= Y.init; X.rotate=Y.rotate; X.fudge= Y.fudge; P=this.diag(X.diag1); P=P.diag(X.diag2); PolyVector Q=new PolyVector(); int shift=mod((X.diag1+X.diag2)*(3*X.number-1)/2,3*X.number); for(int i=1;i<=n;++i) { Q.v[i]=P.v[mod(i+shift,n)]; } Q.n=n; Q=Q.dilate(X); return(Q); } PolyVector dilate(PolyData X) { Vector V=new Vector(X.size,X.size,0.0); PolyVector P=new PolyVector(); Vector W=new Vector(); W=W.sub(v[mod(X.rotate,n)],V); double d=X.radius/W.y; for(int i=1;i<=n;++i) { P.v[i]=V.sub(v[i],V); P.v[i]=P.v[i].scale2(d); P.v[i]=P.v[i].add(P.v[i],V); } P.n=n; return(P); } } class Manager { PolyCanvas P; Manager() {} } class ListenSquare { double x1,x2; double y1,y2; int state; int type; Color C; ListenSquare(double x1,double y1,double x2,double y2) { this.x1=x1; this.x2=x2; this.y1=y1; this.y2=y2; this.state=0; this.type=0; } int inside(Point p) { int val; val=1; if(p.x<=this.x1) val=0; if(p.x>this.x1+this.x2) val=0; if(p.y<=this.y1) val=0; if(p.y>this.y1+this.y2) val=0; return(val); } void render(Graphics g,Color C1,Color C2,Color C3) { int xx1,yy1,xx2,yy2; xx1=(int)(this.x1); yy1=(int)(this.y1); xx2=(int)(int)(this.x2); yy2=(int)(int)(this.y2); g.setColor(C1); g.fillRect(xx1,yy1,xx2,yy2); g.setColor(C3); if(type==1) g.fillRect(xx1+xx2/2+state-5,yy1,10,yy2); if(type==2) g.fillRect(xx1,yy1+yy2/2+state-5,xx2,10); if(type==3) g.fillRect(xx1,yy1,xx2/2+state,yy2); g.setColor(C2); g.drawRect(xx1,yy1,xx2,yy2); } void render(Graphics g,Color C1,Color C2) { int xx1,yy1,xx2,yy2; xx1=(int)(this.x1); yy1=(int)(this.y1); xx2=(int)(int)(this.x2); yy2=(int)(int)(this.y2); g.setColor(C1); g.fillRect(xx1,yy1,xx2,yy2); g.setColor(C2); g.drawRect(xx1,yy1,xx2,yy2); } } class Circle { Vector v; double r; Circle() {} void render(int j,Graphics g,Color C) { g.setColor(C); int x=(int)(v.x-r); int y=(int)(v.y-r); if(j==1) g.drawOval(x,y,(int)(2*r),(int)(2*r)); g.drawOval(x,y,(int)(2*r),(int)(2*r)); } Vector center(Vector v1,Vector v2,Vector v3) { Vector V[]=new Vector[14]; V[1]=v1.add(v1,v2); V[1]=V[1].scale(.5); V[2]=v1.add(v3,v2); V[2]=V[2].scale(.5); V[3]=v1.sub(v1,v2); V[3]=V[3].rotate(Math.PI/2.0); V[4]=v1.sub(v3,v2); V[4]=V[4].rotate(Math.PI/2.0); V[5]=V[1].add(V[1],V[3]); V[6]=V[2].add(V[2],V[4]); V[5].z=1; V[6].z=1; V[7]=V[1].cross(V[1],V[5]); V[8]=V[2].cross(V[2],V[6]); V[9]=V[7].cross(V[7],V[8]); V[10]=V[9].normalize(); return(V[10]); } Circle through(Vector v1,Vector v2,Vector v3) { Circle C=new Circle(); C.v=C.center(v1,v2,v3); Vector V=new Vector(); V=V.sub(C.v,v2); C.r=V.norm(); return(C); } }