ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18lg

Dependencies:   mbed

Committer:
el18lg
Date:
Sat May 23 17:21:24 2020 +0000
Revision:
1:bdafa20e71a0
Started my map, making my way onto my snake programme;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18lg 1:bdafa20e71a0 1 #ifndef BITMAP_H
el18lg 1:bdafa20e71a0 2 #define BITMAP_H
el18lg 1:bdafa20e71a0 3
el18lg 1:bdafa20e71a0 4 #include <vector>
el18lg 1:bdafa20e71a0 5
el18lg 1:bdafa20e71a0 6 // Forward declarations
el18lg 1:bdafa20e71a0 7 class N5110;
el18lg 1:bdafa20e71a0 8
el18lg 1:bdafa20e71a0 9 /**
el18lg 1:bdafa20e71a0 10 * @brief A black & white bitmap that can be rendered on an N5110 screen
el18lg 1:bdafa20e71a0 11 * @author Alex Valavanis <a.valavanis@leeds.ac.uk>
el18lg 1:bdafa20e71a0 12 *
el18lg 1:bdafa20e71a0 13 * @code
el18lg 1:bdafa20e71a0 14 // First declare the pixel map data using '1' for black,
el18lg 1:bdafa20e71a0 15 // or '0' for white pixels
el18lg 1:bdafa20e71a0 16 static int sprite_data[] = {
el18lg 1:bdafa20e71a0 17 0,0,1,0,0,
el18lg 1:bdafa20e71a0 18 0,1,1,1,0,
el18lg 1:bdafa20e71a0 19 0,0,1,0,0,
el18lg 1:bdafa20e71a0 20 0,1,1,1,0,
el18lg 1:bdafa20e71a0 21 1,1,1,1,1,
el18lg 1:bdafa20e71a0 22 1,1,1,1,1,
el18lg 1:bdafa20e71a0 23 1,1,0,1,1,
el18lg 1:bdafa20e71a0 24 1,1,0,1,1
el18lg 1:bdafa20e71a0 25 };
el18lg 1:bdafa20e71a0 26
el18lg 1:bdafa20e71a0 27 // Instantiate the Bitmap object using the data above
el18lg 1:bdafa20e71a0 28 Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite
el18lg 1:bdafa20e71a0 29
el18lg 1:bdafa20e71a0 30 // We can render the bitmap wherever we want on the screen
el18lg 1:bdafa20e71a0 31 sprite.render(lcd, 20, 6); // x and y locations for rendering
el18lg 1:bdafa20e71a0 32 sprite.render(lcd, 30, 10);
el18lg 1:bdafa20e71a0 33
el18lg 1:bdafa20e71a0 34 // We can also print its values to the terminal
el18lg 1:bdafa20e71a0 35 sprite.print();
el18lg 1:bdafa20e71a0 36 * @endcode
el18lg 1:bdafa20e71a0 37 */
el18lg 1:bdafa20e71a0 38 class Bitmap
el18lg 1:bdafa20e71a0 39 {
el18lg 1:bdafa20e71a0 40 private:
el18lg 1:bdafa20e71a0 41 /**
el18lg 1:bdafa20e71a0 42 * @brief The contents of the drawing, with pixels stored in row-major order
el18lg 1:bdafa20e71a0 43 * @details '1' represents a black pixel; '0' represents white
el18lg 1:bdafa20e71a0 44 */
el18lg 1:bdafa20e71a0 45 std::vector<int> _contents;
el18lg 1:bdafa20e71a0 46
el18lg 1:bdafa20e71a0 47 unsigned int _height; ///< The height of the drawing in pixels
el18lg 1:bdafa20e71a0 48 unsigned int _width; ///< The width of the drawing in pixels
el18lg 1:bdafa20e71a0 49
el18lg 1:bdafa20e71a0 50 public:
el18lg 1:bdafa20e71a0 51 Bitmap(int const *contents,
el18lg 1:bdafa20e71a0 52 unsigned int const height,
el18lg 1:bdafa20e71a0 53 unsigned int const width);
el18lg 1:bdafa20e71a0 54
el18lg 1:bdafa20e71a0 55 int get_pixel(unsigned int const row,
el18lg 1:bdafa20e71a0 56 unsigned int const column) const;
el18lg 1:bdafa20e71a0 57
el18lg 1:bdafa20e71a0 58 void print() const;
el18lg 1:bdafa20e71a0 59
el18lg 1:bdafa20e71a0 60 void render(N5110 &lcd,
el18lg 1:bdafa20e71a0 61 unsigned int const x0,
el18lg 1:bdafa20e71a0 62 unsigned int const y0) const;
el18lg 1:bdafa20e71a0 63 };
el18lg 1:bdafa20e71a0 64
el18lg 1:bdafa20e71a0 65 #endif // BITMAP_H