import bsh.util.BshCanvas; // BshCanvas simply buffers graphics graph( int width, int height ) { scale=object(); scale.x=100; scale.y=100; drawAxis() { graphics.setColor( Color.red ); graphics.drawLine( 0, height/2, width, height/2 ); graphics.drawLine( width/2, 0, width/2, height ); } plot(x, y, Color color) { graphics.setColor( color ); graphics.fillOval( (int)((x/scale.x+1)*(width/2))-1, (int)((-y/scale.y+1)*(height/2))-1, 3, 3); canvas.repaint(); } clear() { graphics.setColor( Color.white ); graphics.fillRect(0,0,width,height); drawAxis(); canvas.repaint(); } setScale( x, y ) { scale.x=1.0*x; scale.y=1.0*y; } canvas=new BshCanvas(); canvas.setSize( width, height ); frame=frame( canvas ); graphics=canvas.getBufferedGraphics(); drawAxis(); return this; } g=graph(400,200); g.setScale(2*Math.PI,1.0); for (x=-2*Math.PI; x<2*Math.PI; x+=0.1) { y=Math.sin(x); g.plot( x, y, Color.black ); }