Several examples run on only mbed-os5.13.0 (not 5.14.0)

Dependencies:   BD_SD_DISCO_F769NI BSP_DISCO_F769NI LCD_DISCO_F769NI TS_DISCO_F769NI USBHost_F769NI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mandelbrot.cpp Source File

mandelbrot.cpp

00001 //------------------------------------------------------
00002 //  Class for drawing Mandelbrot set
00003 //  2015/11/03, Copyright (c) 2015 MIKAMI, Naoki
00004 //-----------------------------------------------------------
00005 // https://os.mbed.com/users/MikamiUitOpen/code/F746_Mandelbrot/
00006 //
00007 //      Modified by JH1PJL/K.Arai October 14th, 2019 for DISCO-F769NI
00008 
00009 #include "mandelbrot.hpp"
00010 
00011 namespace Mikami
00012 {
00013     void MandelbrotBase::Display(float x1, float x2, float y1, float y2)
00014     {
00015         x1_ = x1;
00016         y1_ = y1;
00017 
00018         ax_ = (x2 - x1)/(NX_ - 1);
00019         ay_ = (y2 - y1)/(NY_ - 1);
00020 
00021         for (int nx=0; nx<NX_; nx++)
00022             for (int ny=0; ny<NY_; ny++)
00023             {
00024                 uint32_t color = GetColor(Converge(Complex(Fx(nx), Fy(ny))));
00025                 LCD_->DrawPixel(X0_+nx, Y0_+ny, color);
00026             }
00027     }
00028 
00029     // discrimination of congergence
00030     int MandelbrotBase::Converge(Complex c)
00031     {
00032         Complex zn = 0;  // initial value
00033 
00034         for (int n=1; n<=MAX_COUNT_; n++)
00035         {
00036             zn = zn*zn + c;
00037             if ((Sqr(zn.real()) + Sqr(zn.imag())) > 4)
00038                 return(n);  // diverge
00039         }
00040         return 0;           // converge
00041     }
00042 
00043     // Get the color corresponding to the number of repititions (Color1)
00044     uint32_t MandelbrotColor1::GetColor(int x)
00045     {
00046         if (x == 0) return LCD_COLOR_BLACK;
00047         uint32_t clr[] = { LCD_COLOR_BLUE,  LCD_COLOR_CYAN,        LCD_COLOR_LIGHTGREEN,
00048                            LCD_COLOR_GREEN, LCD_COLOR_YELLOW,      LCD_COLOR_LIGHTYELLOW,
00049                            LCD_COLOR_RED,   LCD_COLOR_DARKMAGENTA, LCD_COLOR_MAGENTA};
00050         return  clr[(x-1) % 9];
00051     }
00052 
00053     // Get the color corresponding to the number of repititions (Color2)
00054     uint32_t MandelbrotColor2::GetColor(int x)
00055     {
00056         int b = Max255(20 + x*50);
00057         int g = (x >  5) ? Max255((x -  5)*30) : 0;
00058         int r = (x > 20) ? Max255((x - 20)*10) : 0;
00059         return 0xFF000000 | (r << 16) | (g << 8) | b;
00060     }
00061 }