Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package FF_14312_Sinitsyna_Span;
  2.  
  3. import java.awt.*;
  4. import java.io.BufferedReader;
  5. import java.io.BufferedWriter;
  6. import java.io.IOException;
  7.  
  8. public class Circle implements Shape {
  9. int r = 0;
  10. int cx, cy;
  11.  
  12. public Circle(int nx, int ny){
  13. cx = nx;
  14. cy = ny;
  15. }
  16.  
  17. public void setR(int nr){
  18. r = nr;
  19. }
  20. public int getCx(){
  21. return cx;
  22. }
  23.  
  24. public int getCy() {
  25. return cy;
  26. }
  27.  
  28. @Override
  29. public void draw(Graphics g) {
  30.  
  31. int x = 0, y = r, gap = 0, delta = (2 - 2 * r);
  32. while (y >= 0)
  33. {
  34. g.drawLine(cx+x, cy+y, cx+x, cy+y);
  35.  
  36. g.drawLine(cx + x, cy - y, cx + x, cy - y);
  37. g.drawLine(cx - x, cy - y, cx - x, cy - y);
  38. g.drawLine(cx - x, cy + y,cx - x, cy + y);
  39. gap = 2 * (delta + y) - 1;
  40. if (delta < 0 && gap <= 0)
  41. {
  42. x++;
  43. delta += 2 * x + 1;
  44. continue;
  45. }
  46. if (delta > 0 && gap > 0)
  47. {
  48. y--;
  49. delta -= 2 * y + 1;
  50. continue;
  51. }
  52. x++;
  53. delta += 2 * (x - y);
  54. y--;
  55. }
  56. }
  57.  
  58. public void write(BufferedWriter writer){
  59. try {
  60. writer.write("CIRCLE");
  61. writer.newLine();
  62. writer.write(cx+ " " + cy + " " + r);
  63. writer.newLine();
  64.  
  65. } catch (IOException e) {
  66. e.printStackTrace();
  67. }
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement