Mandelbrot explorer
This commit is contained in:
70
C++/Mandelbrot explorer/main.cpp
Normal file
70
C++/Mandelbrot explorer/main.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <iostream>
|
||||
#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(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;
|
||||
#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;
|
||||
|
||||
float x = 0.0f; float y = 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;
|
||||
iteration++;
|
||||
}
|
||||
olc::Pixel colour = olc::Pixel(iteration * 2, iteration * 2, iteration * 2);
|
||||
DrawRect(pX, pY, 1, 1, colour);
|
||||
}
|
||||
}
|
||||
// m_scale -= 0.01f;
|
||||
|
||||
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:
|
||||
float m_x = 1.0f;
|
||||
float m_y = 1.0f;
|
||||
float m_scale = 0.7f;
|
||||
int m_maxIterations = 100;
|
||||
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++/Mandelbrot explorer/olcPixelGameEngine.h
Normal file
2069
C++/Mandelbrot explorer/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C++/Mandelbrot explorer/output.o
Executable file
BIN
C++/Mandelbrot explorer/output.o
Executable file
Binary file not shown.
4
C++/Pixel-Engine/Rays/.gitignore
vendored
Normal file
4
C++/Pixel-Engine/Rays/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
CMakeCache.txt
|
||||
Makefile
|
||||
48
C++/Pixel-Engine/Rays/.vscode/settings.json
vendored
Normal file
48
C++/Pixel-Engine/Rays/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"chrono": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -4,39 +4,32 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Rect rect;
|
||||
bool isHoverd = false;
|
||||
|
||||
class RaysApp : public olc::PixelGameEngine {
|
||||
public:
|
||||
RaysApp() {
|
||||
RaysApp()
|
||||
: rect() {
|
||||
sAppName = "Rays";
|
||||
}
|
||||
|
||||
bool OnUserCreate() override {
|
||||
rect.SetRect(100, 100, 200, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override {
|
||||
Clear(olc::BLACK);
|
||||
if (!isHoverd) {
|
||||
DrawRect(rect.x, rect.y, rect.w, rect.h, olc::RED);
|
||||
} else {
|
||||
if (rect.Contains(new Vec2<int>(GetMouseX(), GetMouseY()))) {
|
||||
FillRect(rect.x, rect.y, rect.w, rect.h, olc::RED);
|
||||
} else {
|
||||
DrawRect(rect.x, rect.y, rect.w, rect.h, olc::RED);
|
||||
}
|
||||
|
||||
std::cout << "MouseX: " << GetMouseX() << " MouseY: " << GetMouseY() << std::endl;
|
||||
|
||||
if (rect.Contains(new Vec2<int>(GetMouseX(), GetMouseY()))) {
|
||||
isHoverd = true;
|
||||
} else {
|
||||
isHoverd = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Rect rect;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@@ -569,24 +569,24 @@ namespace olc
|
||||
|
||||
//==========================================================
|
||||
|
||||
// std::wstring ConvertS2W(std::string s)
|
||||
// {
|
||||
// #ifdef _WIN32
|
||||
// int count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);
|
||||
// wchar_t* buffer = new wchar_t[count];
|
||||
// MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, buffer, count);
|
||||
// std::wstring w(buffer);
|
||||
// delete[] buffer;
|
||||
// return w;
|
||||
// #endif
|
||||
// //#ifdef __MINGW32__
|
||||
// // wchar_t *buffer = new wchar_t[sImageFile.length() + 1];
|
||||
// // mbstowcs(buffer, sImageFile.c_str(), sImageFile.length());
|
||||
// // buffer[sImageFile.length()] = L'\0';
|
||||
// // wsImageFile = buffer;
|
||||
// // delete[] buffer;
|
||||
// //#else
|
||||
// }
|
||||
std::wstring ConvertS2W(std::string s)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);
|
||||
wchar_t* buffer = new wchar_t[count];
|
||||
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, buffer, count);
|
||||
std::wstring w(buffer);
|
||||
delete[] buffer;
|
||||
return w;
|
||||
#endif
|
||||
//#ifdef __MINGW32__
|
||||
// wchar_t *buffer = new wchar_t[sImageFile.length() + 1];
|
||||
// mbstowcs(buffer, sImageFile.c_str(), sImageFile.length());
|
||||
// buffer[sImageFile.length()] = L'\0';
|
||||
// wsImageFile = buffer;
|
||||
// delete[] buffer;
|
||||
//#else
|
||||
}
|
||||
|
||||
Sprite::Sprite()
|
||||
{
|
||||
@@ -1273,6 +1273,7 @@ namespace olc
|
||||
|
||||
void PixelGameEngine::DrawRect(int32_t x, int32_t y, int32_t w, int32_t h, Pixel p)
|
||||
{
|
||||
w--; h--;
|
||||
DrawLine(x, y, x+w, y, p);
|
||||
DrawLine(x+w, y, x+w, y+h, p);
|
||||
DrawLine(x+w, y+h, x, y+h, p);
|
||||
|
||||
Binary file not shown.
5
OpenGL/cube/.vscode/settings.json
vendored
Normal file
5
OpenGL/cube/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"chrono": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#version 130
|
||||
|
||||
in vec3 Colour;
|
||||
out vec4 outColour;
|
||||
|
||||
uniform vec3 triangleColour;
|
||||
|
||||
void main() {
|
||||
outColour = vec4(Colour, 1.0);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#version 130
|
||||
|
||||
in vec2 position;
|
||||
in vec3 colour;
|
||||
|
||||
out vec3 Colour;
|
||||
|
||||
void main() {
|
||||
Colour = colour;
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
// Equivilent to vec4(position.x, position.y, 0.0, 1.0)
|
||||
}
|
||||
Reference in New Issue
Block a user