1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
// Osman Zakir
// 5 / 8 / 2017
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 13 Exercise 1
// Exercise Specifications:
/**
* Define a class Arc , which draws a part of an ellipse. Hint: fl_arc().
*/
#include "../../cust_std_lib_facilities.h"
#include "../../Graph.h"
#include "../../Simple_window.h"
namespace Graph_lib
{
struct Arc : Shape
{
Arc::Arc(double r, Graph_lib::Point p, double start_deg, double end_deg)
: m_r{ r }, m_p{ p }, m_start_deg{ start_deg }, m_end_deg{ end_deg }
{
add(Graph_lib::Point{ int(m_p.x - m_r), int(m_p.y - m_r) });
}
void draw_lines() const;
double get_radius() const { return m_r; }
Graph_lib::Point get_point() const { return m_p; }
double set_start_deg(double theta) { m_start_deg = theta; }
double set_end_deg(double theta) { m_end_deg = theta; }
private:
double m_r;
Graph_lib::Point m_p;
double m_start_deg;
double m_end_deg;
};
}
int main()
{
using namespace Graph_lib;
constexpr int win_x = 100, win_y = 100;
constexpr int win_width = 600, win_height = 400;
Simple_window win{ Point{win_x, win_y}, win_width, win_height, "Arc" };
const double radius1 = 100.0;
const int arc1_x = 200, arc1_y = 200;
const double start_theta = 0, end_theta = 180;
Graph_lib::Arc arc1{ radius1, Point{arc1_x, arc1_y}, start_theta, end_theta };
arc1.set_color(Color::black);
win.attach(arc1);
const double radius2 = 100.0;
const int arc2_x = 250, arc2_y = 300;
const double start_theta2 = 0, end_theta2 = 75;
Graph_lib::Arc arc2{ radius2, Point{arc2_x, arc2_y}, start_theta2, end_theta2 };
arc2.set_color(Color::black);
win.attach(arc2);
win.wait_for_button();
}
void Arc::draw_lines() const
{
using namespace Graph_lib;
if (color().visibility())
{
fl_arc(point(0).x, point(0).y, int(m_r + m_r), int(m_r + m_r), m_start_deg, m_end_deg);
}
}
|