From 0bd4c9e51ce62ec2ee1629977b8857b799b5ff99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Skaaden?= Date: Tue, 26 Feb 2019 19:54:17 +0100 Subject: [PATCH] Finished Oving 7 --- Oving 7/Oving 7/Emoji.cpp | 31 +++++++++++++++++++++++++++---- Oving 7/Oving 7/Emoji.h | 10 ++++++++++ Oving 7/Oving 7/main.cpp | 33 ++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Oving 7/Oving 7/Emoji.cpp b/Oving 7/Oving 7/Emoji.cpp index b34cfef..4e74a9e 100644 --- a/Oving 7/Oving 7/Emoji.cpp +++ b/Oving 7/Oving 7/Emoji.cpp @@ -19,10 +19,8 @@ void Face::attach_to(Graph_lib::Window& win) #pragma region EmptyFace 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 } + leftEye{ Point{ p.x - r / 2, p.y - r / 8 }, r / 10 }, + rightEye{ Point { p.x + r / 2, p.y - r / 8 }, r / 10 } { leftEye.set_fill_color(Color::black); @@ -76,6 +74,7 @@ void SadFace::attach_to(Graph_lib::Window & win) #pragma endregion + #pragma region AngryFace AngryFace::AngryFace(Point p, int r) : EmptyFace{ p,r }, @@ -104,6 +103,7 @@ void AngryFace::attach_to(Graph_lib::Window & win) #pragma endregion + #pragma region WinkingFace WinkingFace::WinkingFace(Point p, int r) : Face(p, r), @@ -136,3 +136,26 @@ void WinkingFace::attach_to(Graph_lib::Window & win) #pragma endregion +AwkwardFace::AwkwardFace(Point p, int r) : Face{p, r}, + leftEye{Point{p.x - 4 * r / 5, p.y}, r / 10}, + rightEye{Point{p.x + 4 * r / 5, p.y}, r / 10} +{ + leftEye.set_fill_color(Color::black); + rightEye.set_fill_color(Color::black); + + leftEye.set_color(Color::black); + rightEye.set_color(Color::black); + + mouth.add(Point{ p.x - r / 2, p.y + r / 25 }); + mouth.add(Point{ p.x + r / 2, p.y + r / 25 }); + mouth.set_color(Color::black); + mouth.set_style(Line_style(Line_style::solid, 3)); +} + +void AwkwardFace::attach_to(Graph_lib::Window & win) +{ + Face::attach_to(win); + win.attach(leftEye); + win.attach(rightEye); + win.attach(mouth); +} diff --git a/Oving 7/Oving 7/Emoji.h b/Oving 7/Oving 7/Emoji.h index c8180bf..2911442 100644 --- a/Oving 7/Oving 7/Emoji.h +++ b/Oving 7/Oving 7/Emoji.h @@ -100,4 +100,14 @@ private: Open_polyline wink; int x1,x2; int y1, y2, y3; +}; + +class AwkwardFace : public Face +{ +public: + AwkwardFace(Point p, int r); + void attach_to(Graph_lib::Window& win) override; +private: + Circle leftEye, rightEye; + Open_polyline mouth; }; \ No newline at end of file diff --git a/Oving 7/Oving 7/main.cpp b/Oving 7/Oving 7/main.cpp index 383b26c..5b93276 100644 --- a/Oving 7/Oving 7/main.cpp +++ b/Oving 7/Oving 7/main.cpp @@ -2,9 +2,11 @@ #include "Emoji.h" // Size of window and emoji radius -constexpr int xmax = 1000; -constexpr int ymax = 600; -constexpr int emojiRadius = 100; +constexpr int xmax = 750; +constexpr int ymax = 200; +constexpr int emojiRadius = 50; + +void DrawEmojies(Vector_ref& emojis, Graph_lib::Window& win); int main() { @@ -13,14 +15,23 @@ int main() const Point tl{100, 100}; const string win_label{"Emoji factory"}; Simple_window win{tl, xmax, ymax, win_label}; - AngryFace face(Point{ 200, 200 }, emojiRadius); - - face.attach_to(win); - - /* TODO: - * - initialize emojis - * - connect emojis to window - **/ + Vector_ref emoji; + emoji.push_back(new EmptyFace(Point{ 100, 100 }, emojiRadius)); + emoji.push_back(new SmileyFace(Point{ 210, 100 }, emojiRadius)); + emoji.push_back(new SadFace(Point{ 320, 100 }, emojiRadius)); + emoji.push_back(new AngryFace(Point{ 430, 100 }, emojiRadius)); + emoji.push_back(new WinkingFace(Point{ 540, 100 }, emojiRadius)); + emoji.push_back(new AwkwardFace(Point{ 650, 100 }, emojiRadius)); + + DrawEmojies(emoji, win); win.wait_for_button(); } + +void DrawEmojies(Vector_ref& emojis, Graph_lib::Window & win) +{ + for (const auto e : emojis) + { + e->attach_to(win); + } +}