Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17ajf by
Diff: Graphics/Graphics.cpp
- Revision:
- 28:e09b7ac11dea
- Parent:
- 26:baa7077449e7
- Child:
- 29:d59fbe128d1f
--- a/Graphics/Graphics.cpp Fri Apr 05 17:16:59 2019 +0000 +++ b/Graphics/Graphics.cpp Fri Apr 12 20:53:00 2019 +0000 @@ -3,27 +3,30 @@ namespace Graphics { + // "private" methods + void drawPoint(int x, int y); + void drawLine(int x1, int y1, int x2, int y2); + void drawBox(int x1, int y1, int x2, int y2); + void drawDottedLine(int x1, int y1, int x2, int y2); + bool lightOn; + + int shake_frames; + int offsetX = 0, offsetY = 0; + namespace LCD { const int MAX_Y = 47; N5110 * lcd; int YToLcdX(int y) { - return y; + return y + offsetX; } int XToLcdY(int x) { - return MAX_Y - x; + return MAX_Y - x + offsetY; } }; - // "private" methods - void drawPoint(int x, int y); - void drawLine(int x1, int y1, int x2, int y2); - void drawBox(int x1, int y1, int x2, int y2); - void drawDottedLine(int x1, int y1, int x2, int y2); - bool lightOn; - void init() { LCD::lcd = new N5110(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); LCD::lcd->init(); @@ -41,6 +44,14 @@ } void render() { + if (shake_frames > 0) { + offsetX = (rand() % 8) - 4; + offsetY = (rand() % 8) - 4; + } else { + offsetX = 0; + offsetY = 0; + } + shake_frames = shake_frames > 0 ? shake_frames - 1 : shake_frames; LCD::lcd->refresh(); } @@ -136,6 +147,12 @@ drawDottedLine(minX, maxY, maxX, maxY); drawDottedLine(maxX, maxY, maxX, minY); } + + void shake(int frames) { + if (frames > shake_frames) { + shake_frames = frames; + } + } }; namespace UI {