Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Circle.cpp
- *
- * EECS 183, Fall 2016
- * Project 4: CoolPics
- *
- * John Dorsey, Patrick Ahimovic
- * jsdorsey, paddya
- *
- * Functions for the shape subclass of Circle
- */
- #include "Circle.h"
- #include "Line.h"
- #include "Graphics.h"
- #include "utility.h"
- #include <algorithm>
- using namespace std;
- Circle::Circle() {
- radius = 0;
- }
- Circle::Circle(Point pt, int r, Color c) {
- setCenter(pt);
- setRadius(r);
- setColor(c);
- }
- void Circle::setCenter(Point new_pt) {
- center = new_pt;
- }
- void Circle::setColor(Color new_col) {
- color = new_col;
- }
- void Circle::setRadius(int new_r) {
- radius = new_r;
- }
- Point Circle::getCenter() {
- return center;
- }
- int Circle::getRadius() {
- return radius;
- }
- Color Circle::getColor() {
- return color;
- }
- void Circle::read(istream& ins) {
- Point centRead;
- int radRead;
- Color colorRead;
- ins >> centRead >> radRead >> colorRead;
- center = centRead;
- radius = radRead;
- color = colorRead;
- }
- void Circle::write(ostream& outs) {
- Point w_cent = getCenter();
- int w_rad = getRadius();
- Color w_col = getColor();
- outs << " " << w_cent << " " << w_rad << " " << w_col << endl;
- }
- // Your code goes above this line.
- // Don't change the implementations below!
- istream& operator >> (istream& ins, Circle& circle)
- {
- circle.read(ins);
- return ins;
- }
- ostream& operator << (ostream& outs, Circle circle)
- {
- circle.write(outs);
- return outs;
- }
- void Circle::draw(Graphics & drawer)
- {
- int radius = min(getRadius(), (int)DIMENSION);
- int error = -radius;
- int x = radius;
- int y = 0;
- Color c = getColor();
- while (x >= y)
- {
- plot8points(x, y, c, drawer);
- error += y;
- ++y;
- error += y;
- if (error >= 0)
- {
- error -= x;
- --x;
- error -= x;
- }
- }
- }
- int Circle::checkRadius(int radius)
- {
- if (radius < 0)
- {
- return -1 * radius;
- }
- return radius;
- }
- void Circle::plot8points(int x, int y, Color c, Graphics& drawer)
- {
- plot4points(x, y, c, drawer);
- if (x != y) plot4points(y, x, c, drawer);
- }
- void Circle::plot4points(int x, int y, Color c, Graphics& drawer)
- {
- // cx and cy denote the offset of the circle center from the origin.
- int cx = getCenter().getX();
- int cy = getCenter().getY();
- Point pt1Start(cx - x, cy + y);
- Point pt1End(cx + x, cy + y);
- Line line1(pt1Start, pt1End, c);
- line1.draw(drawer);
- Point pt2Start(cx - x, cy - y);
- Point pt2End(cx + x, cy - y);
- Line line2(pt2Start, pt2End, c);
- line2.draw(drawer);
- }
Add Comment
Please, Sign In to add comment