This commit is contained in:
Patrick Haßel 2023-01-09 11:50:51 +01:00
parent 497daf6776
commit c0f5b52a36
6 changed files with 73 additions and 3 deletions

View File

@ -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();

65
src/mode/Matrix/Matrix.h Normal file
View File

@ -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

View File

@ -16,6 +16,7 @@ enum ModeId {
SPACE_INVADERS,
NEW_YEAR,
STARFIELD,
MATRIX,
};
class Mode {

View File

@ -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:

View File

@ -26,6 +26,7 @@ void serial_loop() {
setMode((ModeId) (input - '0'));
break;
case 'a':
case 'b':
setMode((ModeId) (input - 'a' + 10));
break;
case 'r':

View File

@ -60,6 +60,7 @@ void web_index() {
server.sendContent(R"(<a href="/mode?mode=8">SPACE_INVADERS</a><br>)");
server.sendContent(R"(<a href="/mode?mode=9">NEW_YEAR</a><br>)");
server.sendContent(R"(<a href="/mode?mode=10">STARFIELD</a><br>)");
server.sendContent(R"(<a href="/mode?mode=11">MATRIX</a><br>)");
server.sendContent(R"(Helligkeit: <a href="/brighter">+</a> / <a href="/darker">-</a><br>)");
server.sendContent(R"(Geschwindigkeit: <a href="/faster">+</a> / <a href="/slower">-</a><br>)");