From 62b10ca8d053f9f7f07620ff9131f02336236476 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 27 Oct 2025 11:21:58 +0100 Subject: [PATCH] Implement correct size_changed() behaviour --- modules/Polygon/Polygon.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/modules/Polygon/Polygon.cpp b/modules/Polygon/Polygon.cpp index e3e7d3b..254fe21 100644 --- a/modules/Polygon/Polygon.cpp +++ b/modules/Polygon/Polygon.cpp @@ -1,7 +1,6 @@ #include "Polygon.hpp" #include #include -#include #include #include @@ -18,10 +17,10 @@ public: ~Polygon() = default; void configure() override; - int fps() const override; void update() override; void render() override; std::string version() const override; + void size_changed() override; private: int _num_points {}; @@ -29,7 +28,7 @@ private: double _max_speed {2.0}; double _stroke_width {1.0}; Color _stroke_color {"#FFFFFF"}; - Color _fill_color {"#006600"}; + Color _fill_color {"#606060"}; std::vector _points; }; @@ -44,19 +43,24 @@ void Polygon::configure() { _fill_color = _j["fill-color"]; for (int i = 0; i < _num_points; ++i) { Point p; - p.x = sc::random::double_between(0, _r.width); - p.y = sc::random::double_between(0, _r.height); - p.speed_x = sc::random::double_between(_min_speed, _max_speed); - p.speed_x *= sc::random::boolean() ? 1 : -1; - p.speed_y = sc::random::double_between(_min_speed, _max_speed); - p.speed_y *= sc::random::boolean() ? 1 : -1; + p.x = random_x(); + p.y = random_y(); + p.speed_x = random_between(_min_speed, _max_speed); + p.speed_x *= random_bool() ? 1 : -1; + p.speed_y = random_between(_min_speed, _max_speed); + p.speed_y *= random_bool() ? 1 : -1; _points.push_back(p); } } -std::string Polygon::version() const { return "1.0.0"; } +void Polygon::size_changed() { + for (Point &p : _points) { + p.x = random_x(); + p.y = random_y(); + } +} -int Polygon::fps() const { return 30; } +std::string Polygon::version() const { return "1.0.0"; } void Polygon::update() { for (Point& p : _points) {