Created
April 16, 2025 20:28
-
-
Save Xenakios/c2063a55c34d0ced1900a3ce5948bd6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define OLC_PGE_APPLICATION | |
#include "olcPixelGameEngine.h" | |
#include <complex> | |
class Example : public olc::PixelGameEngine | |
{ | |
public: | |
Example() { sAppName = "Mandelbrot"; } | |
public: | |
bool OnUserCreate() override | |
{ | |
// Called once at the start, so create things here | |
return true; | |
} | |
bool OnUserUpdate(float fElapsedTime) override | |
{ | |
size_t num_iters = 50; | |
double bound = 2.0; | |
auto w = ScreenWidth(); | |
auto h = ScreenHeight(); | |
for (size_t x = 0; x < w; ++x) | |
{ | |
for (size_t y = 0; y < h; ++y) | |
{ | |
std::complex<double> c{-2.0 + 4.0 / w * x, -2.0 + 4.0 / h * y}; | |
std::complex<double> z0; | |
for (size_t i = 0; i < num_iters; ++i) | |
{ | |
auto z1 = std::pow(z0, 2.0) + c; | |
z0 = z1; | |
if (std::abs(z1) > bound) | |
{ | |
Draw(x, y, olc::Pixel(0, 0, 0)); | |
break; | |
} | |
else | |
{ | |
Draw(x, y, olc::Pixel(255, 255, 255)); | |
} | |
} | |
} | |
} | |
return true; | |
} | |
}; | |
int main() | |
{ | |
Example demo; | |
if (demo.Construct(256, 240, 4, 4)) | |
demo.Start(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment