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.hpp

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

File content as of revision 4:0f4affc00183:

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

#ifndef F769_MANDELBROT_HPP
#define F769_MANDELBROT_HPP

#include "mbed.h"
#include "TS_DISCO_F769NI.h"
#include "LCD_DISCO_F769NI.h"

#include <complex>              // requisite for complex
typedef complex<float> Complex; // define "Complex"

namespace Mikami
{
    // Base class of Mandelbrot set drawer
    class MandelbrotBase
    {
    public:
        // Constructor
        MandelbrotBase(LCD_DISCO_F769NI &lcd,
                       int x0, int y0, int width, int height, int maxCount)
                      : LCD_(&lcd), X0_(x0), Y0_(y0), NX_(width), NY_(height),
                        MAX_COUNT_(maxCount) {}

        void Display(float x1, float x2, float y1, float y2);

        // translate position in the screen to real coordinate value
        float Fx(int x) { return ax_*x + x1_; }
        float Fy(int y) { return ay_*y + y1_; }

    protected:
        // limit maximum value to 255
        int Max255(int n) { return (n > 255) ? 255 : n; }
    
    private:
        LCD_DISCO_F769NI *const LCD_;
        const int X0_;          // origin of x axis
        const int Y0_;          // origin of y axis
        const int NX_;          // number of pixels for horizon
        const int NY_;          // number of pixels for vertical
        const int MAX_COUNT_;

        float x1_, y1_;
        float ax_, ay_;

        // Get the color corresponding to the number of repititions
        virtual uint32_t GetColor(int x) = 0;

        float Sqr(float x) { return x*x; }

        // discrimination of congergence
        int Converge(Complex c);
    };

    // Derived class of Mandelbrot set drawer to draw black and white pattern
    class MandelbrotBW : public MandelbrotBase
    {
    public:
        MandelbrotBW(LCD_DISCO_F769NI &lcd,
                     int x0, int y0, int width, int height, int maxCount = 100)
                    : MandelbrotBase(lcd, x0, y0, width, height, maxCount) {}        

        // converge: black, diverge: white
        virtual uint32_t GetColor(int x)
        { return (x == 0) ? LCD_COLOR_BLACK : LCD_COLOR_WHITE; }
    };

    // Derived class of Mandelbrot set drawer to draw pattern 1
    class MandelbrotColor1 : public MandelbrotBase
    {
    public:
        MandelbrotColor1(LCD_DISCO_F769NI &lcd,
                         int x0, int y0, int width, int height, int maxCount = 100)
                        : MandelbrotBase(lcd, x0, y0, width, height, maxCount) {}        

        // Get the color corresponding to the number of repititions
        virtual uint32_t GetColor(int x);
    };

    // Derived class of Mandelbrot set drawer to draw pattern 2
    class MandelbrotColor2 : public MandelbrotBase
    {
    public:
        MandelbrotColor2(LCD_DISCO_F769NI &lcd,
                         int x0, int y0, int width, int height, int maxCount = 100)
                        : MandelbrotBase(lcd, x0, y0, width, height, maxCount) {}        

        // Get the color corresponding to the number of repititions
        virtual uint32_t GetColor(int x);
    };
}

#endif  // F769_MANDELBROT_HPP