Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cz.cvut.k36.pr2.hw.hw02.impl;
- import java.awt.geom.Point2D;
- import cz.cvut.k36.pr2.hw.hw02.Canvas;
- import cz.cvut.k36.pr2.hw.hw02.Color;
- import cz.cvut.k36.pr2.hw.hw02.Shape;
- public class Circle implements Shape {
- private Color color;
- private double centerX;
- private double centerY;
- private double radius;
- @Override
- public void printToCanvas(Canvas canvas) {
- for (int i = 0; i < canvas.getWidth(); i++) {
- for (int j = 0; j < canvas.getHeight(); j++) {
- if (contains(i, j, centerX, centerY, radius)) {
- canvas.setColorAt(i, j, this.color);
- }
- }
- }
- }
- private boolean contains(double x1, double y1, double x2, double y2, double radius) {
- if (Point2D.distance(x1, y1, x2, y2) <= radius) {
- return true;
- }
- return false;
- }
- public Circle(Color color, double centerX, double centerY, double radius) {
- this.color = color;
- this.centerX = centerX;
- this.centerY = centerY;
- this.radius = radius;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement