Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FF_14312_Sinitsyna_Span;
- import java.awt.*;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- public class Circle implements Shape {
- int r = 0;
- int cx, cy;
- public Circle(int nx, int ny){
- cx = nx;
- cy = ny;
- }
- public void setR(int nr){
- r = nr;
- }
- public int getCx(){
- return cx;
- }
- public int getCy() {
- return cy;
- }
- @Override
- public void draw(Graphics g) {
- int x = 0, y = r, gap = 0, delta = (2 - 2 * r);
- while (y >= 0)
- {
- g.drawLine(cx+x, cy+y, cx+x, cy+y);
- g.drawLine(cx + x, cy - y, cx + x, cy - y);
- g.drawLine(cx - x, cy - y, cx - x, cy - y);
- g.drawLine(cx - x, cy + y,cx - x, cy + y);
- gap = 2 * (delta + y) - 1;
- if (delta < 0 && gap <= 0)
- {
- x++;
- delta += 2 * x + 1;
- continue;
- }
- if (delta > 0 && gap > 0)
- {
- y--;
- delta -= 2 * y + 1;
- continue;
- }
- x++;
- delta += 2 * (x - y);
- y--;
- }
- }
- public void write(BufferedWriter writer){
- try {
- writer.write("CIRCLE");
- writer.newLine();
- writer.write(cx+ " " + cy + " " + r);
- writer.newLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement