Matrix
This commit is contained in:
parent
497daf6776
commit
c0f5b52a36
@ -7,6 +7,7 @@
|
|||||||
#include "mode/SpaceInvaders/SpaceInvaders.h"
|
#include "mode/SpaceInvaders/SpaceInvaders.h"
|
||||||
#include "mode/NewYear/NewYear.h"
|
#include "mode/NewYear/NewYear.h"
|
||||||
#include "mode/Starfield/Starfield.h"
|
#include "mode/Starfield/Starfield.h"
|
||||||
|
#include "mode/Matrix/Matrix.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
ModeId currentModeId = NONE;
|
ModeId currentModeId = NONE;
|
||||||
@ -89,6 +90,9 @@ void loadNewMode() {
|
|||||||
case STARFIELD:
|
case STARFIELD:
|
||||||
mode = new Starfield(display);
|
mode = new Starfield(display);
|
||||||
break;
|
break;
|
||||||
|
case MATRIX:
|
||||||
|
mode = new Matrix(display);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.print("No mode loaded.\n");
|
Serial.print("No mode loaded.\n");
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|||||||
65
src/mode/Matrix/Matrix.h
Normal file
65
src/mode/Matrix/Matrix.h
Normal 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
|
||||||
@ -16,6 +16,7 @@ enum ModeId {
|
|||||||
SPACE_INVADERS,
|
SPACE_INVADERS,
|
||||||
NEW_YEAR,
|
NEW_YEAR,
|
||||||
STARFIELD,
|
STARFIELD,
|
||||||
|
MATRIX,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mode {
|
class Mode {
|
||||||
|
|||||||
@ -3,15 +3,13 @@
|
|||||||
|
|
||||||
#include "mode/Mode.h"
|
#include "mode/Mode.h"
|
||||||
|
|
||||||
#define STAR_COUNT 20
|
|
||||||
|
|
||||||
class Starfield : public Mode {
|
class Starfield : public Mode {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Vector center;
|
Vector center;
|
||||||
|
|
||||||
Vector stars[STAR_COUNT];
|
Vector stars[20];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ void serial_loop() {
|
|||||||
setMode((ModeId) (input - '0'));
|
setMode((ModeId) (input - '0'));
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
|
case 'b':
|
||||||
setMode((ModeId) (input - 'a' + 10));
|
setMode((ModeId) (input - 'a' + 10));
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
|||||||
@ -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=8">SPACE_INVADERS</a><br>)");
|
||||||
server.sendContent(R"(<a href="/mode?mode=9">NEW_YEAR</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=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"(Helligkeit: <a href="/brighter">+</a> / <a href="/darker">-</a><br>)");
|
||||||
server.sendContent(R"(Geschwindigkeit: <a href="/faster">+</a> / <a href="/slower">-</a><br>)");
|
server.sendContent(R"(Geschwindigkeit: <a href="/faster">+</a> / <a href="/slower">-</a><br>)");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user