Copying from gitlab

This commit is contained in:
2026-01-09 10:45:23 +01:00
commit 25d9b22fbd
11 changed files with 937 additions and 0 deletions

82
src/render.cpp Normal file
View File

@@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* / ) */
/* render.cpp (\__/) ( ( */
/* ) ( ) ) */
/* By: lejulien <leo.julien.42@gmail.com> ={ }= / / */
/* ) `-------/ / */
/* Created: 2023/01/09 12:44:30 by lejulien ( / */
/* Updated: 2023/01/14 17:02:00 by lejulien \ | */
/* */
/* ************************************************************************** */
#include "../includes/render.hpp"
#include "raylib.h"
#include <cmath>
// Constructor
Render::Render(int cell_size) : cell_size_(cell_size) {}
// Display function
int HSVtoHex(float h) {
float r, g, b;
int i = int(h / 60) % 6;
float f = (h / 60) - i;
float p = 0.0f;
float q = 1.0f - f;
float t = f;
switch (i) {
case 0:
r = 1.0f, g = t, b = p;
break;
case 1:
r = q, g = 1.0f, b = p;
break;
case 2:
r = p, g = 1.0f, b = t;
break;
case 3:
r = p, g = q, b = 1.0f;
break;
case 4:
r = t, g = p, b = 1.0f;
break;
default:
r = 1.0f, g = p, b = q;
break;
}
int R = static_cast<int>(r * 255);
int G = static_cast<int>(g * 255);
int B = static_cast<int>(b * 255);
return (R << 24) | (G << 16) | (B << 8) | 255; // Return as 0xRRGGBB integer
}
void Render::display_world(std::vector<bool> *data, int width, int height) {
float maxDist =
std::sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1));
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
if ((*data)[i + j * width]) {
float dist = std::sqrt(i * i + j * j);
float factor = dist / maxDist;
float hue = factor * 360.0f; // Map to 0-360 degrees
DrawRectangle(i * cell_size_, j * cell_size_, cell_size_, cell_size_,
GetColor(HSVtoHex(hue)));
}
}
}
}
// Render loop
void Render::display(World *world) {
display_world(world->getWorldData(), world->getWidth(), world->getHeight());
}
void Render::updateCellSize(int new_size) { cell_size_ = new_size; }