abg

Animated background for X11
git clone git://git.laack.co/abg.git
Log | Files | Refs | README

commit d6300c064682e872dd0055eb352f0d0a0cbc30a9
parent 756194f6daa20b7338b7c5610327ab200b17a175
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 15 Sep 2026 21:01:31 -0500

Refactoring constants

Diffstat:
Abackground/headers/constants.hpp | 9+++++++++
Mbackground/headers/utils.hpp | 2--
Mbackground/src/graph.cpp | 10++++------
Mbackground/src/main.cpp | 10+++++++---
4 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/background/headers/constants.hpp b/background/headers/constants.hpp @@ -0,0 +1,9 @@ +#include <cstddef> +#include <raylib.h> + +const CLITERAL(Color) DARKERGRAY { 40, 40, 40, 255 }; + +const float VERTEX_RENDER_SIZE = 4; +const float EDGE_REDNER_SIZE = 1; +const std::size_t DEFAULT_EDGE_COUNT = 1000; +const std::size_t DEFAULT_VERTEX_COUNT = 200; diff --git a/background/headers/utils.hpp b/background/headers/utils.hpp @@ -3,8 +3,6 @@ #include <cstdint> #include <raylib.h> -#define DARKERGRAY CLITERAL(Color){ 40, 40, 40, 255 } - float square(float x); Vector2 randomPosition(uint32_t xMax, uint32_t yMax); float distanceSquared(Vector2 v1, Vector2 v2); diff --git a/background/src/graph.cpp b/background/src/graph.cpp @@ -1,4 +1,5 @@ #include "../headers/graph.hpp" +#include "../headers/constants.hpp" #include "../headers/vertex.hpp" #include "../headers/utils.hpp" #include <cstddef> @@ -6,9 +7,6 @@ #include <raylib.h> #include <stdexcept> -#define VERTEX_SIZE 5 -#define EDGE_SIZE 1 - Graph::Graph(std::size_t edgeCount, std::size_t vertCount, uint32_t xMax, uint32_t yMax) { if(edgeCount > 0 && vertCount <= 1) { @@ -21,7 +19,7 @@ Graph::Graph(std::size_t edgeCount, std::size_t vertCount, uint32_t xMax, uint32 for(std::size_t i = 0; i < vertCount; ++i) { Vector2 rnd = randomPosition(xMax, yMax); - Vertex v {rnd,VERTEX_SIZE}; + Vertex v {rnd,VERTEX_RENDER_SIZE}; this->vertices.push_back(v); } for(std::size_t i = 0; i < edgeCount; ++i) { @@ -78,7 +76,7 @@ void Graph::render() noexcept { if(edge.traversed) { visited.push_back(edge); } else { - DrawLineEx(v1, v2, EDGE_SIZE,DARKERGRAY); + DrawLineEx(v1, v2, EDGE_REDNER_SIZE,DARKERGRAY); } } } @@ -93,7 +91,7 @@ void Graph::render() noexcept { std::size_t idx2 = edge.v2Index; auto v1 = vertices[idx1].position; auto v2 = vertices[idx2].position; - DrawLineEx(v1, v2, EDGE_SIZE, WHITE); + DrawLineEx(v1, v2, EDGE_REDNER_SIZE, WHITE); } } diff --git a/background/src/main.cpp b/background/src/main.cpp @@ -1,6 +1,8 @@ #include "../headers/graph.hpp" #include "../headers/prim.hpp" #include "../headers/background.hpp" +#include "../headers/constants.hpp" +#include <cstdint> #include <cstdlib> #include <unistd.h> #include <raylib.h> @@ -13,8 +15,6 @@ int main() { SetTraceLogLevel(LOG_ERROR); srand(clock()); - std::size_t edgeCount = 500; - std::size_t vertCount = 100; auto ss = getScreenSize(); @@ -29,7 +29,11 @@ int main() { while (!WindowShouldClose()) { - Graph g = Graph(edgeCount, vertCount, xMax,yMax); + // TODO: What should the cli include? Edges and vertices perhaps? + // I'd also like other graph algos in here too so perhaps --vertices --edges and {algorithm}? + // would also like to have nearest neighbor travelling salesman too + + Graph g = Graph(DEFAULT_EDGE_COUNT, DEFAULT_VERTEX_COUNT, xMax,yMax); std::unordered_set<std::size_t> visitedIndices {}; std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> toVisit {}; std::vector<Edge> edges = g.getEdgesOfVertexIdx(0);