import java.awt.*; import java.applet.*; import java.util.Vector; import java.util.Stack; import java.lang.Integer; public class DrawIFS extends Applet { public byte newStage; public byte currentStage; public final byte DRAWPOLY = 0; public final byte INIT = 1; public final byte DRAWIFS = 2; DrawIFS difs; DrawPolyPanel dpp; DrawControlsE1 dcE1; DrawControlsS1 dcS1; SouthPanel sp; DrawInitPanel dip; DrawControlsE2 dcE2; DrawControlsS2 dcS2; DrawControlsS3 dcS3; DrawPanel dp; RedrawControls rdc; BorderLayout b; public void init() { newStage = DRAWPOLY; currentStage = 3; DrawIFS difs = new DrawIFS(); dpp = new DrawPolyPanel(this); rdc = new RedrawControls(this); dcS1 = new DrawControlsS1(dpp,this,rdc); dcE1 = new DrawControlsE1(dpp,dcS1,this); dip = new DrawInitPanel(); dcS2 = new DrawControlsS2(dip,this,dpp); dcE2 = new DrawControlsE2(dip,this); dp = new DrawPanel(dcE2, dip, dcS2,this); dcS3 = new DrawControlsS3(this,dp); sp = new SouthPanel(this); b = new BorderLayout(); setLayout(b); resetLayout(); } public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { System.exit(0); return true; } else return super.handleEvent(e); } public void resetLayout() { if ( currentStage == DRAWPOLY ) { remove(dpp); remove(dcE1); remove(dcS1); add( "East", dcE2 ); add( "South", sp ); } if ( currentStage == INIT ) { remove(dip); } if ( currentStage == DRAWIFS ) { remove(dp); sp.remove( dcS3 ); sp.add( "Center", dcS2 ); } if ( newStage == DRAWPOLY ) { remove(dcE2); remove( sp ); add( "East", dcE1 ); add( "Center", dpp ); add("South", dcS1 ); dcE1.show(); dcS1.show(); dpp.show(); (dpp.getParent()).validate(); setCurrentStage(DRAWPOLY); } if ( newStage == INIT ) { add( "Center", dip ); dip.clearRect(); sp.show(); dcE2.show(); dcS2.show(); dip.show(); (dip.getParent()).validate(); setCurrentStage(INIT); } if ( newStage == DRAWIFS ) { sp.remove( dcS2 ); sp.add( "Center", dcS3 ); add( "Center", dp ); dcS3.show(); dp.show(); (dp.getParent()).validate(); setCurrentStage(DRAWIFS); } } public void setNewStage( byte stage ) { switch (stage) { case DRAWPOLY: case INIT: case DRAWIFS: this.newStage = stage; break; default: throw new IllegalArgumentException(); } } public void setCurrentStage( byte stage ) { switch (stage) { case DRAWPOLY: case INIT: case DRAWIFS: this.currentStage = stage; break; default: throw new IllegalArgumentException(); } } public void initBigPoly() { if (( dcE1.sbe.getValue() >= 124 )&&( dcS1.sbs.getValue() <= 1 )) { dcE1.le.setText("0"); dcS1.ls1.setText("0"); dpp.polyDrawn[0] = dpp.OFF; for ( int i = 0 ; i < 2 ; i++ ) { for ( int j = 0 ; j < 5 ; j++ ) { dpp.poly[0][i][j] = 0; dpp.elPoly[0][0][i][j] = 0; dpp.elPoly[1][0][i][j] = 0; } } dpp.repaint(); } } public static void main(String args[]) { Frame f = new Frame("DrawIFS"); DrawIFS drawIFS = new DrawIFS(); drawIFS.init(); drawIFS.start(); f.add("Center", drawIFS); f.resize(400, 430); f.show(); } } class DrawControlsS1 extends Panel { Label ls1; Scrollbar sbs; DrawPolyPanel dpp; DrawIFS difs; RedrawControls rdc; public DrawControlsS1( DrawPolyPanel dpp, DrawIFS difs, RedrawControls rdc ) { this.dpp = dpp; this.difs = difs; this.rdc = rdc; setBackground(Color.white); setLayout(new BorderLayout()); sbs = new Scrollbar( Scrollbar.HORIZONTAL ); sbs.setValues( 0, 0, 0, 200 ); ls1 = new Label( "now 1 " , 1 ); add("South", sbs ); add("West", ls1 ); add("East", new Button("Initialize")); add("Center", rdc ); } public boolean handleEvent(Event evt) { if (( evt.id == Event.SCROLL_ABSOLUTE || evt.id == Event.SCROLL_LINE_DOWN || evt.id == Event.SCROLL_LINE_UP || evt.id == Event.SCROLL_PAGE_DOWN || evt.id == Event.SCROLL_PAGE_UP )&&( evt.target == sbs )) { ls1.setText( String.valueOf(sbs.getValue()) ); difs.dcE1.le.setText( String.valueOf(125 - difs.dcE1.sbe.getValue())); dpp.setPoly( (byte)1, (sbs.getValue())); if ( sbs.getValue() <= 1 ) { difs.initBigPoly(); } else dpp.polyDrawn[0] = dpp.ON; dpp.repaint(); return true; } else return super.handleEvent ( evt ); } public boolean action( Event e, Object arg ) { if ( arg.equals("Initialize")) { difs.setNewStage(difs.INIT); difs.sp.ls2.setText ("Chose the number of iterations, an initial rectangle and a fractal"); difs.resetLayout(); return true; } return super.action( e, arg ); } } class DrawControlsE1 extends Panel { Label le; Scrollbar sbe; DrawPolyPanel dpp; DrawControlsS1 dcS1; DrawIFS difs; public DrawControlsE1(DrawPolyPanel dpp,DrawControlsS1 dcS1, DrawIFS difs) { this.dpp = dpp; this.dcS1 = dcS1; this.difs = difs; setBackground(Color.white); setLayout(new BorderLayout()); sbe = new Scrollbar( Scrollbar.VERTICAL ); sbe.setValues( 125, 0, 0, 125 ); le = new Label( "next 2" , 1 ); add("East", sbe ); add("North", le ); add("South", new Button("Redraw")); } public boolean handleEvent(Event evt) { if (( evt.id == Event.SCROLL_ABSOLUTE || evt.id == Event.SCROLL_LINE_DOWN || evt.id == Event.SCROLL_LINE_UP || evt.id == Event.SCROLL_PAGE_DOWN || evt.id == Event.SCROLL_PAGE_UP )&&( evt.target == sbe )) { le.setText( String.valueOf(125 - sbe.getValue())); dcS1.ls1.setText( String.valueOf(dcS1.sbs.getValue()) ); dpp.setPoly( (byte)2, (125 - sbe.getValue())); if ( sbe.getValue() >= 124 ) { difs.initBigPoly(); } else dpp.polyDrawn[0] = dpp.ON; dpp.repaint(); return true; } else return super.handleEvent ( evt ); } public boolean action( Event e, Object arg ) { if ( arg.equals("Redraw")) { sbe.setValue(125); le.setText("0"); dcS1.sbs.setValue(0); dcS1.ls1.setText("0"); dpp.initPoly(); return true; } return super.action( e, arg ); } } class RedrawControls extends Panel { DrawIFS difs; DrawPolyPanel dpp; private Button[] rd = { new Button("1Sky"), new Button("2Navy"), new Button("3Green"), new Button("4Rose") }; Label lrd; Font f; public RedrawControls(DrawIFS difs) { this.difs = difs; this.dpp = difs.dpp; lrd = new Label( "Redraw Parallelogram:", 1 ); f = new Font("Geneva", Font.PLAIN, 9 ); lrd.setFont(f); setBackground(Color.lightGray); setLayout( new FlowLayout()); add( lrd ); for ( int i = 0 ; i < 4 ; i++ ) { add( rd[i] ); rd[i].setForeground(dpp.col[i+1]); } } public boolean action(Event e, Object arg) { for ( int i = 0 ; i < 4 ; i++ ) { if ((e.target.equals(rd[i]))&&(dpp.mode == dpp.LINE)&& (dpp.polyDrawn[i + 1] == dpp.ON)) { dpp.redraw++; dpp.polyStack.push( new Integer(dpp.k )); dpp.k = i + 1; dpp.polyDrawn[i + 1] = dpp.OFF; for ( int n = 0 ; n < 2 ; n++ ) { for (int j = 0 ; j < 5 ; j++ ) { dpp.poly[i+1][n][j] = 0; dpp.elPoly[0][i+1][n][j] = 0; dpp.elPoly[1][i+1][n][j] = 0; } } dpp.repaint(); difs.dcS1.ls1.setText("now " + String.valueOf(dpp.k)); if ((((Integer)dpp.polyStack.peek()).intValue())<5 ) difs.dcE1.le.setText("next " + ((Integer)dpp.polyStack.peek()).toString()); else difs.dcE1.le.setText("Redraw"); return true; } } return super.action( e, arg ); } } class DrawPolyPanel extends Panel { DrawIFS difs; public static final byte LINE = 0; public static final byte POLY = 1; byte mode = LINE; public static final byte ON = 1; public static final byte OFF = 0; byte drawenable = OFF; public static final byte RED = 0; public static final byte BLACK = 1; byte colour = RED; int redraw = 0; Stack polyStack = new Stack(); byte polyDrawn[] = new byte[5]; int [][][] poly = new int[5][2][5]; int [][][][] elPoly = new int[2][5][2][5]; Color[] col = { new Color(0,0,0), new Color(0,0,0), new Color(0,0,0), new Color(0,0,0), new Color(0,0,0)}; int i,j,m,SBROT,SBTR; int k = 1; float [] dx = new float[2]; public DrawPolyPanel(DrawIFS difs) { this.difs = difs; setBackground(Color.white); col[0] = Color.yellow; col[1] = Color.cyan; col[2] = Color.blue; col[3] = Color.green; col[4] = Color.magenta; polyStack.push( new Integer( 5 )); for ( i = 0 ; i < 4 ; i++ ) { polyStack.push(new Integer( 5 - i )); } } public boolean handleEvent(Event evt) { if ( k < 5 ) { switch ( evt.id ) { case Event.MOUSE_DOWN: { if ( mode == LINE ) { poly[k][0][0] = evt.x; poly[k][1][0] = evt.y; shrinkLine(evt); difs.dcE1.le.setText("x " + poly[k][0][0]); difs.dcS1.ls1.setText("y " + poly[k][1][0]); drawenable = ON; return true; } else if ( mode == POLY ) { poly[k][0][2] = evt.x; poly[k][1][2] = evt.y; colour = RED; shrinkPoly(); difs.dcE1.le.setText("x " + poly[k][0][2]); difs.dcS1.ls1.setText("y " + poly[k][1][2]); drawenable = ON; repaint(); return true; } } case Event.MOUSE_DRAG: { if ( mode == LINE ) { poly[k][0][1] = evt.x; poly[k][1][1] = evt.y; colour = RED; shrinkLine(evt); difs.dcE1.le.setText("x " + poly[k][0][1]); difs.dcS1.ls1.setText("y " + poly[k][1][1]); repaint(); return true; } else if ( mode == POLY ) { poly[k][0][2] = evt.x; poly[k][1][2] = evt.y; colour = RED; shrinkPoly(); difs.dcE1.le.setText("x " + poly[k][0][2]); difs.dcS1.ls1.setText("y " + poly[k][1][2]); repaint(); return true; } } case Event.MOUSE_UP: { if ( mode == LINE ) { poly[k][0][1] = evt.x; poly[k][1][1] = evt.y; colour = BLACK; shrinkLine(evt); repaint(); return true; } else if ( mode == POLY ) { poly[k][0][2] = evt.x; poly[k][1][2] = evt.y; colour = BLACK; shrinkPoly(); polyDrawn[k] = ON; if ( redraw != 0 ) { drawenable = OFF; k = ((Integer)polyStack.pop()).intValue(); mode = LINE; redraw--; if ( k<5) difs.dcS1.ls1.setText("now " + String.valueOf(k)); else difs.dcS1.ls1.setText("done"); if ((((Integer)polyStack.peek()).intValue())<5) difs.dcE1.le.setText("next " + ((Integer)polyStack.peek()).toString()); else difs.dcE1.le.setText("Redraw"); } else { if ( k<4 ) difs.dcS1.ls1.setText("now " + String.valueOf(k+1)); else difs.dcS1.ls1.setText("done"); if ( k<3 ) difs.dcE1.le.setText("next " + String.valueOf(k+2)); else difs.dcE1.le.setText("Redraw"); } repaint(); return true; } } } } return super.handleEvent(evt); } public void shrinkLine(Event evt) { if ( evt.id == Event.MOUSE_DOWN ) { for ( i = 0 ; i < 2 ; i++ ) { for ( j = 0 ; j < 2 ; j++ ) { if (( 1 - 2*i )*poly[k][j][0] + i*399 < 2 ) { poly[k][j][0] = i*399 + 2 - 4*i ; } } } } if (( evt.id == Event.MOUSE_DRAG)||( evt.id == Event.MOUSE_UP)) { for ( i = 0 ; i < 2 ; i++ ) { for ( j = 0 ; j < 2 ; j++ ) { if (( 1 - 2*i )*poly[k][j][1] + i*399 < 2 ) { dx[0] = (float)(poly[k][1-j][1] - poly[k][1-j][0]); dx[1] = (float)(poly[k][j][1] - poly[k][j][0]); poly[k][1-j][1] = poly[k][1-j][0] + (int)((dx[0]/dx[1])* ( i*399 + 2 - i*4 - poly[k][j][0])); poly[k][j][1] = i*399 + 2 - i*4 ; } } } } } public void shrinkPoly() { for ( j = 0 ; j < 2 ; j++ ) { poly[k][j][3] = poly[k][j][2] - poly[k][j][1] + poly[k][j][0]; poly[k][j][4] = poly[k][j][0]; } for ( m = 0 ; m < 2 ; m++ ) { for ( i = 0 ; i < 2 ; i++ ) { for ( j = 0 ; j < 2 ; j++ ) { if (( 1 - 2*i )*poly[k][j][2+m] + i*399 < 1 ) { dx[0] = (float)(poly[k][1-j][2+m] - poly[k][1-j][1-m]); dx[1] = (float)(poly[k][j][2+m] - poly[k][j][1-m]); poly[k][1-j][2+m] = poly[k][1-j][1-m] + (int)((dx[0]/dx[1])* ( i*399 + 1 - i*2 - poly[k][j][1-m])); poly[k][j][2+m] = i*399 + 1 - 2*i ; poly[k][0][3-m] = poly[k][0][2+m] - poly[k][0][1-m] + poly[k][0][0+m]; poly[k][1][3-m] = poly[k][1][2+m] - poly[k][1][1-m] + poly[k][1][0+m]; } } } } } public void initPoly() { for ( m = 0 ; m < 5 ; m++ ) { for ( j = 0 ; j < 5 ; j++ ) { for ( i = 0 ; i < 2 ; i++ ) { poly[m][i][j] = 0; elPoly[0][m][i][j] = 0; elPoly[1][m][i][j] = 0; } } } while ( !polyStack.empty() ) { polyStack.pop(); } polyStack.push( new Integer( 5 )); for ( i = 0 ; i < 4 ; i++ ) { polyStack.push( new Integer( 5 - i )); polyDrawn[i] = OFF; } polyDrawn[4] = OFF; k = 1; SBROT = 0; SBTR = 0; redraw = 0; mode = LINE; repaint(); } public int [][][] getPoly() { return poly; } public void setPoly(byte SB, int SBVAL) { poly[0][0][1] = 399; if ( SB == (byte)1 ) SBROT = SBVAL; else SBTR = SBVAL; poly [0][0][0] = SBROT; poly [0][0][4] = SBROT; for ( j = 1 ; j < 4 ; j++ ) { poly[0][j%2][j] = 399*(j/2) + ( 1 - 2*(j/2))*SBROT; poly[0][(j+1)%2][j] = 399*((j+1)/2 - 2*((j+1)/4)); } for ( j = 0 ; j < 5 ; j++ ) { poly[0][0][j] = poly[0][0][j] + (((j/2) - 2*(j/4))*SBTR*SBROT )/400 + (( 1 - 2*((j+1)/2) + 4*((j+1)/4))*SBTR)/2 + (SBROT*SBTR)/400; poly[0][1][j] = poly[0][1][j] - ((j/2) - 2*(j/4))*SBTR - ((((j+1)/2) - 2*((j+1)/4))*SBTR*SBROT )/400; } for ( j = 0 ; j < 5 ; j++ ) { for ( i = 0 ; i < 2 ; i++ ) { elPoly[0][0][i][j] = poly[0][i][0] + (( 8 + 4*((j/2) - 2*(j/4)))* ( poly[0][i][1] - poly[0][i][0] ))/100 + (( 8 + 16*(((j+1)/2) - 2*((j+1)/4)))* ( poly[0][i][3] - poly[0][i][0] ))/100; elPoly[1][0][i][j] = poly[0][i][0] + (( 8 + 10*((j/2) - 2*(j/4)))* ( poly[0][i][1] - poly[0][i][0] ))/100 + (( 24 + 4*(((j+1)/2) - 2*((j+1)/4)))* ( poly[0][i][3] - poly[0][i][0] ))/100; } } repaint(); } public void paint(Graphics g) { for ( int PL = 0 ; PL < 5 ; PL++ ) { if ( polyDrawn[PL] == ON ) { g.drawPolygon( poly[PL][0] , poly[PL][1] , 5 ); g.setColor(col[PL]); g.fillPolygon( elPoly[0][PL][0] , elPoly[0][PL][1] , 5 ); g.fillPolygon( elPoly[1][PL][0] , elPoly[1][PL][1] , 5 ); g.setColor(Color.black); } } if (( mode == POLY )&&( drawenable == OFF )) { g.drawLine(poly[k][0][0], poly[k][1][0], poly[k][0][1], poly[k][1][1]); } if ( drawenable == ON ) { switch ( mode ) { case LINE: { if ( colour == BLACK ) { g.drawLine(poly[k][0][0], poly[k][1][0], poly[k][0][1], poly[k][1][1]); mode = POLY; drawenable = OFF; } else { g.setColor(Color.red); g.drawLine(poly[k][0][0], poly[k][1][0], poly[k][0][1], poly[k][1][1]); g.setColor(Color.black); } break; } case POLY: { for ( j = 0 ; j < 5 ; j++ ) { for ( i = 0 ; i < 2 ; i++ ) { elPoly[0][k][i][j] = poly[k][i][0] + (( 8 + 4*((j/2) - 2*(j/4)))* ( poly[k][i][1] - poly[k][i][0] ))/100 + (( 8 + 16*(((j+1)/2) - 2*((j+1)/4)))* ( poly[k][i][3] - poly[k][i][0] ))/100; elPoly[1][k][i][j] = poly[k][i][0] + (( 8 + 10*((j/2) - 2*(j/4)))* ( poly[k][i][1] - poly[k][i][0] ))/100 + (( 24 + 4*(((j+1)/2) - 2*((j+1)/4)))* ( poly[k][i][3] - poly[k][i][0] ))/100; } } if ( colour == BLACK ) { g.drawPolygon( poly[k][0] , poly[k][1] , 5 ); g.setColor(col[k]); g.fillPolygon( elPoly[0][k][0] , elPoly[0][k][1] , 5 ); g.fillPolygon( elPoly[1][k][0] , elPoly[1][k][1] , 5 ); g.setColor(Color.black); mode = LINE; if ( !polyStack.empty() ) k = ((Integer)(polyStack.pop())).intValue(); drawenable = OFF; } else { g.setColor(Color.red); g.drawPolygon( poly[k][0] , poly[k][1] , 5 ); g.setColor(Color.black); } } } } } } class DrawInitPanel extends Panel { int[][] x = new int[2][3]; int height,width; public static final byte RED = 0; public static final byte BLACK = 1; byte colour = RED; float[][] rect = new float[2][3]; public DrawInitPanel() { setBackground(Color.white); } public boolean handleEvent(Event evt) { switch (evt.id) { case Event.MOUSE_DOWN: x[0][0] = evt.x; x[1][0] = evt.y; return true; case Event.MOUSE_UP: x[0][1] = evt.x; x[1][1] = evt.y; colour = BLACK; compute(); repaint(); return true; case Event.MOUSE_DRAG: x[0][1] = evt.x; x[1][1] = evt.y; colour = RED; compute(); repaint(); return true; case Event.WINDOW_DESTROY: System.exit(0); return true; default: return super.handleEvent(evt); } } public void compute() { if ( x[0][0] != 0 ) { for ( int j = 0 ; j < 2 ; j++ ) { for ( int i = 0 ; i < 2 ; i++ ) { for ( int k = 0 ; k < 2 ; k++ ) { if (( 1 - 2*j )*x[i][k] + j*398 < 0 ) x[i][k] = j*398; } } } if ( x[0][1] < x[0][0] ) { width = x[0][0] - x[0][1]; x[0][2] = x[0][1]; } else { width = x[0][1] - x[0][0]; x[0][2] = x[0][0]; } if ( x[1][1] < x[1][0] ) { height = x[1][0] - x[1][1]; x[1][2] = x[1][1]; } else { height = x[1][1] - x[1][0]; x[1][2] = x[1][0]; } } } public float[][] getRect() { if (( x[0][2] == 0 )&&( x[1][2] == 0 )) { rect[0][0] = 160F; rect[1][0] = 160F; rect[0][1] = .2F; rect[1][2] = .2F; } else { rect[0][0] = x[0][2]; rect[1][0] = x[1][2]; rect[0][1] = ((float)width)/400; rect[1][2] = ((float)height)/400; } return rect; } public void clearRect() { for ( int i = 0 ; i < 2 ; i++ ) { for ( int j = 0 ; j < 3 ; j++ ) { rect[i][j] = 0; x[i][j] = 0; } } width = 0; height = 0; } public void paint(Graphics g) { if (( colour == BLACK )&&( x[0][0] != 0 )) { g.fillRect(x[0][2], x[1][2], width, height); } else { g.setColor(Color.red); g.drawRect(x[0][2], x[1][2], width, height); g.setColor(Color.black); } } } class SouthPanel extends Panel { DrawIFS difs; DrawControlsS2 dcS2; DrawControlsS3 dcS3; BorderLayout sb; Label ls2; Font f; String[] fractal = {"Your Fractal ", "the Barnsley Fern ", "the Snowflake ", "the Winter Tree ", "the Maple Leaf "}; public SouthPanel( DrawIFS difs ) { this.difs = difs; this.dcS2 = difs.dcS2; this.dcS3 = difs.dcS3; ls2 = new Label ("Chose the number of iterations, an initial rectangle and a fractal"); f = new Font("Geneva", Font.PLAIN, 9 ); ls2.setFont(f); sb = new BorderLayout(); setLayout(sb); add("North", ls2 ); add("Center", dcS2 ); } } class DrawControlsS2 extends Panel { DrawPolyPanel dpp; DrawInitPanel dip; DrawIFS difs; int frac,ntrans; int poly [][][] = new int [5][2][5]; float [][][] trans = new float [5][2][3]; String oldLabel; Button[] buttons2 = {new Button("Restart"), new Button("Yours"), new Button("Fern"), new Button("Flake"), new Button("Tree"), new Button("Leaf")}; public DrawControlsS2(DrawInitPanel dip, DrawIFS drawIFS, DrawPolyPanel dpp) { this.dpp = dpp; this.dip = dip; this.difs = drawIFS; setBackground(Color.lightGray); for ( int j = 0 ; j < 6 ; j++ ) { add( buttons2[j] ); } } public boolean action( Event evt , Object arg ) { if ((( arg.equals("Yours"))||( arg.equals("Fern"))||( arg.equals("Flake"))|| ( arg.equals("Tree"))||( arg.equals("Leaf")))&& ( difs.dp.compState == difs.dp.OFF)) { difs.setNewStage(difs.DRAWIFS); ntrans = 0; if ( arg.equals("Yours")) { frac = 0; poly = dpp.getPoly(); for ( int k = 0 ; k < 5 ; k++ ) { for ( int i = 0 ; i < 2 ; i++ ) { for ( int j = 0 ; j < 2 ; j++ ) { trans[ntrans][i][j+1] = ((float)(poly[k][i][2*j+1] - poly[k][i][0]))/400; } trans[ntrans][i][0] = poly[k][i][0]; } if (( trans[ntrans][0][0] != 0 )||( trans[ntrans][1][0] != 0 )) ntrans++; } } if ( arg.equals("Fern")) { frac = 1; ntrans = 4; trans[0][0][0] = (float)(75); trans[0][1][0] = (float)(0); trans[0][0][1] = (float)(.71); trans[0][1][1] = (float)(.05); trans[0][0][2] = (float)(-.05); trans[0][1][2] = (float)(.71); trans[1][0][0] = (float)(202); trans[1][1][0] = (float)(204); trans[1][0][1] = (float)(.0075); trans[1][1][1] = (float)(.4825); trans[1][0][2] = (float)(.0125); trans[1][1][2] = (float)(0); trans[2][0][0] = (float)(31); trans[2][1][0] = (float)(347); trans[2][0][1] = (float)(.1175); trans[2][1][1] = (float)(-.2925); trans[2][0][2] = (float)(.4125); trans[2][1][2] = (float)(.1275); trans[3][0][0] = (float)(375); trans[3][1][0] = (float)(326); trans[3][0][1] = (float)(-.0725); trans[3][1][1] = (float)(-.32); trans[3][0][2] = (float)(-.4275); trans[3][1][2] = (float)(.1); trans[4][0][0] = (float)(0); trans[4][1][0] = (float)(0); trans[4][0][1] = (float)(0); trans[4][1][1] = (float)(0); trans[4][0][2] = (float)(0); trans[4][1][2] = (float)(0); } else if ( arg.equals("Flake")) { frac = 2; ntrans = 4; trans[0][0][0] = (float)(153); trans[0][1][0] = (float)(33.44); trans[0][0][1] = (float)(.225); trans[0][1][1] = (float)(0); trans[0][0][2] = (float)(0); trans[0][1][2] = (float)(.225); trans[1][0][0] = (float)(49.84); trans[1][1][0] = (float)(212.72); trans[1][0][1] = (float)(.225); trans[1][1][1] = (float)(0); trans[1][0][2] = (float)(0); trans[1][1][2] = (float)(.225); trans[2][0][0] = (float)(256.24); trans[2][1][0] = (float)(212.78); trans[2][0][1] = (float)(.225); trans[2][1][1] = (float)(0); trans[2][0][2] = (float)(0); trans[2][1][2] = (float)(.225); trans[3][0][0] = (float)(-.0064); trans[3][1][0] = (float)(254.44); trans[3][0][1] = (float)(.37); trans[3][1][1] = (float)(-.642); trans[3][0][2] = (float)(.642); trans[3][1][2] = (float)(.37); trans[4][0][0] = (float)(0); trans[4][1][0] = (float)(0); trans[4][0][1] = (float)(0); trans[4][1][1] = (float)(0); trans[4][0][2] = (float)(0); trans[4][1][2] = (float)(0); } else if ( arg.equals("Tree")) { frac = 3; ntrans = 5; trans[0][0][0] = (float)(0); trans[0][1][0] = (float)(124.72); trans[0][0][1] = (float)(.195); trans[0][1][1] = (float)(-.344); trans[0][0][2] = (float)(.488); trans[0][1][2] = (float)(.433); trans[1][0][0] = (float)(266.04); trans[1][1][0] = (float)(27.92); trans[1][0][1] = (float)(.4); trans[1][1][1] = (float)(.252); trans[1][0][2] = (float)(-.414); trans[1][1][2] = (float)(.361); trans[2][0][0] = (float)(211.04); trans[2][1][0] = (float)(370); trans[2][0][1] = (float)(-.058); trans[2][1][1] = (float)(-.453); trans[2][0][2] = (float)(.07); trans[2][1][2] = (float)(-.111); trans[3][0][0] = (float)(223.36); trans[3][1][0] = (float)(206.04); trans[3][0][1] = (float)(-.035); trans[3][1][1] = (float)(.469); trans[3][0][2] = (float)(-.07); trans[3][1][2] = (float)(-.022); trans[4][0][0] = (float)(342.48); trans[4][1][0] = (float)(99.08); trans[4][0][1] = (float)(-.637); trans[4][1][1] = (float)(0); trans[4][0][2] = (float)(0); trans[4][1][2] = (float)(.501); } else if ( arg.equals("Leaf")) { frac = 4; ntrans = 3; trans[0][0][0] = (float)(78); trans[0][1][0] = (float)(3); trans[0][0][1] = (float)(.6075); trans[0][1][1] = (float)(0); trans[0][0][2] = (float)(0); trans[0][1][2] = (float)(.5625); trans[1][0][0] = (float)(13); trans[1][1][0] = (float)(204); trans[1][0][1] = (float)(.365); trans[1][1][1] = (float)(-.3625); trans[1][0][2] = (float)(.375); trans[1][1][2] = (float)(.375); trans[2][0][0] = (float)(241); trans[2][1][0] = (float)(60); trans[2][0][1] = (float)(.39); trans[2][1][1] = (float)(.3875); trans[2][0][2] = (float)(-.345); trans[2][1][2] = (float)(.345); trans[3][0][0] = (float)(0); trans[3][1][0] = (float)(0); trans[3][0][1] = (float)(0); trans[3][1][1] = (float)(0); trans[3][0][2] = (float)(0); trans[3][1][2] = (float)(0); trans[4][0][0] = (float)(0); trans[4][1][0] = (float)(0); trans[4][0][1] = (float)(0); trans[4][1][1] = (float)(0); trans[4][0][2] = (float)(0); trans[4][1][2] = (float)(0); } difs.dp.setTrans(); difs.dp.initScreen(); difs.sp.ls2.setText("Drawing " + difs.sp.fractal[frac]); difs.resetLayout(); difs.dcS3.compute(); return true; } if ( arg.equals("Restart")) { difs.setNewStage(difs.DRAWPOLY); dip.clearRect(); difs.resetLayout(); return true; } else return super.action(evt, arg); } public boolean handleEvent( Event evt ) { if (( evt.id == Event.MOUSE_ENTER )&&(evt.target instanceof Button)) { oldLabel = difs.sp.ls2.getText(); for ( int j = 1 ; j < 6 ; j++ ) { if ( evt.target == buttons2[j] ) { difs.sp.ls2.setText("This button will draw " + difs.sp.fractal[j-1]); } } if ( evt.target == buttons2[0] ) { difs.sp.ls2.setText ("Takes you to the first screen to draw parallelograms."); } } if (( evt.id == Event.MOUSE_EXIT )&&( evt.target instanceof Button)) { difs.sp.ls2.setText(oldLabel); } return super.handleEvent( evt ); } public float[][][] getTrans() { return trans; } public int getNtrans() { return ntrans; } } class DrawControlsE2 extends Panel { DrawInitPanel dip; DrawIFS difs; int n, i, lastn; String oldLabel; CheckboxGroup iter = new CheckboxGroup(); Checkbox[] Ch = { new Checkbox("1", iter, false), new Checkbox("2", iter, false), new Checkbox("3", iter, false), new Checkbox("4", iter, false), new Checkbox("5", iter, false), new Checkbox("6", iter, false), new Checkbox("7", iter, false), new Checkbox("8", iter, false), new Checkbox("9", iter, false) }; public DrawControlsE2 (DrawInitPanel target, DrawIFS tegrat) { this.dip = target; this.difs = tegrat; setLayout(new GridLayout( 9 , 1 )); setBackground(Color.lightGray); for ( i = 0 ; i < 9 ; i++ ) { add( Ch[i] ); Ch[i].setBackground( new Color((16320 - 4080*i + 255*i*i )/64, (16320*i*i - 4080*i*i*i + 255*i*i*i*i)/256 , (i*i*255)/64)); } } public boolean action(Event e, Object arg) { for ( i = 0 ; i < 9 ; i++ ) { if (e.target.equals(Ch[i])) { n = i + 1; if ( difs.currentStage == difs.INIT ) { difs.sp.ls2.setText("You chose "+ (i+1) + " iterations, now choose an initial rectangle and a fractal."); oldLabel = "You chose "+ String.valueOf(i+1) + " iterations, now choose an initial rectangle and a fractal."; } if ( difs.currentStage == difs.DRAWIFS ) { difs.sp.ls2.setText("You chose "+ (i+1) + " iterations, Redraw to compute a new image."); oldLabel = "You chose "+ String.valueOf(i+1) + " iterations, Redraw to compute a new image."; } return true; } } return super.action( e, arg ); } public boolean handleEvent( Event evt ) { if (( evt.id == Event.MOUSE_ENTER )&&(evt.target instanceof Checkbox)) { oldLabel = difs.sp.ls2.getText(); for ( int j = 0 ; j < 9 ; j++ ) { if ( evt.target == Ch[j] ) { difs.sp.ls2.setText("This choice will compute " + (j+1) + " iterations."); } } } if (( evt.id == Event.MOUSE_EXIT )&&( evt.target instanceof Checkbox)) { difs.sp.ls2.setText(oldLabel); } return super.handleEvent( evt ); } public boolean keyDown( Event evt, int key ) { if (( key > 48 )&&( key < 58 )) { System.out.println(String.valueOf(key)); iter.setCurrent(Ch[key - 49]); n = key - 48; return true; } if (( key < 49 )||(( key > 57 )&&( key < 200 ))) { if (( difs.currentStage == difs.DRAWIFS )&& ( difs.dp.compState == difs.dp.OFF )) { if ( lastn == n ) { iter.setCurrent(Ch[n]); n++; } } difs.dcS3.compute(); return true; } return super.keyDown( evt, key ); } public int getn() { return n; } } class DrawControlsS3 extends Panel { DrawIFS difs; DrawPanel dp; String oldLabel; Thread compThread; Label ls3; Button b1 = new Button("Initialize"); Button b2 = new Button("Redraw"); Button b3 = new Button("Attractor"); public DrawControlsS3(DrawIFS target, DrawPanel drawpanel) { this.difs = target; this.dp = drawpanel; add( b1 ); add( b2 ); add( b3 ); } public void compute() { dp.repaint(); compThread = new Thread( dp, "compThread" ); compThread.setPriority(Thread.NORM_PRIORITY); compThread.start(); } public boolean action( Event evt , Object arg ) { if ( arg.equals("Initialize")) { if ( compThread != null ) { compThread.stop(); compThread = null; } dp.compState = dp.OFF; dp.initScreen(); difs.setNewStage( difs.INIT ); difs.sp.ls2.setText( "Chose the number of iterations, an initial rectangle and a fractal"); oldLabel = "Chose the number of iterations, an initial rectangle and a fractal"; difs.resetLayout(); return true; } if ((( arg.equals("Redraw"))||( arg.equals("Attractor")))&& (dp.compState == dp.OFF )) { if ( arg.equals("Attractor")) dp.compDFS = dp.ON; compute(); return true; } else return super.action( evt, arg ); } public boolean handleEvent( Event evt ) { if (( evt.id == Event.MOUSE_ENTER )&&(evt.target instanceof Button)) { oldLabel = difs.sp.ls2.getText(); if ( evt.target == b1 ) { difs.sp.ls2.setText( "Return to the second screen to choose another fractal."); } if ( evt.target == b2 ) { difs.sp.ls2.setText ("Redraw the current fractal with " + difs.dcE2.n + " iterations."); } if ( evt.target == b3 ) { difs.sp.ls2.setText( "Draw the current fractal to the level of screen resolution."); } } if (( evt.id == Event.MOUSE_EXIT )&&( evt.target instanceof Button)) { difs.sp.ls2.setText(oldLabel); } return super.handleEvent( evt ); } } class DrawPanel extends Panel implements Runnable { int [][] Screen = new int [400][400]; float [][][] triplet; float [][][] trans = new float [4][2][3]; int [][] poly = new int[2][4]; Vector points1 = new Vector(1500); Vector points2 = new Vector(1500); Vector [] polygon = {points1, points2}; int h,i,j,k,m,p,q,np,nq, len; int HIGH = 1; int LOW; float mx; DrawControlsE2 dcE2; DrawInitPanel dip; DrawControlsS2 dcS2; DrawIFS difs; SouthPanel sp; int ntrans = 0; int depth = 0; public static final int OFF = 0; public static final int ON = 1; int compState = OFF; int compDFS = OFF; int TOP = 0; int BOTTOM = 0; int INC = 0; int MAX = 60; int[] map = new int[MAX + 1]; float[][] point = new float[MAX + 1][2]; int level = 0; int colour = 0; public DrawPanel (DrawControlsE2 target, DrawInitPanel tegrat, DrawControlsS2 drawControls, DrawIFS difs) { this.dcE2 = target; this.dip = tegrat; this.dcS2 = drawControls; this.difs = difs; this.sp = difs.sp; setBackground(Color.white); } public void setTrans() { this.trans = dcS2.getTrans(); } public void initScreen() { LOW = 0; for ( i = 0 ; i < 400 ; i++ ) { for ( j = 0 ; j < 400 ; j++ ) { Screen [i][j] = 0 ; } } polygon[0].removeAllElements(); polygon[1].removeAllElements(); polygon[0].addElement(dip.getRect()); } public void run() { if ( compDFS == ON ) { compState = ON; ntrans = dcS2.getNtrans(); initScreen(); polygon[0].removeAllElements(); repaint(); initCompdfs(); compFxPt(); compsdfs(); LOW = HIGH; difs.sp.ls2.setText( difs.sp.fractal[dcS2.frac] + "drawn completely" ); repaint(); difs.dcS3.compThread = null; } else try { compState = ON; HIGH = dcE2.getn(); dcE2.lastn = HIGH; if ( HIGH < LOW ) { initScreen(); } for ( m = LOW ; m < HIGH ; m++ ) { len = 0; p = m%2; q = (m+1)%2; np = polygon[p].size(); nq = polygon[q].size(); for ( h = 0 ; h < np ; h++ ) { for ( k = 0 ; k < dcS2.getNtrans() ; k++ ) { triplet = new float[2][2][3]; triplet[p] = (float[][])polygon[p].elementAt(h); mx = 0; for ( i = 0 ; i < 2 ; i++ ) { for ( j = 1 ; j < 3 ; j++ ) { triplet[q][i][j] = trans[k][i][1]*triplet[p][0][j] + trans[k][i][2]*triplet[p][1][j]; if ( triplet[q][i][j] > mx ) mx = triplet[q][i][j]; else if ( -triplet[q][i][j] > mx ) mx = -triplet[q][i][j]; } triplet[q][i][0] = trans[k][i][1]*triplet[p][0][0] + trans[k][i][2]*triplet[p][1][0] + trans[k][i][0]; } if ( mx < .0025 ) { initCompdfs(); point[0][0] = triplet[q][0][0]; point[0][1] = triplet[q][1][0]; compdfs( HIGH - m ); } else if ( len < nq ) { polygon[q].setElementAt(triplet[q],len ); len++; } else polygon[q].addElement(triplet[q]); } } if ( len < nq ) { for ( i = len ; i < nq ; i++ ) { polygon[q].removeElementAt( len ); } } int w = polygon[q].size(); java.lang.System.out.println( "polygon[q].size() = " + w ); difs.sp.ls2.setText( "Drawing " + difs.sp.fractal[dcS2.frac] + ": with " + polygon[q].size() + " parallelograms computed so far."); if ( m < 1 ) { try { Thread.currentThread().sleep(50); } catch( InterruptedException ignored ) {} } Thread.currentThread().yield(); } LOW = HIGH; repaint(); difs.dcS3.compThread = null; } catch(OutOfMemoryError e) { initScreen(); compState = OFF; if (difs.dcS3.compThread != null ) difs.dcS3.compThread = null; difs.setCurrentStage( difs.currentStage ); difs.setNewStage( difs.INIT ); difs.sp.ls2.setText ("Java is out of memory, choose smaller rectangle or fewer iterations."); difs.resetLayout(); } } public void compsdfs() { level = 0; colour = 0; j = 0; comp: while ( j == 0 ) { Thread.currentThread().yield(); INC = increment(TOP); point[INC][0] = trans[map[TOP]][0][1]*point[TOP][0] + trans[map[TOP]][0][2]*point[TOP][1] + trans[map[TOP]][0][0]; point[INC][1] = trans[map[TOP]][1][1]*point[TOP][0] + trans[map[TOP]][1][2]*point[TOP][1] + trans[map[TOP]][1][0]; TOP = INC; level++; if ( TOP == BOTTOM ) { BOTTOM = increment( BOTTOM ); } map[TOP] = 0; if ( Screen[(int)point[TOP][0]][(int)point[TOP][1]] != 0 ) { do { TOP = decrement( TOP ); level--; if (( TOP == BOTTOM )&&( map[TOP] == ntrans - 1 )) break comp; } while ( map[TOP] == ntrans - 1 ); map[TOP]++; } else { colour = (int)( level/12 ); Screen[(int)point[TOP][0]][(int)point[TOP][1]] = colour; } } } public void compFxPt() { point[1][0] = 200; point[1][1] = 200; h = dcS2.getNtrans() - 1; do { point[0][0] = point[1][0]; point[0][1] = point[1][1]; point[1][0] = trans[h][0][1]*point[0][0] + trans[h][0][2]*point[0][1] + trans[h][0][0]; point[1][1] = trans[h][1][1]*point[0][0] + trans[h][1][2]*point[0][1] + trans[h][1][0]; } while (((int)point[1][0] != (int)point[0][0])||((int)point[1][1] != (int)point[0][1])); point[0][0] = point[1][0]; point[0][1] = point[1][1]; } public void initCompdfs() { TOP = 0; BOTTOM = 0; INC = 0; for ( int t = 0 ; t <= MAX ; t++ ) { map[t] = 0; point[t][0] = 0; point[t][1] = 0; } } public int increment( int s ) { if ( s == MAX ) s = 0; else s++; return s; } public int decrement( int s ) { if ( s == 0 ) s = MAX; else s--; return s; } public void compdfs( int d ) { this.depth = d; ntrans = dcS2.getNtrans(); INC = TOP + 1; for ( int s = 0 ; s < 2 ; s++ ) { point[INC][s] = trans[map[TOP]][s][1]*point[TOP][0] + trans[map[TOP]][s][2]*point[TOP][1] + trans[map[TOP]][s][0]; } TOP = INC; map[TOP] = 0; if ( TOP == depth ) { Screen[(int)point[TOP][0]][(int)point[TOP][1]] = 1; } if ( Screen[(int)point[TOP][0]][(int)point[TOP][1]] == 1 ) { do { TOP--; if (( TOP == 0 )&&( map[TOP] == ntrans - 1 )) return; } while ( map[TOP] == ntrans - 1 ); map[TOP]++; compdfs(depth); } else { compdfs(depth); } } public void paint(Graphics g) { if (( HIGH == LOW )&&( compState == ON )) { k = 0; for ( i = 0 ; i < 400 ; i += 2 ) { for ( j = 0 ; j < 400 ; j += 2 ) { if ( Screen [i][j] == 1 ) { g.drawLine( i , j , i , j ); k++; } if ( Screen [i][j] > 1 ) { if (Screen [i][j] < 256 ) { g.setColor( new Color( 255, Screen [i][j], 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 512 ) { g.setColor( new Color( 511 - Screen [i][j], 255 , 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 768 ) { g.setColor( new Color( 0 , 255 , Screen [i][j] - 512 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1024 ) { g.setColor( new Color( 0 , 1023 - Screen [i][j], 255 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1280 ) { g.setColor( new Color( (int)(( Screen [i][j] - 1024 )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1024 )/2 ))); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1536 ) { g.setColor( new Color( (int)( 64 - ( 1535 - Screen [i][j] )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1025 )/2 ))); g.drawLine( i , j , i , j ); k++; } else { g.setColor(Color.black); g.drawLine( i , j , i , j ); k++; } } g.setColor(Color.black); } } for ( j = 1 ; j < 400 ; j += 2 ) { for ( i = 0 ; i < 400 ; i += 2 ) { if ( Screen [i][j] == 1 ) { g.drawLine( i , j , i , j ); k++; } if ( Screen [i][j] > 1 ) { if (Screen [i][j] < 256 ) { g.setColor( new Color( 255, Screen [i][j], 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 512 ) { g.setColor( new Color( 511 - Screen [i][j], 255 , 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 768 ) { g.setColor( new Color( 0 , 255 , Screen [i][j] - 512 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1024 ) { g.setColor( new Color( 0 , 1023 - Screen [i][j], 255 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1280 ) { g.setColor( new Color( (int)(( Screen [i][j] - 1024 )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1024 )/2 ))); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1536 ) { g.setColor( new Color( (int)( 64 - ( 1535 - Screen [i][j] )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1025 )/2 ))); g.drawLine( i , j , i , j ); k++; } else { g.setColor(Color.black); g.drawLine( i , j , i , j ); k++; } } g.setColor(Color.black); } } for ( i = 1 ; i < 400 ; i += 2 ) { for ( j = 0 ; j < 400 ; j += 2 ) { if ( Screen [i][j] == 1 ) { g.drawLine( i , j , i , j ); k++; } if ( Screen [i][j] > 1 ) { if (Screen [i][j] < 256 ) { g.setColor( new Color( 255, Screen [i][j], 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 512 ) { g.setColor( new Color( 511 - Screen [i][j], 255 , 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 768 ) { g.setColor( new Color( 0 , 255 , Screen [i][j] - 512 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1024 ) { g.setColor( new Color( 0 , 1023 - Screen [i][j], 255 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1280 ) { g.setColor( new Color( (int)(( Screen [i][j] - 1024 )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1024 )/2 ))); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1536 ) { g.setColor( new Color( (int)( 64 - ( 1535 - Screen [i][j] )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1025 )/2 ))); g.drawLine( i , j , i , j ); k++; } else { g.setColor(Color.black); g.drawLine( i , j , i , j ); k++; } } g.setColor(Color.black); } } for ( j = 1 ; j < 400 ; j += 2 ) { for ( i = 1 ; i < 400 ; i += 2 ) { if ( Screen [i][j] == 1 ) { g.drawLine( i , j , i , j ); k++; } if ( Screen [i][j] > 1 ) { if (Screen [i][j] < 256 ) { g.setColor( new Color( 255, Screen [i][j], 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 512 ) { g.setColor( new Color( 511 - Screen [i][j], 255 , 0 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 768 ) { g.setColor( new Color( 0 , 255 , Screen [i][j] - 512 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1024 ) { g.setColor( new Color( 0 , 1023 - Screen [i][j], 255 )); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1280 ) { g.setColor( new Color( (int)(( Screen [i][j] - 1024 )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1024 )/2 ))); g.drawLine( i , j , i , j ); k++; } else if ( Screen [i][j] < 1536 ) { g.setColor( new Color( (int)( 64 - ( 1535 - Screen [i][j] )/4 ) , 0 , (int)( 255 - ( Screen [i][j] - 1025 )/2 ))); g.drawLine( i , j , i , j ); k++; } else { g.setColor(Color.black); g.drawLine( i , j , i , j ); k++; } } g.setColor(Color.black); } } java.lang.System.out.println("no. of Points drawn is" + k ); nq = polygon[q].size(); difs.sp.ls2.setText( difs.sp.fractal[dcS2.frac] + "drawn: with " + nq + " parallelograms computed and " + k + " points drawn." ); difs.dcS3.oldLabel = String.valueOf(difs.sp.fractal[dcS2.frac]) + "drawn: with " + String.valueOf(nq) + " parallelograms computed and " + String.valueOf( k ) + " points drawn."; for ( j = 0 ; j < nq ; j++ ) { for ( i = 0 ; i < 2 ; i++ ) { poly[i][0] = (int)(((float[][])polygon[q].elementAt( j ))[i][0]); poly[i][1] = (int)(((float[][])polygon[q].elementAt( j ))[i][1]*400 + ((float[][])polygon[q].elementAt( j ))[i][0]); poly[i][2] = (int)(((float[][])polygon[q].elementAt( j ))[i][1]*400 + ((float[][])polygon[q].elementAt( j ))[i][2]*400 + ((float[][])polygon[q].elementAt( j ))[i][0]); poly[i][3] = (int)(((float[][])polygon[q].elementAt( j ))[i][2]*400 + ((float[][])polygon[q].elementAt( j ))[i][0]); } g.fillPolygon( poly[0] , poly[1] , 4 ); g.drawLine( poly[0][0], poly[1][0], poly[0][0], poly[1][0] ); } compState = OFF; if ( compDFS == ON ) { initScreen(); compDFS = OFF; } } } }