#include using namespace std; /* New library ILI9341 for due by Marek Buriak http://marekburiak.github.io/ILI9341_due/ https://github.com/marekburiak/ILI9341_due THx */ #include #include #include #include "fonts\Arial_bold_14.h" #define LCD_CS 10 #define LCD_DC 42 #define LCD_RST 43 ILI9341_due tft(LCD_CS, LCD_DC, LCD_RST); ILI9341_due_gText t1(&tft); char textBuff[20]; // Color set #define BLACK 0x0000 #define RED 0xF800 #define GREEN 0x07E0 //#define BLUE 0x001F #define BLUE 0x102E #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define ORANGE 0xFD20 #define GREENYELLOW 0xAFE5 #define DARKGREEN 0x03E0 #define WHITE 0xFFFF //uint16_t color; uint8_t color; // instead of uint16_t #define MAX_ITERATION 142 #define SCREEN_X_MAX 320 #define SCREEN_Y_MAX 240 const float X0 = -2.5; const float Y0 = -1; const float X1 = 1; const float Y1 = 1; //Color set const byte cmap[]={0b00000000,0b11100000,0b11100100,0b11101000,0b11101100,0b11110000,0b11110100,0b11111000,0b11111100, 0b11011100,0b10111100,0b10011100,0b01111100,0b01011100,0b00111100,0b00011100,0b00011101,0b00011110, 0b00011111,0b00011011,0b00010111,0b00010011,0b00001111,0b00001011,0b00000111,0b00000011,0b00100011, 0b01000011,0b01100011,0b10000011,0b10100011,0b11000011,0b11100011,0b11100010,0b11100001,0b11100000,0b00000000}; void setup() { Serial.begin(9600); tft.begin(); //tft.fillScreen(BLUE); tft.setRotation(3); GradienteVCc(0,0,320,240, 0, 0, 255); t1.defineArea(0, 0, 320, 240); t1.selectFont(Arial_bold_14); t1.setFontLetterSpacing(5); t1.setFontColor(ILI9341_WHITE, tft.color565(0,0,255)); t1.drawString("Fractal", 0,5); delay(1000); Serial.println("Mandelbrot generator"); unsigned long stime = millis(); drawmandelbrot(X0, Y0, X1, Y1); Serial.print("Drawing time : "); Serial.println(millis() - stime); } void loop() { } // Fractal code source: http://skyduino.wordpress.com/2012/08/25/arduinogenerique-generateur-de-fractale-de-mandelbrot/ void drawmandelbrot(const float x0, const float y0, const float x1, const float y1) { for(uint16_t x = 0; x < SCREEN_X_MAX; ++x) { float sx = x * (x1 - x0) / SCREEN_X_MAX + x0; for(uint16_t y = 0; y < SCREEN_Y_MAX; ++y) { float sy = y * (y1 - y0) / SCREEN_Y_MAX + y0; float z_r = 0, z_i = 0; uint16_t i = 0; do { float tmp = z_r * z_r - z_i * z_i + sx; z_i = 2 * z_r * z_i + sy; z_r = tmp; ++i; } while((z_r * z_r + z_i * z_i) < 4 && i < MAX_ITERATION); color = cmap[sizeof(cmap)-i]; tft.drawPixel(x, y, (i == MAX_ITERATION) ? 0x0000 : tft.color565(255-color,0, 0)); //Red-Black-Black } } } // Vertical gradient: up (0%) to down (100%) void GradienteVcC(int X1, int Y1, int X2, int Y2, int Color1R, int Color1G, int Color1B) { int Gradiente1; Color1R = Color1R*10; Color1G = Color1G*10; Color1B = Color1B*10; // for (int i=0; i<=Y2-Y1; i++) { Gradiente1 = 1000 * i/(Y2 - Y1); tft.drawFastHLine(X1, Y1+i, X2-X1, tft.color565(Color1R*Gradiente1/10000, Color1G*Gradiente1/10000, Color1B*Gradiente1/10000)); } } // Vertical gradient: up (100%) to down (0%) void GradienteVCc(int X1, int Y1, int X2, int Y2, int Color1R, int Color1G, int Color1B) { int Gradiente1; Color1R = Color1R*10; Color1G = Color1G*10; Color1B = Color1B*10; // for (int i=0; i<=Y2-Y1; i++) { Gradiente1 = 1000 * ((Y2 - Y1)-i)/(Y2 - Y1); tft.drawFastHLine(X1, Y1+i, X2-X1, tft.color565(Color1R*Gradiente1/10000, Color1G*Gradiente1/10000, Color1B*Gradiente1/10000)); } }