Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program displays a Mandelbrot calculation in a circular zoomed-in sequence.

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Fri Oct 03 13:21:52 2014 +0000
Revision:
0:e24e3d741c52
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:e24e3d741c52 1
embeddedartists 0:e24e3d741c52 2 #ifndef MANDELBDEMO_H
embeddedartists 0:e24e3d741c52 3 #define MANDELBDEMO_H
embeddedartists 0:e24e3d741c52 4
embeddedartists 0:e24e3d741c52 5 #include "Graphics.h"
embeddedartists 0:e24e3d741c52 6 #include "GFXFb.h"
embeddedartists 0:e24e3d741c52 7 #include "EaLcdBoardGPIO.h"
embeddedartists 0:e24e3d741c52 8
embeddedartists 0:e24e3d741c52 9 class MandelbDemo : public Graphics {
embeddedartists 0:e24e3d741c52 10 public:
embeddedartists 0:e24e3d741c52 11
embeddedartists 0:e24e3d741c52 12 typedef struct
embeddedartists 0:e24e3d741c52 13 {
embeddedartists 0:e24e3d741c52 14 uint8_t xx;
embeddedartists 0:e24e3d741c52 15 uint8_t yy;
embeddedartists 0:e24e3d741c52 16 uint8_t rr;
embeddedartists 0:e24e3d741c52 17 uint8_t skip;
embeddedartists 0:e24e3d741c52 18 } Coord_t;
embeddedartists 0:e24e3d741c52 19
embeddedartists 0:e24e3d741c52 20 /** Set the address of the frame buffer to use.
embeddedartists 0:e24e3d741c52 21 *
embeddedartists 0:e24e3d741c52 22 * It is the content of the frame buffer that is shown on the
embeddedartists 0:e24e3d741c52 23 * display. All the drawing on the frame buffer can be done
embeddedartists 0:e24e3d741c52 24 * 'offline' and whenever it should be shown this function
embeddedartists 0:e24e3d741c52 25 * can be called with the address of the offline frame buffer.
embeddedartists 0:e24e3d741c52 26 *
embeddedartists 0:e24e3d741c52 27 * @param pFrameBuf Pointer to the frame buffer, which must be
embeddedartists 0:e24e3d741c52 28 * 3 times as big as the frame size (for tripple
embeddedartists 0:e24e3d741c52 29 * buffering).
embeddedartists 0:e24e3d741c52 30 * dispWidth The width of the display (in pixels).
embeddedartists 0:e24e3d741c52 31 * dispHeight The height of the display (in pixels).
embeddedartists 0:e24e3d741c52 32 * loops Number of loops in the demo code.
embeddedartists 0:e24e3d741c52 33 * delayMs Delay in milliseconds between schreen updates.
embeddedartists 0:e24e3d741c52 34 *
embeddedartists 0:e24e3d741c52 35 * @returns
embeddedartists 0:e24e3d741c52 36 * none
embeddedartists 0:e24e3d741c52 37 */
embeddedartists 0:e24e3d741c52 38 MandelbDemo(uint8_t *pFrameBuf, uint16_t dispWidth, uint16_t dispHeight);
embeddedartists 0:e24e3d741c52 39
embeddedartists 0:e24e3d741c52 40 void run(EaLcdBoardGPIO& lcdBoard, uint32_t loops, uint32_t delayMs);
embeddedartists 0:e24e3d741c52 41
embeddedartists 0:e24e3d741c52 42 protected:
embeddedartists 0:e24e3d741c52 43 virtual void plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t doMandel );
embeddedartists 0:e24e3d741c52 44
embeddedartists 0:e24e3d741c52 45 private:
embeddedartists 0:e24e3d741c52 46
embeddedartists 0:e24e3d741c52 47 enum Constants {
embeddedartists 0:e24e3d741c52 48 UPDATE_ZONE_COLOR = 0x39e7, //DARK_GRAY
embeddedartists 0:e24e3d741c52 49
embeddedartists 0:e24e3d741c52 50 // Width and Height of Mandelbrot (which will be a square)
embeddedartists 0:e24e3d741c52 51 MANDEL_WIDTH = 250,
embeddedartists 0:e24e3d741c52 52 MANDEL_HEIGHT = MANDEL_WIDTH,
embeddedartists 0:e24e3d741c52 53
embeddedartists 0:e24e3d741c52 54 // Number of iterations before the Mandelbrot function stops
embeddedartists 0:e24e3d741c52 55 MAXITERATIONS = 256
embeddedartists 0:e24e3d741c52 56 };
embeddedartists 0:e24e3d741c52 57
embeddedartists 0:e24e3d741c52 58 int32_t windowX;
embeddedartists 0:e24e3d741c52 59 int32_t windowY;
embeddedartists 0:e24e3d741c52 60 uint16_t *pFrmBuf;
embeddedartists 0:e24e3d741c52 61 uint16_t *pFrmBuf1;
embeddedartists 0:e24e3d741c52 62 uint16_t *pFrmBuf2;
embeddedartists 0:e24e3d741c52 63 uint16_t *pFrmBuf3;
embeddedartists 0:e24e3d741c52 64
embeddedartists 0:e24e3d741c52 65 //Graphics graphics;
embeddedartists 0:e24e3d741c52 66
embeddedartists 0:e24e3d741c52 67 // Color mapping array
embeddedartists 0:e24e3d741c52 68 uint16_t cols[MAXITERATIONS + 1];
embeddedartists 0:e24e3d741c52 69
embeddedartists 0:e24e3d741c52 70 // Color of pixel to be plotted
embeddedartists 0:e24e3d741c52 71 uint32_t color;
embeddedartists 0:e24e3d741c52 72
embeddedartists 0:e24e3d741c52 73 // real and imaginary part of the pixel p
embeddedartists 0:e24e3d741c52 74 float pixel_real;
embeddedartists 0:e24e3d741c52 75 float pixel_imag;
embeddedartists 0:e24e3d741c52 76
embeddedartists 0:e24e3d741c52 77 //real and imaginary parts of new and old z
embeddedartists 0:e24e3d741c52 78 float newReal;
embeddedartists 0:e24e3d741c52 79 float newImag;
embeddedartists 0:e24e3d741c52 80 float oldReal;
embeddedartists 0:e24e3d741c52 81 float oldImag;
embeddedartists 0:e24e3d741c52 82
embeddedartists 0:e24e3d741c52 83 // Zoom and position within image
embeddedartists 0:e24e3d741c52 84 float zoom;
embeddedartists 0:e24e3d741c52 85 float moveX;
embeddedartists 0:e24e3d741c52 86 float moveY;
embeddedartists 0:e24e3d741c52 87
embeddedartists 0:e24e3d741c52 88 // For loop counters
embeddedartists 0:e24e3d741c52 89 // int x;
embeddedartists 0:e24e3d741c52 90 // int y;
embeddedartists 0:e24e3d741c52 91
embeddedartists 0:e24e3d741c52 92 uint32_t iterate( int32_t x, int32_t y );
embeddedartists 0:e24e3d741c52 93
embeddedartists 0:e24e3d741c52 94 unsigned short qsqrt(unsigned long a) const;
embeddedartists 0:e24e3d741c52 95 };
embeddedartists 0:e24e3d741c52 96
embeddedartists 0:e24e3d741c52 97 #endif /* MANDELBDEMO_H */
embeddedartists 0:e24e3d741c52 98