import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class test1 extends Applet { PlayCanvas P; ViewCanvas V; Canvas X; Canvas T; GridBagLayout game; GridBagConstraints c; int[] PIECE=new int[10]; double[] SIZE=new double[10]; Color[] COLOR=new Color[30]; Color[]VCOLOR=new Color[50]; double[] VSIZE=new double[10]; public void init() { PIECE[0]=2; PIECE[1]=1; PIECE[2]=2; PIECE[3]=5; SIZE[0]=780; SIZE[1]=190; SIZE[2]=0; SIZE[3]=30; VSIZE[0]=110; VSIZE[1]=100; VSIZE[2]=20; VCOLOR[0]=Color.red; VCOLOR[1]=Color.blue; VCOLOR[2]=Color.cyan; VCOLOR[3]=Color.yellow; VCOLOR[10]=Color.black; VCOLOR[11]=new Color(220,220,220); VCOLOR[12]=Color.blue; VCOLOR[13]=new Color(10,70,120); VCOLOR[20]=Color.white; VCOLOR[21]=Color.black; VCOLOR[22]=Color.white; VCOLOR[23]=Color.white; VCOLOR[30]=new Color(80,80,80); VCOLOR[31]=Color.white; VCOLOR[32]=Color.blue.darker(); VCOLOR[33]=new Color(20,90,160); COLOR[0]=Color.blue.brighter(); COLOR[1]=Color.blue.darker(); COLOR[2]=Color.red.brighter(); COLOR[3]=Color.red.darker(); COLOR[4]=Color.green.brighter(); COLOR[5]=Color.green.darker(); COLOR[6]=Color.magenta; COLOR[7]=Color.magenta.darker(); COLOR[8]=Color.cyan; COLOR[9]=Color.cyan.darker(); COLOR[10]=Color.yellow; COLOR[11]=Color.yellow.darker(); COLOR[12]=new Color(100,100,255); COLOR[13]=new Color(100,50,50); game=new GridBagLayout(); c=new GridBagConstraints(); setLayout(game); P=new PlayCanvas(SIZE,PIECE,COLOR); V=new ViewCanvas(VSIZE,VCOLOR,P); X=new Canvas(); X.setSize(10,10); P=P.addView(V); P.setBackground(Color.black); V.setBackground(Color.black); setBackground(Color.blue); add(V); add(X); add(P); } } class DBCanvas extends Canvas { public void update(Graphics g) { Graphics g2; Image offscreen = null; offscreen = createImage(getSize().width, getSize().height); g2 = offscreen.getGraphics(); paint(g2); g.drawImage(offscreen, 0, 0, this); g2.dispose(); offscreen.flush(); } } class PlayCanvas extends DBCanvas implements MouseListener,MouseMotionListener { PolyFlip[] P=new PolyFlip[10]; Complex[] z=new Complex[10]; double SIZE[]; int PIECE[]; Color COLOR[]; int listen; ViewCanvas V; int AXIS; int history; int shadow; PlayCanvas(double[] SIZE,int[] PIECE, Color[] COLOR) { addMouseListener(this); addMouseMotionListener(this); this.SIZE=SIZE; this.PIECE=PIECE; this.COLOR=COLOR; int side=PIECE[PIECE[0]+1]; int i; for(i=1;i<10;++i) { z[i]=new Complex(); z[i]=z[i].ZERO(); } for(i=1;i<=PIECE[0];++i) { P[i]=new PolyFlip(SIZE[2],SIZE[3],PIECE[i],side,z[i],0,0,0,COLOR); } listen=-1; history=-5; shadow=-1; AXIS=0; this.setSize((int)(SIZE[0]),(int)(SIZE[0])); reconfigure(7); } public void paint(Graphics gfx) { Graphics2D g=(Graphics2D) gfx; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int i; int x,y; x=(int)(V.MOVE.x*SIZE[1]/V.SIZE[2]); y=(int)(V.MOVE.y*SIZE[1]/V.SIZE[2]); g.setColor(V.COLOR[20+V.BACK]); g.drawRect(0,0,2*(int)(SIZE[1])-1,2*(int)(SIZE[1])-1); g.translate((int)(SIZE[1]),(int)(SIZE[1])); g.translate(-x,-y); /*markers*/ if((AXIS==0)||(AXIS==2)) P[1].goal_render(g,V.COLOR[30+V.BACK]); if((AXIS==1)||(AXIS==2)) { g.setColor(V.COLOR[20+V.BACK]); g.drawLine(-2000,0,2000,0); g.drawLine(0,-2000,0,2000); } /*****************/ /*pieces*/ if((shadow>-1)&&(V.shadow_option==1)) { for(i=1;i<=PIECE[0];++i) this.P[i].shadow_render(g,shadow,V.COLOR[20+V.BACK]); } for(i=1;i<=PIECE[0];++i) this.P[PIECE[0]+1-i].render(g,V.COLOR[20+V.BACK]); /********/ g.setColor(V.COLOR[20+V.BACK]); g.translate(-(int)(SIZE[1]),-(int)(SIZE[1])); g.translate(x,y); g.drawRect(0,0,2*(int)(SIZE[1])-1,2*(int)(SIZE[1])-1); g.setColor(Color.blue); g.fillRect((int)(2*SIZE[1]),0,(int)(SIZE[0]-2*SIZE[1]),(int)(SIZE[0])); g.fillRect(0,(int)(2*SIZE[1]),(int)(SIZE[0]),(int)(SIZE[0]-2*SIZE[1])); } public void mouseDragged(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseEntered(MouseEvent e) { history=-3;} public void mouseExited(MouseEvent e) { shadow=-1; repaint(0,0,(int)(2*SIZE[1]),(int)(2*SIZE[1])); } public void mouseReleased(MouseEvent e) { shadow=-1; if(listen>-1) repaint(0,0,(int)(2*SIZE[1]),(int)(2*SIZE[1])); } public void mouseClicked(MouseEvent e) { int i; e.consume(); Point p=new Point(); int x=(int)(V.MOVE.x*SIZE[1]/V.SIZE[2]); int y=(int)(V.MOVE.y*SIZE[1]/V.SIZE[2]); p.x=x+e.getX()-(int)(SIZE[1]); p.y=y+e.getY()-(int)(SIZE[1]); this.listen=this.P[1].inside(p); for(i=2;i<=PIECE[0];++i) { if(this.listen==-1) this.listen=this.P[i].inside(p); } p.x=e.getX()-(int)(SIZE[1]); p.y=e.getY()-(int)(SIZE[1]); if((p.x>SIZE[1])||(p.y>SIZE[1])) listen=-1; for(i=1;i<=PIECE[0];++i) this.P[i]=this.P[i].flip(this.listen); if(listen>=0) { repaint(0,0,(int)(2*SIZE[1]),(int)(2*SIZE[1])); V.repaint(2,2,(int)(2*V.SIZE[1]-4),(int)(2*V.SIZE[1]-4)); } } public void mouseMoved(MouseEvent e) { int i; e.consume(); Point p=new Point(); int x=(int)(V.MOVE.x*SIZE[1]/V.SIZE[2]); int y=(int)(V.MOVE.y*SIZE[1]/V.SIZE[2]); p.x=x+e.getX()-(int)(SIZE[1]); p.y=y+e.getY()-(int)(SIZE[1]); if(V.shadow_option==1) { this.listen=this.P[1].inside(p); for(i=2;i<=PIECE[0];++i) { if(this.listen==-1) this.listen=this.P[i].inside(p); } p.x=e.getX()-(int)(SIZE[1]); p.y=e.getY()-(int)(SIZE[1]); if((p.x>SIZE[1])||(p.y>SIZE[1])) listen=-1; if(listen!=history) { shadow=listen; history=listen; repaint(1,1,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } } PlayCanvas addView(ViewCanvas Y) { PlayCanvas X=this; X.V=Y; return(X); } PlayCanvas reconfigure(int side) { PlayCanvas Q=this; if(side==5) { Q.PIECE[0]=2; Q.PIECE[1]=1; Q.PIECE[2]=2; Q.PIECE[3]=5; } if(side==6) { Q.PIECE[0]=1; Q.PIECE[1]=1; Q.PIECE[2]=6; } if(side==7) { Q.PIECE[0]=3; Q.PIECE[1]=1; Q.PIECE[2]=2; Q.PIECE[3]=3; Q.PIECE[4]=7; } if(side==8) { Q.PIECE[0]=2; Q.PIECE[1]=1; Q.PIECE[2]=3; Q.PIECE[3]=8; } if(side==9) { Q.PIECE[0]=3; Q.PIECE[1]=1; Q.PIECE[2]=2; Q.PIECE[3]=4; Q.PIECE[4]=9; } if(side==10) { Q.PIECE[0]=2; Q.PIECE[1]=1; Q.PIECE[2]=3; Q.PIECE[3]=10; } if(side==11) { Q.PIECE[0]=5; Q.PIECE[1]=1; Q.PIECE[2]=2; Q.PIECE[3]=3; Q.PIECE[4]=4; Q.PIECE[5]=5; Q.PIECE[6]=11; } if(side==12) { Q.PIECE[0]=2; Q.PIECE[1]=1; Q.PIECE[2]=5; Q.PIECE[3]=12; } if(side==13) { Q.PIECE[0]=6; Q.PIECE[1]=1; Q.PIECE[2]=2; Q.PIECE[3]=3; Q.PIECE[4]=4; Q.PIECE[5]=5; Q.PIECE[6]=6; Q.PIECE[7]=13; } SIZE[2]=Q.P[1].r1; SIZE[3]=Q.P[1].r2; int i; for(i=1;i<=Q.PIECE[0];++i) { Q.P[i]=new PolyFlip(SIZE[2],SIZE[3],PIECE[i],side,Q.z[i].ZERO(),0,0,0,COLOR); } return(Q); } } class ViewCanvas extends DBCanvas implements MouseListener,MouseMotionListener { double SIZE[]; Color COLOR[]; PlayCanvas P; int listen; int BACK; Point MOVE=new Point(); int words; int history; int shadow_option; String[] S; ViewCanvas(double[] SIZE,Color COLOR[],PlayCanvas P) { this.SIZE=SIZE; this.COLOR=COLOR; this.P=P; addMouseListener(this); addMouseMotionListener(this); this.setSize((int)(2*SIZE[1]+SIZE[1]/5),(int)(P.SIZE[0])); setBackground(Color.black); listen=-1; BACK=0; MOVE.x=0; MOVE.y=0; S=new String[5]; S[1]="Move the cursor over any part of"; S[2]="the control panel and you can read"; S[3]="here how that part functions"; words=1; history=-4; shadow_option=1; } public void paint(Graphics gfx) { Graphics2D g=(Graphics2D) gfx; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int i; int[] s=new int[11]; s[1]=(int)(SIZE[1]); s[2]=(int)(SIZE[1]/5); s[3]=(int)(SIZE[2]); s[4]=(int)(s[2]/2); s[5]=(int)(s[2]/4); g.setColor(Color.blue); g.fillRect(0,2*s[1]+s[2],(int)(P.SIZE[0]),(int)(P.SIZE[0])); /*wordbox*/ g.fillRect(0,2*s[1]+s[2]+5,2*s[1]+s[2]-6,3*s[2]); g.setColor(Color.white); g.setFont(new Font("Helvetica",Font.PLAIN,12)); g.drawString(S[1],15,2*s[1]+s[2]+30); g.drawString(S[2],15,2*s[1]+s[2]+45); g.drawString(S[3],15,2*s[1]+s[2]+60); /**********/ /*title*/ g.setColor(Color.yellow); g.fillRect(0,3*s[1],2*s[1]+s[2]-1,4*s[2]); g.setColor(Color.orange); g.fillRect(0,3*s[1]+2*s[2],2*s[1]+s[2]-1,2*s[2]); g.setColor(Color.black); g.drawRect(0,3*s[1],2*s[1]+s[2]-1,4*s[2]); g.setFont(new Font("Helvetica",Font.PLAIN,25)); g.setColor(Color.black); g.drawString("Lucy and Lily II",10,3*s[1]+30); g.setFont(new Font("Helvetica",Font.PLAIN,12)); g.drawString("c 2000 Rich Schwartz",37,3*s[1]+67); g.drawOval(35,3*s[1]+57,12,12); /**********/ g.setColor(COLOR[20+BACK]); if(P.AXIS!=3) g.drawOval(s[1]-1,s[1]-1,2,2); g.translate((int)(SIZE[1]),(int)(SIZE[1])); g.translate(MOVE.x,MOVE.y); g.setColor(COLOR[BACK]); g.drawRect(-s[3],-s[3],2*s[3],2*s[3]); g.translate(-MOVE.x,-MOVE.y); for(i=1;i<=this.P.PIECE[0];++i) { g.setColor(COLOR[20+BACK]); int x=(int)(P.P[i].c.x*SIZE[2]/P.SIZE[1]); int y=(int)(P.P[i].c.y*SIZE[2]/P.SIZE[1]); if(P.P[i].hide==0) g.drawOval(x-2,y-2,4,4); } g.translate(-(int)(SIZE[1]),-(int)(SIZE[1])); /*buttons*/ g.setColor(Color.cyan.darker()); g.fillRect(0,2*s[1],2*s[1],s[2]); g.setColor(Color.yellow); g.fillRect(2*s[1],0,s[2]-1,2*s[1]); g.setColor(Color.yellow); for(i=0;i<=4;++i) g.fillRect(i*s[2],2*s[1],s[2],s[2]); g.setColor(Color.cyan); for(i=4;i<=3+P.PIECE[0];++i) g.fillRect(i*s[2],2*s[1],s[2],s[2]); g.setColor(Color.black); for(i=0;i<=3+P.PIECE[0];++i) g.drawRect(i*s[2],2*s[1],s[2],s[2]); g.setColor(Color.cyan); g.fillRect(2*s[1],0,s[2],3*s[2]); g.setColor(Color.green.brighter()); g.fillRect(2*s[1],3*s[2],s[2],4*s[2]); g.setColor(Color.yellow); g.fillRect(2*s[1],9*s[2],s[2],2*s[2]); g.setColor(Color.black); for(i=0;i<=10;++i) g.drawRect(2*s[1],i*s[2],s[2],s[2]); g.setColor(COLOR[20+BACK]); g.drawRect(0,0,2*s[1],2*s[1]); g.setColor(Color.black); g.drawRect(0,2*s[1],2*s[1]+s[2],s[2]-1); g.drawRect(2*s[1],0,s[2]-1,2*s[1]+s[2]); /**************/ /*button icons*/ g.setColor(Color.black); for(i=1;i<=P.PIECE[0];++i) { if(P.P[i].hide==0) g.drawOval((3+i)*s[2]+s[4]-2,2*s[1]+s[4]-2,4,4); } /*************/ g.drawOval(s[5],2*s[1]+s[5],s[4],s[4]); /***************/ g.drawLine(s[2]+s[5],2*s[1]+s[5],s[2]+s[5],2*s[1]+s[4]); g.drawLine(s[2]+s[5],2*s[1]+s[5],s[2]+s[4],2*s[1]+s[5]); g.drawLine(s[2]+s[5],2*s[1]+s[5],s[2]+s[4],2*s[1]+s[4]); /*******************/ g.drawLine(2*s[2]+s[4],2*s[1]+s[4],2*s[2]+s[5],2*s[1]+s[4]); g.drawLine(2*s[2]+s[4],2*s[1]+s[4],2*s[2]+s[4],2*s[1]+s[5]); g.drawLine(2*s[2]+s[5],2*s[1]+s[5],2*s[2]+s[4],2*s[1]+s[4]); /********************/ g.drawString("1",4+2*s[1],4*s[3]-s[5]); g.drawString("5",4+2*s[1],4*s[3]-s[5]+s[3]); g.drawString("20",2+2*s[1],4*s[3]-s[5]+2*s[3]); g.drawString("50",2+2*s[1],4*s[3]-s[5]+3*s[3]); g.translate(3*s[2],2*s[1]); g.fillRect(s[5],+s[5]-2,s[4],s[5]+2); g.drawRect(s[5],+s[5]-2,s[4],s[4]+3); g.translate(-3*s[2],-2*s[1]); /****************/ g.drawLine(2*s[1]+s[5],s[4]+2,2*s[1]+s[5]+s[4],s[4]+2); g.drawLine(2*s[1]+s[5],s[4]-2,2*s[1]+s[5]+s[4],s[4]-2); /****************/ g.drawLine(2*s[1]+s[4],s[2]+s[5],2*s[1]+s[4],s[2]+s[4]+s[5]); g.drawLine(2*s[1]+s[5],s[2]+s[4],2*s[1]+s[5]+s[4],s[2]+s[4]); /****************/ g.drawLine(2*s[1]+s[5],2*s[2]+s[4],2*s[1]+s[5]+s[4],2*s[2]+s[4]); /***************/ g.translate(2*s[1],7*s[2]); g.drawLine(s[5],s[4],s[5]+s[4],s[4]); g.drawLine(s[4],s[5],s[4],s[5]+s[4]); g.drawOval(s[4]-2,s[4]-2,4,4); g.translate(-2*s[1],-7*s[2]); g.translate(2*s[1],8*s[2]); g.setColor(COLOR[10+BACK]); g.fillRect(s[5],s[5],s[4],s[4]); g.setColor(Color.black); g.drawRect(s[5],s[5],s[4],s[4]); g.translate(-2*s[1],-8*s[2]); /****************/ g.drawRect(2*s[1]+s[5]-2,-s[2]+2*s[1]+s[5]-2,s[4]+4,s[4]+4); g.drawLine(2*s[1]+s[4],-s[2]+2*s[1]+s[4],2*s[1]+s[4]+s[5]-1,-s[2]+2*s[1]+s[4]+s[5]-1); g.drawLine(2*s[1]+s[4],-s[2]+2*s[1]+s[4],2*s[1]+s[4],-s[2]+2*s[1]+s[4]+s[5]-1); g.drawLine(2*s[1]+s[4],-s[2]+2*s[1]+s[4],2*s[1]+s[4]+s[5]-1,-s[2]+2*s[1]+s[4]); /****************/ g.translate(2*s[1],10*s[2]); g.drawRect(s[5]-2,s[5]-2,s[4]+4,s[4]+4); g.drawLine(s[4],s[4],s[4]+s[5]-1,s[4]+s[5]-1); g.drawLine(s[4],s[4]+s[5]-1,s[4]+s[5]-1,s[4]+s[5]-1); g.drawLine(s[4]+s[5]-1,s[4],+s[4]+s[5]-1,s[4]+s[5]-1); g.translate(-2*s[1],-10*s[2]); } public void mouseDragged(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseClicked(MouseEvent e) { e.consume(); Point p=new Point(); p.x=e.getX(); p.y=e.getY(); int listen=0; int i,sid; sid=P.PIECE[P.PIECE[0]+1]; for(i=0;i<10;++i) { if((p.y>2*SIZE[1])&&(p.x>i*SIZE[1]/5)&&(p.x<=(i+1)*SIZE[1]/5)) listen=i+1; } for(i=0;i<11;++i) { if((p.x>2*SIZE[1])&&(p.y>i*SIZE[1]/5)&&(p.y<=(i+1)*SIZE[1]/5)) listen=i+11; } if(p.y>2.2*SIZE[1]) listen=-1; p.x=e.getX()-(int)(SIZE[1]); p.y=e.getY()-(int)(SIZE[1]); if(listen==0) { MOVE=p; repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1]));} if(listen==1) { for(i=1;i<=P.PIECE[0];++i) P.P[i]=P.P[i].ring(); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); } if(listen==2) { for(i=1;i<=P.PIECE[0];++i) P.P[i]=P.P[i].scale(1.0/0.9); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); } if(listen==3) { for(i=1;i<=P.PIECE[0];++i) P.P[i]=P.P[i].scale(0.9); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } if(listen==4) { int m; int j,k; shadow_option=1-shadow_option; } if((listen>=5)&&(listen<5+P.PIECE[0])) { P.P[listen-4]=P.P[listen-4].hide(); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2.2*SIZE[1]-2)); } if(listen==11) { P=P.reconfigure(sid); MOVE.x=0; MOVE.y=0; repaint(2,2,(int)(2.2*SIZE[1]-2),(int)(2.2*SIZE[1]-2)); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); } if(listen==12) { if(sid<13) { P=P.reconfigure(sid+1); MOVE.x=0; MOVE.y=0; repaint(2,2,(int)(2.2*SIZE[1]-2),(int)(2.2*SIZE[1]-2)); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); } } if(listen==13) { if(sid>5) { P=P.reconfigure(sid-1); MOVE.x=0; MOVE.y=0; repaint(2,2,(int)(2.2*SIZE[1]-2),(int)(2.2*SIZE[1]-2)); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); } } if(listen==14) { int m; int j,k; for(k=1;k<=1;++k) { m=P.P[1].random_integer(); for(j=1;j<=P.PIECE[0];++j) P.P[j]=P.P[j].flip(m); P.repaint(0,0,(int)(2*P.SIZE[1]+21),(int)(2*P.SIZE[1]+21)); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } if(listen==15) { int m; int j,k; for(k=1;k<=5;++k) { m=P.P[1].random_integer(); for(j=1;j<=P.PIECE[0];++j) P.P[j]=P.P[j].flip(m); P.repaint(0,0,(int)(2*P.SIZE[1]+21),(int)(2*P.SIZE[1]+21)); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } if(listen==16) { int m; int j,k; for(k=1;k<=20;++k) { m=P.P[1].random_integer(); for(j=1;j<=P.PIECE[0];++j) P.P[j]=P.P[j].flip(m); P.repaint(0,0,(int)(2*P.SIZE[1]+21),(int)(2*P.SIZE[1]+21)); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } if(listen==17) { int m; int j,k; for(k=1;k<=50;++k) { m=P.P[1].random_integer(); for(j=1;j<=P.PIECE[0];++j) P.P[j]=P.P[j].flip(m); P.repaint(0,0,(int)(2*P.SIZE[1]+21),(int)(2*P.SIZE[1]+21)); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } if(listen==18) { P.AXIS=P.AXIS+1; if(P.AXIS==4) P.AXIS=0; P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } if(listen==19) { ++BACK; if(BACK==4)BACK=0; setBackground(COLOR[10+BACK]); P.setBackground(COLOR[10+BACK]); P.repaint(0,0,(int)(2*P.SIZE[1]),(int)(2*P.SIZE[1])); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } if(listen==20) { if(P.SIZE[1]>SIZE[1]+11) { P.SIZE[1]=P.SIZE[1]-20; P.repaint(0,0,(int)(2*P.SIZE[1]+41),(int)(2*P.SIZE[1]+41)); repaint(2,2,(int)(2*SIZE[1]-2),(int)(2*SIZE[1]-2)); } } if(listen==21) { if(P.SIZE[1]=2*SIZE[1])&&(p.x>=i*SIZE[1]/5)&&(p.x<=(i+1)*SIZE[1]/5)) listen=i+1; } for(i=0;i<11;++i) { if((p.x>=2*SIZE[1])&&(p.y>=i*SIZE[1]/5)&&(p.y<=(i+1)*SIZE[1]/5)) listen=i+11; } if(p.y>2.2*SIZE[1]) listen=-1; if((listen==-1)&&(history!=listen)) { S[1]="Move the cursor over any part of"; S[2]="the control panel and you can read"; S[3]="here how that part functions"; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==0)&&(history!=listen)) { S[1]="Viewport: records in miniature"; S[2]="the positions of the polygons."; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==1)&&(history!=listen)) { S[1]=""; S[2]="changes polygon style"; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==2)&&(history!=listen)) { S[1]=""; S[2]="enlarges polygons"; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==3)&&(history!=listen)) { S[1]=""; S[2]="shrinks polygons"; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==4)&&(history!=listen)) { S[1]=""; S[2]="turns shadow option on/off"; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen>=5)&&(listen<=10)&&(history!=listen)) { if(P.PIECE[0]>listen-5) { S[1]="hide or uncover the polygon"; S[2]="bound to this button"; S[3]=""; } if(P.PIECE[0]<=listen-5) { S[1]=""; S[2]="no function"; S[3]=""; } repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==11)&&(history!=listen)) { S[1]="reset game"; S[2]=""; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==12)&&(history!=listen)) { S[1]="reset game and increase number"; S[2]="of sides of the polygons."; S[3]="maximum is 13."; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==13)&&(history!=listen)) { S[1]="reset game and decrease number"; S[2]="of sides of the polygons."; S[3]="minimum is 5."; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==14)&&(history!=listen)) { S[1]="Make 1 random move."; S[2]="Start a new game by clicking"; S[3]="this button."; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==15)&&(history!=listen)) { S[1]="Make 5 random moves."; S[2]="Start a new game by clicking"; S[3]="this button.";history=listen; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); } if((listen==16)&&(history!=listen)) { S[1]="Make 20 random moves."; S[2]="Start a new game by clicking"; S[3]="this button.";history=listen; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); } if((listen==17)&&(history!=listen)) { S[1]="Make 50 random moves."; S[2]="Start a new game by clicking"; S[3]="this button.";history=listen; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); } if((listen==18)&&(history!=listen)) { S[1]="Turns coordinate axes and"; S[2]="origin marker on and off."; S[3]="Cycles through 4 options."; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==19)&&(history!=listen)) { S[1]=""; S[2]="change background color"; S[3]=""; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); history=listen; } if((listen==20)&&(history!=listen)) { S[1]=""; S[2]="shrink playing board"; S[3]="";history=listen; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); } if((listen==21)&&(history!=listen)) { S[1]=""; S[2]="enlarge playing board"; S[3]="";history=listen; repaint(6,(int)(2.2*SIZE[1]+7),(int)(2.2*SIZE[1]+6),(int)(3*SIZE[1]/5-1)); } } } } class ListenTriangle { Polygon P; ListenTriangle(Polygon P) { this.P=P; } int inside(Point p) { int x1,x2,x3,y1,y2,y3; int v1x,v1y,v2x,v2y; int A1,A2,A3; int value; Polygon Q; Q=this.P; x1=Q.xpoints[0]; x2=Q.xpoints[1]; x3=Q.xpoints[2]; y1=Q.ypoints[0]; y2=Q.ypoints[1]; y3=Q.ypoints[2]; v1x=p.x-x1; v1y=p.y-y1; v2x=p.x-x2; v2y=p.y-y2; A3=v1x*v2y-v1y*v2x; v1x=p.x-x2; v1y=p.y-y2; v2x=p.x-x3; v2y=p.y-y3; A1=v1x*v2y-v1y*v2x; v1x=p.x-x3; v1y=p.y-y3; v2x=p.x-x1; v2y=p.y-y1; A2=v1x*v2y-v1y*v2x; value=0; if((A1<0)&&(A2<0)&&(A3<0)) value=1; if((A1>0)&&(A2>0)&&(A3>0)) value=1; return(value); } } class Complex { double x,y; Complex() { this.x=x; this.y=y; } Complex ZERO() { Complex z=new Complex(); z.x=0.0; z.y=0.0; return(z); } } class PolyFlip { Color[] C; Complex c; double r1,r2; int mode; int hide; int angle; int k,n; PolyFlip(double r1,double r2,int k,int n,Complex c,int hide,int mode,int angle,Color[] C) { this.k=k; this.n=n; this.r1=r1; this.r2=r2; this.c=c; this.mode=mode; this.hide=hide; this.angle=angle; this.C=C; hide=0; } void render(Graphics g,Color C) { double x1,x2,x3,y1,y2,y3,x4,y4,x5,y5; int i,m; double ii,nn; Polygon P=new Polygon(); for(i=0;i-1) { if(this.mode==0) { ii=i*this.k; nn=this.n; x=this.r2*Math.cos(2.0*Math.PI*(this.angle+ii)/nn); y=this.r2*Math.sin(2.0*Math.PI*(this.angle+ii)/nn); len=2*Math.cos(Math.PI/nn); Q.c.x=Q.c.x+len*x; Q.c.y=Q.c.y-len*y; Q.angle=this.angle+2*this.k*i; } if(this.mode==1) { ii=-i*this.k; nn=this.n; x=this.r2*Math.cos(2.0*Math.PI*(this.angle+ii)/nn); y=this.r2*Math.sin(2.0*Math.PI*(this.angle+ii)/nn); len=2*Math.cos(Math.PI/nn); Q.c.x=Q.c.x-len*x; Q.c.y=Q.c.y+len*y; Q.angle=-2*this.k*i+this.angle; } Q.mode=1-this.mode; } return(Q); } PolyFlip scale(double d) { PolyFlip Q=this; Q.c.x=d*Q.c.x; Q.c.y=d*Q.c.y; Q.r1=d*Q.r1; Q.r2=d*Q.r2; return(Q); } PolyFlip ring() { PolyFlip Q=this; Q.r1=Q.r1+.25*Q.r2; if(Q.r1>.9*Q.r2) Q.r1=0; return(Q); } int random_integer() { double ran,ii,nn; int tn=this.n; int i; int m; m=tn-1; ran=Math.random(); ran=ran-Math.floor(ran); for(i=1;i