// (C) Copyright Jack Culpepper 1997 // This code may not be distributed without permission. package mandel; import java.awt.*; import mandel.MandelTask; public class MandelFrame extends Frame { protected byte[][] data; // for some reason, ( 0, 0 ) in the graphics object coordinate system is // masked by the window manager's frame widget. this number represents the // verticle thickness of the widget, so that we may size our window larger // by an appropriate amount, and begin our draw a little further down than // we otherwise would. (it's possible that this number may vary from // window manager to window manager) protected static final int window_widget_height = 25; protected Graphics offscreenG; protected Image offscreenI; public MandelFrame( String name, byte[][] data ) { super( name ); this.data = data; this.setSize( data.length, data[0].length + window_widget_height ); this.show(); } public void update( Graphics g ) { paint( g ); } public void paint( Graphics g ) { if ( offscreenI != null ) { g.drawImage( offscreenI, 0, 0, this ); } } public void drawPoint( int x, int y, Graphics g ) { byte i = data[ x ][ y ]; if ( i < 0 || i > 100 ) i = 100; Color color = new Color( ( float ) ( ( float )i / 100.0 ), 0, 0 ); g.setColor( color ); g.drawLine( x, y + window_widget_height, x, y + window_widget_height ); } public void input( MandelTask t ) { if ( offscreenI == null ) { offscreenI = createImage( data.length, data[0].length + window_widget_height ); } if ( offscreenI == null ) System.out.println( "Null!!!!!" ); else { for ( int i = 0 ; i < t.res.x ; i++ ) { for ( int j = 0 ; j < t.res.y ; j++ ) { drawPoint( i + t.loc.x, j + t.loc.y, offscreenI.getGraphics() ); } } } paint( this.getGraphics() ); } }