From 9fe739f5c171467c9269a8aad520a8ee5017693a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sat, 14 Jan 2023 17:50:58 +0100 Subject: [PATCH] WIP Starfield moving center --- src/mode/Starfield/Starfield.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/mode/Starfield/Starfield.h b/src/mode/Starfield/Starfield.h index 2caaf51..a538262 100644 --- a/src/mode/Starfield/Starfield.h +++ b/src/mode/Starfield/Starfield.h @@ -9,13 +9,16 @@ private: Vector center; + Vector centerNext; + Vector stars[20]; public: explicit Starfield(Display &display) : Mode(display), - center(width / 2.0, height / 2.0) { + center(width / 2.0, height / 2.0), + centerNext(center.x, center.y) { for (auto &star: stars) { star.x = random(width); star.y = random(height); @@ -29,6 +32,7 @@ public: protected: void step(microseconds_t microseconds) override { + stepCenter(); for (auto &star: stars) { const Vector velocity = star.minus(center).multiply((double) microseconds / 200000.0); star = star.plus(velocity); @@ -41,6 +45,25 @@ protected: markDirty(); } + void stepCenter() { + // TODO moving center overtakes moving stars (less stars in direction of moving center) +// Vector diff = centerNext.minus(center); +// if (diff.length < 0.01) { +// centerNext = Vector(random(width), random(height)); +// } else { +// if (diff.x >= 0) { +// center.x += min(0.1, diff.x); +// } else { +// center.x += max(-0.1, diff.x); +// } +// if (diff.y >= 0) { +// center.y += min(0.1, diff.y); +// } else { +// center.y += max(-0.1, diff.y); +// } +// } + } + void draw(Display &display) override { display.clear(); for (auto &star: stars) {