Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BD_SD_DISCO_F769NI BSP_DISCO_F769NI LCD_DISCO_F769NI TS_DISCO_F769NI USBHost_F769NI
Mandelbrot/mandelbrot.cpp@3:35ac9ee7d2d6, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:39:01 2019 +0000
- Revision:
- 3:35ac9ee7d2d6
- Child:
- 4:0f4affc00183
1st trial revision (Not finalized yet)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 3:35ac9ee7d2d6 | 1 | //------------------------------------------------------ |
kenjiArai | 3:35ac9ee7d2d6 | 2 | // Class for drawing Mandelbrot set |
kenjiArai | 3:35ac9ee7d2d6 | 3 | // 2015/11/03, Copyright (c) 2015 MIKAMI, Naoki |
kenjiArai | 3:35ac9ee7d2d6 | 4 | //----------------------------------------------------------- |
kenjiArai | 3:35ac9ee7d2d6 | 5 | // Modified by JH1PJL/K.Arai July 25th,2019 for DISCO-F769NI |
kenjiArai | 3:35ac9ee7d2d6 | 6 | |
kenjiArai | 3:35ac9ee7d2d6 | 7 | #include "mandelbrot.hpp" |
kenjiArai | 3:35ac9ee7d2d6 | 8 | |
kenjiArai | 3:35ac9ee7d2d6 | 9 | namespace Mikami |
kenjiArai | 3:35ac9ee7d2d6 | 10 | { |
kenjiArai | 3:35ac9ee7d2d6 | 11 | void MandelbrotBase::Display(float x1, float x2, float y1, float y2) |
kenjiArai | 3:35ac9ee7d2d6 | 12 | { |
kenjiArai | 3:35ac9ee7d2d6 | 13 | x1_ = x1; |
kenjiArai | 3:35ac9ee7d2d6 | 14 | y1_ = y1; |
kenjiArai | 3:35ac9ee7d2d6 | 15 | |
kenjiArai | 3:35ac9ee7d2d6 | 16 | ax_ = (x2 - x1)/(NX_ - 1); |
kenjiArai | 3:35ac9ee7d2d6 | 17 | ay_ = (y2 - y1)/(NY_ - 1); |
kenjiArai | 3:35ac9ee7d2d6 | 18 | |
kenjiArai | 3:35ac9ee7d2d6 | 19 | for (int nx=0; nx<NX_; nx++) |
kenjiArai | 3:35ac9ee7d2d6 | 20 | for (int ny=0; ny<NY_; ny++) |
kenjiArai | 3:35ac9ee7d2d6 | 21 | { |
kenjiArai | 3:35ac9ee7d2d6 | 22 | uint32_t color = GetColor(Converge(Complex(Fx(nx), Fy(ny)))); |
kenjiArai | 3:35ac9ee7d2d6 | 23 | LCD_->DrawPixel(X0_+nx, Y0_+ny, color); |
kenjiArai | 3:35ac9ee7d2d6 | 24 | } |
kenjiArai | 3:35ac9ee7d2d6 | 25 | } |
kenjiArai | 3:35ac9ee7d2d6 | 26 | |
kenjiArai | 3:35ac9ee7d2d6 | 27 | // discrimination of congergence |
kenjiArai | 3:35ac9ee7d2d6 | 28 | int MandelbrotBase::Converge(Complex c) |
kenjiArai | 3:35ac9ee7d2d6 | 29 | { |
kenjiArai | 3:35ac9ee7d2d6 | 30 | Complex zn = 0; // initial value |
kenjiArai | 3:35ac9ee7d2d6 | 31 | |
kenjiArai | 3:35ac9ee7d2d6 | 32 | for (int n=1; n<=MAX_COUNT_; n++) |
kenjiArai | 3:35ac9ee7d2d6 | 33 | { |
kenjiArai | 3:35ac9ee7d2d6 | 34 | zn = zn*zn + c; |
kenjiArai | 3:35ac9ee7d2d6 | 35 | if ((Sqr(zn.real()) + Sqr(zn.imag())) > 4) |
kenjiArai | 3:35ac9ee7d2d6 | 36 | return(n); // diverge |
kenjiArai | 3:35ac9ee7d2d6 | 37 | } |
kenjiArai | 3:35ac9ee7d2d6 | 38 | return 0; // converge |
kenjiArai | 3:35ac9ee7d2d6 | 39 | } |
kenjiArai | 3:35ac9ee7d2d6 | 40 | |
kenjiArai | 3:35ac9ee7d2d6 | 41 | // Get the color corresponding to the number of repititions (Color1) |
kenjiArai | 3:35ac9ee7d2d6 | 42 | uint32_t MandelbrotColor1::GetColor(int x) |
kenjiArai | 3:35ac9ee7d2d6 | 43 | { |
kenjiArai | 3:35ac9ee7d2d6 | 44 | if (x == 0) return LCD_COLOR_BLACK; |
kenjiArai | 3:35ac9ee7d2d6 | 45 | uint32_t clr[] = { LCD_COLOR_BLUE, LCD_COLOR_CYAN, LCD_COLOR_LIGHTGREEN, |
kenjiArai | 3:35ac9ee7d2d6 | 46 | LCD_COLOR_GREEN, LCD_COLOR_YELLOW, LCD_COLOR_LIGHTYELLOW, |
kenjiArai | 3:35ac9ee7d2d6 | 47 | LCD_COLOR_RED, LCD_COLOR_DARKMAGENTA, LCD_COLOR_MAGENTA}; |
kenjiArai | 3:35ac9ee7d2d6 | 48 | return clr[(x-1) % 9]; |
kenjiArai | 3:35ac9ee7d2d6 | 49 | } |
kenjiArai | 3:35ac9ee7d2d6 | 50 | |
kenjiArai | 3:35ac9ee7d2d6 | 51 | // Get the color corresponding to the number of repititions (Color2) |
kenjiArai | 3:35ac9ee7d2d6 | 52 | uint32_t MandelbrotColor2::GetColor(int x) |
kenjiArai | 3:35ac9ee7d2d6 | 53 | { |
kenjiArai | 3:35ac9ee7d2d6 | 54 | int b = Max255(20 + x*50); |
kenjiArai | 3:35ac9ee7d2d6 | 55 | int g = (x > 5) ? Max255((x - 5)*30) : 0; |
kenjiArai | 3:35ac9ee7d2d6 | 56 | int r = (x > 20) ? Max255((x - 20)*10) : 0; |
kenjiArai | 3:35ac9ee7d2d6 | 57 | return 0xFF000000 | (r << 16) | (g << 8) | b; |
kenjiArai | 3:35ac9ee7d2d6 | 58 | } |
kenjiArai | 3:35ac9ee7d2d6 | 59 | } |