better mandelbrot set
This commit is contained in:
56
C++/Julia explorer/.vscode/settings.json
vendored
Normal file
56
C++/Julia explorer/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"atomic": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cmath": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xthread": "cpp",
|
||||
"thread": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xmemory0": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xtree": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
||||
74
C++/Julia explorer/main.cpp
Normal file
74
C++/Julia explorer/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
class Mandelbrot : public olc::PixelGameEngine {
|
||||
public:
|
||||
Mandelbrot() {
|
||||
sAppName = "Mandelbrot set";
|
||||
}
|
||||
|
||||
bool OnUserCreate() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(long double fElapsedTime) override {
|
||||
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int pX = 0; pX < 1000; pX++) {
|
||||
long double mX = ((long double)pX - 1000.0f / 2.0f) / 100 * m_scale - 1 + m_x;
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int pY = 0; pY < 600; pY++) {
|
||||
long double mY = (600.0f / 2.0f - (long double)pY) / 100 * m_scale - 1 + m_y;
|
||||
|
||||
long double Zre = 0.0f; long double Zim = 0.0f;
|
||||
int iteration = 0;
|
||||
while ((Zre * Zre) + (Zim * Zim) <= 2 * 2 && iteration < m_maxIterations) {
|
||||
long double tX = (Zre * Zre) - (Zim * Zim) + mX;
|
||||
Zim = (2 * Zre * Zim) + mY;
|
||||
Zre = tX;
|
||||
iteration++;
|
||||
}
|
||||
long double ratio = (long double)iteration - std::log2(std::log2(Zre*Zre + Zim*Zim)) / m_maxIterations;
|
||||
ratio *= 255.0f;
|
||||
olc::Pixel colour = olc::Pixel(ratio, ratio, ratio);
|
||||
DrawRect(pX, pY, 1, 1, colour);
|
||||
}
|
||||
}
|
||||
|
||||
if (GetKey(olc::Key::W).bHeld)
|
||||
m_y *= 1.01f;
|
||||
if (GetKey(olc::Key::S).bHeld)
|
||||
m_y /= 1.01f;
|
||||
if (GetKey(olc::Key::D).bHeld)
|
||||
m_x *= 1.01f;
|
||||
if (GetKey(olc::Key::A).bHeld)
|
||||
m_x /= 1.01f;
|
||||
if (GetKey(olc::Key::DOWN).bHeld)
|
||||
m_scale *= 1.01f;
|
||||
if (GetKey(olc::Key::UP).bHeld)
|
||||
m_scale /= 1.01f;
|
||||
|
||||
std::cout << "Render time: " << fElapsedTime << std::endl;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
long double m_x = 1.0f;
|
||||
long double m_y = 1.0f;
|
||||
long double m_scale = 0.7f;
|
||||
int m_maxIterations = 255;
|
||||
std::map<int, olc::Pixel> m_palete;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Mandelbrot app;
|
||||
|
||||
app.Construct(1000, 600, 1, 1);
|
||||
app.Start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
2069
C++/Julia explorer/olcPixelGameEngine.h
Normal file
2069
C++/Julia explorer/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C++/Julia explorer/out.exe
Normal file
BIN
C++/Julia explorer/out.exe
Normal file
Binary file not shown.
56
C++/Mandelbrot explorer/.vscode/settings.json
vendored
Normal file
56
C++/Mandelbrot explorer/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"atomic": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cmath": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xthread": "cpp",
|
||||
"thread": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xmemory0": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xtree": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
#define OLC_PGE_APPLICATION
|
||||
@@ -15,26 +17,29 @@ public:
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override {
|
||||
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int pX = 0; pX < 1000; pX++) {
|
||||
float mX = ((float)pX - 1000.0f / 2.0f) / 100 * m_scale - 1 + m_x;
|
||||
long double mX = ((long double)pX - 1000.0f / 2.0f) / 100 * m_scale - 1 + m_x;
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int pY = 0; pY < 600; pY++) {
|
||||
float mY = (600.0f / 2.0f - (float)pY) / 100 * m_scale - 1 + m_y;
|
||||
long double mY = (600.0f / 2.0f - (long double)pY) / 100 * m_scale - 1 + m_y;
|
||||
|
||||
float x = 0.0f; float y = 0.0f;
|
||||
long double Zre = 0.0f; long double Zim = 0.0f;
|
||||
int iteration = 0;
|
||||
while ((x * x) + (y * y) <= 2 * 2 && iteration < m_maxIterations) {
|
||||
float tX = (x * x) - (y * y) + mX;
|
||||
y = (2 * x * y) + mY;
|
||||
x = tX;
|
||||
while ((Zre * Zre) + (Zim * Zim) <= 2 * 2 && iteration < m_maxIterations) {
|
||||
long double tX = (Zre * Zre) - (Zim * Zim) + mX;
|
||||
Zim = (2 * Zre * Zim) + mY;
|
||||
Zre = tX;
|
||||
iteration++;
|
||||
}
|
||||
olc::Pixel colour = olc::Pixel(iteration * 2, iteration * 2, iteration * 2);
|
||||
long double ratio1 = (long double)iteration - std::log2(std::log2(Zre*Zre + Zim*Zim)) / m_maxIterations;
|
||||
long double ratio2 = (long double)iteration - std::log(std::log(Zre*Zre * Zim*Zim)) / m_maxIterations;
|
||||
long double ratio3 = (long double)iteration - std::log10(std::log10(Zre*Zre - Zim*Zim)) / m_maxIterations;
|
||||
olc::Pixel colour = olc::Pixel(ratio1 + 255.0f, ratio2 + 255.0f, ratio3 + 255.0f);
|
||||
DrawRect(pX, pY, 1, 1, colour);
|
||||
}
|
||||
}
|
||||
// m_scale -= 0.01f;
|
||||
|
||||
if (GetKey(olc::Key::W).bHeld)
|
||||
m_y *= 1.01f;
|
||||
@@ -53,10 +58,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
float m_x = 1.0f;
|
||||
float m_y = 1.0f;
|
||||
float m_scale = 0.7f;
|
||||
int m_maxIterations = 100;
|
||||
long double m_x = 1.0f;
|
||||
long double m_y = 1.0f;
|
||||
long double m_scale = 0.7f;
|
||||
int m_maxIterations = 15;
|
||||
std::map<int, olc::Pixel> m_palete;
|
||||
};
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace
|
||||
{
|
||||
public:
|
||||
ResourcePack();
|
||||
~ResourcePack();
|
||||
// ~ResourcePack();
|
||||
struct sEntry : public std::streambuf {
|
||||
uint32_t nID, nFileOffset, nFileSize; uint8_t* data; void _config() { this->setg((char*)data, (char*)data, (char*)(data + nFileSize)); }
|
||||
};
|
||||
@@ -839,10 +839,10 @@ namespace olc
|
||||
|
||||
}
|
||||
|
||||
ResourcePack::~ResourcePack()
|
||||
{
|
||||
ClearPack();
|
||||
}
|
||||
// ResourcePack::~ResourcePack()
|
||||
// {
|
||||
// ClearPack();
|
||||
// }
|
||||
|
||||
olc::rcode ResourcePack::AddToPack(std::string sFile)
|
||||
{
|
||||
|
||||
BIN
C++/Mandelbrot explorer/out.exe
Normal file
BIN
C++/Mandelbrot explorer/out.exe
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user