Advertisement
crassus9999

Untitled

Mar 13th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package cz.cvut.k36.pr2.hw.hw02.impl;
  2.  
  3. import java.awt.geom.Point2D;
  4.  
  5. import cz.cvut.k36.pr2.hw.hw02.Canvas;
  6. import cz.cvut.k36.pr2.hw.hw02.Color;
  7. import cz.cvut.k36.pr2.hw.hw02.Shape;
  8.  
  9. public class Circle implements Shape {
  10.    
  11.     private Color color;
  12.     private double centerX;
  13.     private double centerY;
  14.     private double radius;
  15.  
  16.     @Override
  17.     public void printToCanvas(Canvas canvas) {
  18.         for (int i = 0; i < canvas.getWidth(); i++) {
  19.             for (int j = 0; j < canvas.getHeight(); j++) {
  20.                 if (contains(i, j, centerX, centerY, radius)) {
  21.                     canvas.setColorAt(i, j, this.color);
  22.                 }
  23.             }
  24.         }
  25.     }
  26.    
  27.    
  28.     private boolean contains(double x1, double y1, double x2, double y2, double radius) {
  29.         if (Point2D.distance(x1, y1, x2, y2) <= radius) {
  30.             return true;
  31.         }
  32.         return false;
  33.     }
  34.  
  35.     public Circle(Color color, double centerX, double centerY, double radius) {
  36.         this.color = color;
  37.         this.centerX = centerX;
  38.         this.centerY = centerY;
  39.         this.radius = radius;
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement