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

Mandelbrot/mandelbrot.cpp

Committer:
kenjiArai
Date:
2019-10-14
Revision:
4:0f4affc00183
Parent:
3:35ac9ee7d2d6

File content as of revision 4:0f4affc00183:

//------------------------------------------------------
//  Class for drawing Mandelbrot set
//  2015/11/03, Copyright (c) 2015 MIKAMI, Naoki
//-----------------------------------------------------------
// https://os.mbed.com/users/MikamiUitOpen/code/F746_Mandelbrot/
//
//      Modified by JH1PJL/K.Arai October 14th, 2019 for DISCO-F769NI

#include "mandelbrot.hpp"

namespace Mikami
{
    void MandelbrotBase::Display(float x1, float x2, float y1, float y2)
    {
        x1_ = x1;
        y1_ = y1;

        ax_ = (x2 - x1)/(NX_ - 1);
        ay_ = (y2 - y1)/(NY_ - 1);

        for (int nx=0; nx<NX_; nx++)
            for (int ny=0; ny<NY_; ny++)
            {
                uint32_t color = GetColor(Converge(Complex(Fx(nx), Fy(ny))));
                LCD_->DrawPixel(X0_+nx, Y0_+ny, color);
            }
    }

    // discrimination of congergence
    int MandelbrotBase::Converge(Complex c)
    {
        Complex zn = 0;  // initial value

        for (int n=1; n<=MAX_COUNT_; n++)
        {
            zn = zn*zn + c;
            if ((Sqr(zn.real()) + Sqr(zn.imag())) > 4)
                return(n);  // diverge
        }
        return 0;           // converge
    }

    // Get the color corresponding to the number of repititions (Color1)
    uint32_t MandelbrotColor1::GetColor(int x)
    {
        if (x == 0) return LCD_COLOR_BLACK;
        uint32_t clr[] = { LCD_COLOR_BLUE,  LCD_COLOR_CYAN,        LCD_COLOR_LIGHTGREEN,
                           LCD_COLOR_GREEN, LCD_COLOR_YELLOW,      LCD_COLOR_LIGHTYELLOW,
                           LCD_COLOR_RED,   LCD_COLOR_DARKMAGENTA, LCD_COLOR_MAGENTA};
        return  clr[(x-1) % 9];
    }

    // Get the color corresponding to the number of repititions (Color2)
    uint32_t MandelbrotColor2::GetColor(int x)
    {
        int b = Max255(20 + x*50);
        int g = (x >  5) ? Max255((x -  5)*30) : 0;
        int r = (x > 20) ? Max255((x - 20)*10) : 0;
        return 0xFF000000 | (r << 16) | (g << 8) | b;
    }
}