Oving 7 Done
parent
55ddeb17f9
commit
7ca45b26e5
|
@ -9,12 +9,6 @@ Face::Face(Point c, int r) : faceMask{c, r}
|
|||
{
|
||||
faceMask.set_fill_color(Color::yellow);
|
||||
faceMask.set_color(Color::black);
|
||||
/* TODO:
|
||||
* - add member initializer list
|
||||
* - implement the constructor. I.e. fill color
|
||||
**/
|
||||
|
||||
cout << "Not yet implemented\n";
|
||||
}
|
||||
|
||||
void Face::attach_to(Graph_lib::Window& win)
|
||||
|
@ -22,39 +16,123 @@ void Face::attach_to(Graph_lib::Window& win)
|
|||
win.attach(faceMask);
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
* - define more emojis.
|
||||
**/
|
||||
#pragma region EmptyFace
|
||||
|
||||
EmptyFace::EmptyFace(Point p, int r, bool upSideDown) : Face( p, r )
|
||||
EmptyFace::EmptyFace(Point p, int r) : Face(p, r),
|
||||
//leftEye{ Point{ p.x - int(sqrt(2) / 4 * r), p.y - int(sqrt(2) / 4 * r) }, r / 10 },
|
||||
//rightEye{ Point { p.x + int(sqrt(2) / 4 * r), p.y - int(sqrt(2) / 4 * r) }, r / 10 }
|
||||
leftEye{ Point{ p.x - r / 2, p.y - r / 2 }, r / 10 },
|
||||
rightEye{ Point { p.x + r / 2, p.y - r / 2 }, r / 10 }
|
||||
{
|
||||
int offset = int(1 / 4 * r * sqrt(2));
|
||||
if (upSideDown)
|
||||
offset *= -1;
|
||||
|
||||
int eyeR = r / 4;
|
||||
leftEye.set_fill_color(Color::black);
|
||||
rightEye.set_fill_color(Color::black);
|
||||
|
||||
Point left { p.x - offset, p.y - offset };
|
||||
Point right { p.x + offset, p.y - offset };
|
||||
|
||||
//Circle leftEye { left, eyeR };
|
||||
//Circle rightEye { right, eyeR };
|
||||
|
||||
//leftEye.set_fill_color(Color::black);
|
||||
//rightEye.set_fill_color(Color::black);
|
||||
|
||||
//eyes.push_back(leftEye);
|
||||
//eyes.push_back(rightEye);
|
||||
|
||||
|
||||
leftEye.set_color(Color::black);
|
||||
rightEye.set_color(Color::black);
|
||||
}
|
||||
|
||||
void EmptyFace::attach_to(Graph_lib::Window & win)
|
||||
{
|
||||
Face::attach_to(win);
|
||||
//win.attach(eyes[0]);
|
||||
Circle leftE{ left, eyeR };
|
||||
Circle rightE{ right, eyeR };
|
||||
win.attach(leftE);
|
||||
win.attach(rightE);
|
||||
win.attach(leftEye);
|
||||
win.attach(rightEye);
|
||||
}
|
||||
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region SmileyFace
|
||||
|
||||
SmileyFace::SmileyFace(Point p, int r) : EmptyFace{ p,r }, Smile{ Point{p.x, p.y + r / 10}, int(4 / 3 * r), r, 180, 360 }
|
||||
{
|
||||
Smile.set_color(Color::black);
|
||||
Smile.set_style(Line_style(Line_style::solid, 4));
|
||||
}
|
||||
|
||||
void SmileyFace::attach_to(Graph_lib::Window & win)
|
||||
{
|
||||
EmptyFace::attach_to(win);
|
||||
win.attach(Smile);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region SadFace
|
||||
|
||||
SadFace::SadFace(Point p, int r) : EmptyFace{ p,r }, Sad{ Point{p.x, p.y + r - r / 3}, int(4 / 3 * r), r, 0, 180 }
|
||||
{
|
||||
Sad.set_color(Color::black);
|
||||
Sad.set_style(Line_style(Line_style::solid, 4));
|
||||
}
|
||||
|
||||
void SadFace::attach_to(Graph_lib::Window & win)
|
||||
{
|
||||
EmptyFace::attach_to(win);
|
||||
win.attach(Sad);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region AngryFace
|
||||
|
||||
AngryFace::AngryFace(Point p, int r) : EmptyFace{ p,r },
|
||||
AngryOver{ Point{p.x, p.y + r - r / 3}, int(4 / 3 * r), r, 0, 180 },
|
||||
x1{3 * r / 5}, y1{ 4 * r / 5 },
|
||||
x2{r / 8}, y2{2 * r / 3},
|
||||
leftBrow{Point{p.x - x1, p.y - y1}, Point{p.x - x2, p.y - y2}},
|
||||
rightBrow{ Point{p.x + x1, p.y - y1}, Point{p.x + x2, p.y - y2} }
|
||||
{
|
||||
AngryOver.set_color(Color::black);
|
||||
AngryOver.set_style(Line_style(Line_style::solid, 4));
|
||||
leftBrow.set_color(Color::black);
|
||||
leftBrow.set_style(Line_style(Line_style::solid, 4));
|
||||
rightBrow.set_color(Color::black);
|
||||
rightBrow.set_style(Line_style(Line_style::solid, 4));
|
||||
}
|
||||
|
||||
|
||||
void AngryFace::attach_to(Graph_lib::Window & win)
|
||||
{
|
||||
EmptyFace::attach_to(win);
|
||||
win.attach(AngryOver);
|
||||
win.attach(leftBrow);
|
||||
win.attach(rightBrow);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region WinkingFace
|
||||
|
||||
WinkingFace::WinkingFace(Point p, int r) : Face(p, r),
|
||||
leftEye{ Point{ p.x - r / 2, p.y - r / 2 }, r / 10 },
|
||||
smile{ Point{p.x, p.y + r / 10}, int(4 / 3 * r), r, 180, 360 },
|
||||
x1{p.x + r / 6}, x2{p.x + 6* r / 10},
|
||||
y1{p.y - 7 * r / 10}, y2{ p.y - r / 2}, y3{ p.y - 3 * r / 10}
|
||||
{
|
||||
|
||||
leftEye.set_fill_color(Color::black);
|
||||
leftEye.set_color(Color::black);
|
||||
|
||||
smile.set_color(Color::black);
|
||||
smile.set_style(Line_style(Line_style::solid, 4));
|
||||
|
||||
wink.add(Point{ x2,y1 });
|
||||
wink.add(Point{ x1, y2 });
|
||||
wink.add(Point{ x2,y3 });
|
||||
wink.set_color(Color::black);
|
||||
wink.set_style(Line_style(Line_style::solid, 3));
|
||||
}
|
||||
|
||||
void WinkingFace::attach_to(Graph_lib::Window & win)
|
||||
{
|
||||
Face::attach_to(win);
|
||||
win.attach(leftEye);
|
||||
win.attach(smile);
|
||||
win.attach(wink);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
using namespace Graph_lib;
|
||||
|
||||
// An abstract class. Concrete classes derived from this base class
|
||||
// has to implement the member function attach_to().
|
||||
class Emoji
|
||||
{
|
||||
public:
|
||||
|
@ -22,18 +20,11 @@ public:
|
|||
Emoji(const Emoji&) = delete;
|
||||
Emoji& operator=(const Emoji&) = delete;
|
||||
|
||||
// Deleting the copy constructor also deletes the default constructor.
|
||||
// Emoji needs a default constructor.
|
||||
Emoji() {}
|
||||
// Emoji() = default; // is an alternative way of achieving the same.
|
||||
|
||||
// The pure virtual function that has to be overriden for a deriving class
|
||||
// to be instantiable. Every class deriving from Emoji is supposed to
|
||||
// attach all its Shapes to a window. This makes the class abstract.
|
||||
virtual void attach_to(Graph_lib::Window&) = 0;
|
||||
|
||||
// Relevant because Vector_ref can own Emojis and automatically cleans up.
|
||||
// Subject will be visited later in the course.
|
||||
|
||||
virtual ~Emoji() {}
|
||||
};
|
||||
|
||||
|
@ -41,30 +32,72 @@ public:
|
|||
// An abstract class.
|
||||
class Face : public Emoji
|
||||
{
|
||||
/* TODO:
|
||||
* - add shapes (private)
|
||||
* - make the class abstract
|
||||
**/
|
||||
|
||||
Circle faceMask;
|
||||
|
||||
public:
|
||||
Face(const Face&) = delete;
|
||||
Face& operator=(const Face&) = delete;
|
||||
virtual ~Face() {}
|
||||
|
||||
Face(Point c, int r);
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
|
||||
private:
|
||||
Circle faceMask;
|
||||
};
|
||||
|
||||
/* TODO:
|
||||
* - declare more emojis.
|
||||
**/
|
||||
|
||||
class EmptyFace : public Face
|
||||
{
|
||||
public:
|
||||
EmptyFace(Point p, int r, bool upSideDown = false);
|
||||
EmptyFace(Point p, int r);
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
private:
|
||||
int offset;
|
||||
int eyeR;
|
||||
Point left, right;
|
||||
Vector_ref<Circle> eyes;
|
||||
Circle leftEye;
|
||||
Circle rightEye;
|
||||
};
|
||||
|
||||
class SmileyFace : public EmptyFace
|
||||
{
|
||||
public:
|
||||
SmileyFace(Point p, int r);
|
||||
virtual ~SmileyFace() {};
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
private:
|
||||
Arc Smile;
|
||||
};
|
||||
|
||||
|
||||
class SadFace : public EmptyFace
|
||||
{
|
||||
public:
|
||||
SadFace(Point p, int r);
|
||||
virtual ~SadFace() {};
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
private:
|
||||
Arc Sad;
|
||||
};
|
||||
|
||||
class AngryFace : public EmptyFace
|
||||
{
|
||||
public:
|
||||
AngryFace(Point p, int r);
|
||||
virtual ~AngryFace() {};
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
private:
|
||||
int x1, y1;
|
||||
int x2, y2;
|
||||
Arc AngryOver;
|
||||
Line leftBrow, rightBrow;
|
||||
};
|
||||
|
||||
class WinkingFace : public Face
|
||||
{
|
||||
public:
|
||||
WinkingFace(Point p, int r);
|
||||
void attach_to(Graph_lib::Window& win) override;
|
||||
private:
|
||||
Circle leftEye;
|
||||
Arc smile;
|
||||
Open_polyline wink;
|
||||
int x1,x2;
|
||||
int y1, y2, y3;
|
||||
};
|
|
@ -4,7 +4,7 @@
|
|||
// Size of window and emoji radius
|
||||
constexpr int xmax = 1000;
|
||||
constexpr int ymax = 600;
|
||||
constexpr int emojiRadius = 50;
|
||||
constexpr int emojiRadius = 100;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -13,9 +13,9 @@ int main()
|
|||
const Point tl{100, 100};
|
||||
const string win_label{"Emoji factory"};
|
||||
Simple_window win{tl, xmax, ymax, win_label};
|
||||
EmptyFace eFace(Point{ 100, 100 }, emojiRadius);
|
||||
AngryFace face(Point{ 200, 200 }, emojiRadius);
|
||||
|
||||
eFace.attach_to(win);
|
||||
face.attach_to(win);
|
||||
|
||||
/* TODO:
|
||||
* - initialize emojis
|
||||
|
|
Loading…
Reference in New Issue