Doom Fire
This commit is contained in:
55
C++/Doom Fire Algorithm/.vscode/settings.json
vendored
Normal file
55
C++/Doom Fire Algorithm/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"ostream": "cpp",
|
||||
"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",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
91
C++/Doom Fire Algorithm/main.cpp
Normal file
91
C++/Doom Fire Algorithm/main.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
int WINDOW_HEIGHT = 720;
|
||||
int WINDOW_WIDTH = 1280;
|
||||
|
||||
int fireSize = 4;
|
||||
int* firePixelsArray = new int[(WINDOW_WIDTH / fireSize) * (WINDOW_HEIGHT / fireSize)];
|
||||
int numberOfPixels = (WINDOW_WIDTH / fireSize) * (WINDOW_HEIGHT / fireSize);
|
||||
|
||||
int fireColoursPalette[37][3] = {{7, 7, 7}, {31, 7, 7}, {47, 15, 7}, {71, 15, 7}, {87, 23, 7}, {103, 31, 7}, {119, 31, 7}, {143, 39, 7}, {159, 47, 7}, {175, 63, 7}, {191, 71, 7}, {199, 71, 7}, {223, 79, 7}, {223, 87, 7}, {223, 87, 7}, {215, 95, 7}, {215, 95, 7}, {215, 103, 15}, {207, 111, 15}, {207, 119, 15}, {207, 127, 15}, {207, 135, 23}, {199, 135, 23}, {199, 143, 23}, {199, 151, 31}, {191, 159, 31}, {191, 159, 31}, {191, 167, 39}, {191, 167, 39}, {191, 175, 47}, {183, 175, 47}, {183, 183, 47}, {183, 183, 55}, {207, 207, 111}, {223, 223, 159}, {239, 239, 199}, {255, 255, 255}};
|
||||
|
||||
class FireSim : public olc::PixelGameEngine {
|
||||
public:
|
||||
FireSim() {
|
||||
sAppName = "Doom Fire Simulator";
|
||||
}
|
||||
|
||||
bool OnUserCreate() override {
|
||||
for (int i = 0; i < numberOfPixels; i++) {
|
||||
firePixelsArray[i] = 20;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override {
|
||||
m_timeAccumilator += fElapsedTime;
|
||||
if (m_timeAccumilator >= 0.033) {
|
||||
m_timeAccumilator = 0.0f;
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int i = 0; i < numberOfPixels; i++) {
|
||||
UpdateFireIntensity(i);
|
||||
}
|
||||
}
|
||||
Render();
|
||||
|
||||
if (GetMouse(0).bHeld) {
|
||||
Vec2<int> m = {GetMouseX(), GetMouseY()};
|
||||
int index = (m.y * WINDOW_WIDTH + m.x) / fireSize;
|
||||
if (index >= numberOfPixels) {
|
||||
return true;
|
||||
}
|
||||
firePixelsArray[index] = 36;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateFireIntensity(int pixel) {
|
||||
int pixelBelowIndex = pixel + (WINDOW_WIDTH / fireSize);
|
||||
if (pixelBelowIndex < numberOfPixels) {
|
||||
int decay = floor(rand() % 3);
|
||||
int pixelBelowIntensity = firePixelsArray[pixelBelowIndex];
|
||||
int intensity = pixelBelowIntensity - decay >= 0 ? pixelBelowIntensity - decay : 0;
|
||||
int position = (pixel - decay >= 0) ? pixel - decay : 0;
|
||||
firePixelsArray[position] = intensity;
|
||||
}
|
||||
}
|
||||
|
||||
void Render() {
|
||||
Clear(olc::BLACK);
|
||||
for (int x = 0; x < WINDOW_WIDTH; x += fireSize) {
|
||||
for (int y = 0; y < WINDOW_HEIGHT; y += fireSize) {
|
||||
int pixel = x + ((WINDOW_WIDTH / fireSize) * y);
|
||||
int pixelI = pixel / fireSize;
|
||||
int fireIntensity = firePixelsArray[pixelI];
|
||||
uint8_t r = fireColoursPalette[fireIntensity][0];
|
||||
uint8_t g = fireColoursPalette[fireIntensity][1];
|
||||
uint8_t b = fireColoursPalette[fireIntensity][2];
|
||||
olc::Pixel col = {r, g, b, 255};
|
||||
FillRect(x, y, fireSize, fireSize, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OnUserDestroy() override {
|
||||
delete[] firePixelsArray;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
float m_timeAccumilator = 0.0f;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
FireSim app;
|
||||
if (app.Construct(WINDOW_WIDTH, WINDOW_HEIGHT, 1, 1))
|
||||
app.Start();
|
||||
return 0;
|
||||
}
|
||||
2534
C++/Doom Fire Algorithm/olcPixelGameEngine.h
Normal file
2534
C++/Doom Fire Algorithm/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C++/Doom Fire Algorithm/output.exe
Normal file
BIN
C++/Doom Fire Algorithm/output.exe
Normal file
Binary file not shown.
14
C++/Navier Stokes Fluid Sim/CMakeLists.txt
Normal file
14
C++/Navier Stokes Fluid Sim/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(NavierStokes)
|
||||
|
||||
set(CMAKE_MODULE_PATH CMakeModule/)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++17")
|
||||
|
||||
set(Executable output)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAD ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
add_executable(${Executable} main.cpp)
|
||||
|
||||
target_link_libraries(${Executable} Threads::Threads ${WinSDK})
|
||||
46
C++/Navier Stokes Fluid Sim/main.cpp
Normal file
46
C++/Navier Stokes Fluid Sim/main.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <string>
|
||||
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
#define N 600
|
||||
#define SIZE (N + 2) * (N + 2)
|
||||
#define IX(i,j) ((i)+(N+2)*(j))
|
||||
|
||||
class NavierStokes : public olc::PixelGameEngine {
|
||||
public:
|
||||
NavierStokes() {
|
||||
sAppName = "Fluid Dynamics";
|
||||
}
|
||||
|
||||
bool OnUserCreate() override {
|
||||
return true;
|
||||
memset(u, 0, sizeof(float) * SIZE);
|
||||
memset(v, 0, sizeof(float) * SIZE);
|
||||
memset(u_prev, 0, sizeof(float) * SIZE);
|
||||
memset(v_prev, 0, sizeof(float) * SIZE);
|
||||
memset(dens, 0, sizeof(float) * SIZE);
|
||||
memset(dens_prev, 0, sizeof(float) * SIZE);
|
||||
|
||||
};
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override {
|
||||
Clear(olc::WHITE);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
float u[SIZE], v[SIZE], u_prev[SIZE], v_prev[SIZE];
|
||||
float dens[SIZE], dens_prev[SIZE];
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
NavierStokes app;
|
||||
if (app.Construct(600, 600, 1, 1)) {
|
||||
app.Start();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
2534
C++/Navier Stokes Fluid Sim/olcPixelGameEngine.h
Normal file
2534
C++/Navier Stokes Fluid Sim/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C++/Navier Stokes Fluid Sim/output.exe
Normal file
BIN
C++/Navier Stokes Fluid Sim/output.exe
Normal file
Binary file not shown.
BIN
C++/Navier Stokes Fluid Sim/output.execd
Normal file
BIN
C++/Navier Stokes Fluid Sim/output.execd
Normal file
Binary file not shown.
Reference in New Issue
Block a user