import java.awt.*; class TestsWU extends Frame { public static int xSize = 500; public static int ySize = 500; public TestsWU(){ setLayout(null); setSize(xSize,ySize); setVisible(true); } public static void main( String args[] ) { Frame frm = (Frame) new TestsWU(); //new Frame(); Graphics g = frm.getGraphics(); g.setColor(new Color(0,0,0)); g.fillRect( 0,0,xSize,ySize); InitializeISqrt(); int R = 20; int y=0; int x=R; int xCenter = 200; int yCenter = 200; int I = 255; while( y<x ) { ISQRT( R*R-y*y ); x = ISignificand; int p = POWERES_OF_TEN[IExponent]; int id = x % p; int xLeft = (x - id) / p; int xRight = ((x - id) + p ) / p; x /= p; int ILeft = I*(p-id)/p; int IRight = I* id /p; //Draw cicle: g.setColor(new Color(IRight,IRight,IRight)); g.fillRect( xRight+xCenter, yCenter-y, 1, 1 ); g.setColor(new Color(ILeft,ILeft,ILeft)); g.fillRect( xLeft+xCenter, yCenter-y, 1, 1 ); y +=1; }//while y<x //Draw coodinate lines: g.setColor(new Color(0,0,255)); g.drawLine( xCenter, yCenter, xCenter+R, yCenter ); g.drawLine( xCenter, yCenter, xCenter, yCenter-R ); }//main //Auxiliary array to store precalculated powers of 10: private static int POWERES_OF_TEN[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; //Primary array where precalculated roots will be stored: private static int[] ISqrt; public static void InitializeISqrt() { ISqrt = new int[10000]; for( int i=0; i<10000; i++ ){ ISqrt[i] = (int) ( Math.sqrt((double)i) * 10000 ); } } //Calculating square root represented by integer numbers. //Input 100>x>=0. //Output: ISignificand, IExponent // where // sqrt(x) = ISignificand * 10^IExponent public static int IExponent; public static int ISignificand; public static void ISQRT( int x ) { int shift=0; while ( x>=10000 ) { x = x/100; shift +=1; } IExponent = 4-shift; ISignificand = ISqrt[x]; }//ISQRT }//class Copyright_C_2008_Landkey_Computers.txt