Mandelbrot fractal - color version - slow but nice :-)

Dependencies:   mbed

Committer:
JLS
Date:
Wed Jan 26 18:54:28 2011 +0000
Revision:
0:59939414a202

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JLS 0:59939414a202 1 #include "TFT_4DGL.h"
JLS 0:59939414a202 2
JLS 0:59939414a202 3 TFT_4DGL lcd(p9,p10,p11);
JLS 0:59939414a202 4
JLS 0:59939414a202 5 int main() {
JLS 0:59939414a202 6
JLS 0:59939414a202 7 float xmin = -2.5;
JLS 0:59939414a202 8 float ymin = -2.0;
JLS 0:59939414a202 9 float wh = 4;
JLS 0:59939414a202 10
JLS 0:59939414a202 11 int maxiterations = 100;
JLS 0:59939414a202 12 int width = 320;
JLS 0:59939414a202 13 int height = 320;
JLS 0:59939414a202 14
JLS 0:59939414a202 15 float xmax = xmin+wh;
JLS 0:59939414a202 16
JLS 0:59939414a202 17 float ymax = ymin+wh;
JLS 0:59939414a202 18
JLS 0:59939414a202 19 float dx = (xmax - xmin) / (width);
JLS 0:59939414a202 20 float dy = (ymax - ymin) / (height);
JLS 0:59939414a202 21
JLS 0:59939414a202 22 float y = ymin;
JLS 0:59939414a202 23
JLS 0:59939414a202 24
JLS 0:59939414a202 25 for (int j = 0; j < (height); j++) {
JLS 0:59939414a202 26
JLS 0:59939414a202 27 float x = xmin;
JLS 0:59939414a202 28 for (int i = 0; i < width; i++) {
JLS 0:59939414a202 29
JLS 0:59939414a202 30 float a = x;
JLS 0:59939414a202 31 float b = y;
JLS 0:59939414a202 32 int n = 0;
JLS 0:59939414a202 33 while (n < maxiterations) {
JLS 0:59939414a202 34
JLS 0:59939414a202 35 float aa = a * a;
JLS 0:59939414a202 36 float bb = b * b;
JLS 0:59939414a202 37 float twoab = 2.0 * a * b;
JLS 0:59939414a202 38 a = aa - bb + x;
JLS 0:59939414a202 39 b = twoab + y;
JLS 0:59939414a202 40
JLS 0:59939414a202 41 if(aa + bb > 16.0) {
JLS 0:59939414a202 42 break;
JLS 0:59939414a202 43 }
JLS 0:59939414a202 44 n++;
JLS 0:59939414a202 45 }
JLS 0:59939414a202 46
JLS 0:59939414a202 47 if (n == maxiterations) {
JLS 0:59939414a202 48
JLS 0:59939414a202 49 } else {
JLS 0:59939414a202 50
JLS 0:59939414a202 51 lcd.pixel(120+80*y,210+80*x,n*n*n*n*n*n*n*n);
JLS 0:59939414a202 52
JLS 0:59939414a202 53 }
JLS 0:59939414a202 54 x += dx;
JLS 0:59939414a202 55 }
JLS 0:59939414a202 56 y += dy;
JLS 0:59939414a202 57 }
JLS 0:59939414a202 58
JLS 0:59939414a202 59 }