-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandelbrot.h
62 lines (58 loc) · 1.78 KB
/
mandelbrot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
MCUFRIEND_kbv tft; // this wants to be over here for some reason!
unsigned int rainbow(int value)
{
// Value is expected to be in range 0-127
// The value is converted to a spectrum colour from 0 = blue through to red = blue
//int value = random (128);
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
float sx = 0, sy = 0;
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
void drawMandelbrot() {
for (int px = 1; px < 320; px++)
{
for (int py = 0; py < 240; py++)
{
float x0 = (map(px, 0, 320, -250000/2, -242000/2)) / 100000.0; //scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
float yy0 = (map(py, 0, 240, -75000/4, -60000/4)) / 100000.0; //100000.0; -75000/4, -61000/4 //scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
float xx = 0.0;
float yy = 0.0;
int iteration = 0;
int max_iteration = 128;
while ( ((xx * xx + yy * yy) < 4) && (iteration < max_iteration) )
{
float xtemp = xx * xx - yy * yy + x0;
yy = 2 * xx * yy + yy0;
xx = xtemp;
iteration++;
}
int color = rainbow((3*iteration)%128);
tft.drawPixel(px, py, color);
}
}
//while(1);
}