Creep4Play

Bresenham Circle

Apr 13th, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.  
  2. public abstract class Circle {
  3.    
  4.     public void create(int x0, int y0, int r) {
  5.         int x = r, y = 0, e = 1-x;
  6.         while(x >= y) {
  7.             draw(x0 + x, y0 + y);
  8.             draw(x0 + y, y0 + x);
  9.             draw(x0 - x, y0 + y);
  10.             draw(x0 - y, y0 + x);
  11.             draw(x0 + x, y0 - y);
  12.             draw(x0 + y, y0 - x);
  13.             draw(x0 - x, y0 - y);
  14.             draw(x0 - y, y0 - x);
  15.             ++y;
  16.             if (e < 0)
  17.                 e += (y << 2) + 1;
  18.             else
  19.                 e += y - --x + 1 << 2;
  20.         }
  21.     }
  22.    
  23.     public abstract void draw(int x, int y);
  24.    
  25. }
Advertisement
Add Comment
Please, Sign In to add comment