inkplate-6-arduino-library/examples/Others/Inkplate_Mandelbrot_set/Inkplate_Mandelbrot_set.ino

74 lines
1.5 KiB
C++

#include "Inkplate.h"
#define MAXITERATIONS 150
Inkplate display(INKPLATE_1BIT);
// Takes a long time to render, cca 3 minutes
// Explore different positions to draw
// Some interesting ones can be found here http://www.cuug.ab.ca/dewara/mandelbrot/Mandelbrowser.html
double xFrom = -0.7423, xTo = -0.8463;
double yFrom = 0.1092, yTo = 0.2102;
void setup()
{
Serial.begin(115200);
display.begin();
}
void loop()
{
display.clearDisplay();
for (int j = 0; j < 600; ++j)
{
for (int i = 0; i < 800; ++i)
display.drawPixel(
i, j, colorAt(xFrom + (double)i * (xTo - xFrom) / 800.0, yFrom + (double)j * (yTo - yFrom) / 600.0));
// for whole set:
// display.drawPixel(i, j, colorAt(-2.0 + (3.0 * (double)i / 800.0), -1.0 + 2.0 * (double)j / 600.0));
Serial.println(j);
}
display.display();
delay(5000);
}
struct complex
{
double re;
double im;
};
void addComplex(struct complex *z, struct complex *c)
{
z->re += c->re;
z->im += c->im;
}
void squareComplex(struct complex *z)
{
double re = z->re;
double im = z->im;
z->re = re * re - im * im;
z->im = 2 * re * im;
}
double modulusComplexSqr(struct complex *z)
{
return z->re * z->re + z->im * z->im;
}
uint8_t colorAt(double x, double y)
{
struct complex z = {0.0, 0.0};
struct complex c = {x, y};
int i;
for (i = 0; i < MAXITERATIONS && modulusComplexSqr(&z) <= 4.0; ++i)
{
squareComplex(&z);
addComplex(&z, &c);
}
return i == MAXITERATIONS;
}