diff --git a/src/mode.cpp b/src/mode.cpp
index 2afebcc..3e5945b 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -7,6 +7,7 @@
#include "mode/SpaceInvaders/SpaceInvaders.h"
#include "mode/NewYear/NewYear.h"
#include "mode/Starfield/Starfield.h"
+#include "mode/Matrix/Matrix.h"
#include "display.h"
ModeId currentModeId = NONE;
@@ -89,6 +90,9 @@ void loadNewMode() {
case STARFIELD:
mode = new Starfield(display);
break;
+ case MATRIX:
+ mode = new Matrix(display);
+ break;
default:
Serial.print("No mode loaded.\n");
display.clear();
diff --git a/src/mode/Matrix/Matrix.h b/src/mode/Matrix/Matrix.h
new file mode 100644
index 0000000..b2af1a4
--- /dev/null
+++ b/src/mode/Matrix/Matrix.h
@@ -0,0 +1,65 @@
+#ifndef MODE_MATRIX_H
+#define MODE_MATRIX_H
+
+#include "mode/Mode.h"
+
+class Matrix : public Mode {
+
+private:
+
+ struct Glyph {
+ double x;
+ double y;
+ double velocity = 0;
+ uint8_t length = 0;
+ };
+
+ Glyph glyphs[10];
+
+public:
+
+ explicit Matrix(Display &display) :
+ Mode(display) {
+ for (auto &glyph: glyphs) {
+ resetGlyph(glyph);
+ }
+ }
+
+ void resetGlyph(Glyph &glyph) const {
+ glyph.x = random(width);
+ glyph.y = 0;
+ glyph.velocity = (random(20) + 5);
+ glyph.length = random(8) + 2;
+ }
+
+ const char *getName() override {
+ return "Matrix";
+ }
+
+protected:
+
+ void step(microseconds_t microseconds) override {
+ for (auto &glyph: glyphs) {
+ glyph.y += glyph.velocity * (double) microseconds / 1000000.0;
+ if (glyph.y - glyph.length >= height) {
+ resetGlyph(glyph);
+ }
+ }
+ markDirty();
+ }
+
+ void draw(Display &display) override {
+ display.clear();
+ for (auto &glyph: glyphs) {
+ for (int i = 0; i < glyph.length; ++i) {
+ display.set((int) round(glyph.x), (int) round(glyph.y - i), {64, 128, 64});
+ }
+ if (((int) round(glyph.y) + glyph.length) % 2 == 0) {
+ display.set((int) round(glyph.x), (int) round(glyph.y), {0, 255, 0});
+ }
+ }
+ }
+
+};
+
+#endif
diff --git a/src/mode/Mode.h b/src/mode/Mode.h
index 8628c32..e5c98ef 100644
--- a/src/mode/Mode.h
+++ b/src/mode/Mode.h
@@ -16,6 +16,7 @@ enum ModeId {
SPACE_INVADERS,
NEW_YEAR,
STARFIELD,
+ MATRIX,
};
class Mode {
diff --git a/src/mode/Starfield/Starfield.h b/src/mode/Starfield/Starfield.h
index c2e5c56..2caaf51 100644
--- a/src/mode/Starfield/Starfield.h
+++ b/src/mode/Starfield/Starfield.h
@@ -3,15 +3,13 @@
#include "mode/Mode.h"
-#define STAR_COUNT 20
-
class Starfield : public Mode {
private:
Vector center;
- Vector stars[STAR_COUNT];
+ Vector stars[20];
public:
diff --git a/src/serial.cpp b/src/serial.cpp
index f1fef88..f5ded6a 100644
--- a/src/serial.cpp
+++ b/src/serial.cpp
@@ -26,6 +26,7 @@ void serial_loop() {
setMode((ModeId) (input - '0'));
break;
case 'a':
+ case 'b':
setMode((ModeId) (input - 'a' + 10));
break;
case 'r':
diff --git a/src/server.cpp b/src/server.cpp
index c89d329..e36773a 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -60,6 +60,7 @@ void web_index() {
server.sendContent(R"(SPACE_INVADERS
)");
server.sendContent(R"(NEW_YEAR
)");
server.sendContent(R"(STARFIELD
)");
+ server.sendContent(R"(MATRIX
)");
server.sendContent(R"(Helligkeit: + / -
)");
server.sendContent(R"(Geschwindigkeit: + / -
)");