abg

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

commit 95406b636b76e06831279e04c0fd89103a8ab600
parent dad54a3d11d86564bf65a811e571231bbf9ff3b7
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 15 Sep 2026 00:32:16 -0500

Removed old code, added installation target

Diffstat:
Mbackground/Makefile | 4+++-
Dbackground/old/Makefile | 4----
Dbackground/old/draw.c | 38--------------------------------------
Dbackground/old/draw.h | 4----
Dbackground/old/edge.cpp | 28----------------------------
Dbackground/old/edge.hpp | 21---------------------
Dbackground/old/main.cpp | 135-------------------------------------------------------------------------------
Dbackground/old/util.c | 10----------
Dbackground/old/util.h | 1-
Dbackground/old/vert.c | 33---------------------------------
Dbackground/old/vert.h | 14--------------
11 files changed, 3 insertions(+), 289 deletions(-)

diff --git a/background/Makefile b/background/Makefile @@ -1,2 +1,4 @@ build: - g++ -Ofast main.cpp graph.cpp edge.cpp utils.cpp vertex.cpp -lraylib + g++ -Ofast main.cpp graph.cpp edge.cpp utils.cpp vertex.cpp -lraylib -o background +install: build + cp background /usr/local/bin diff --git a/background/old/Makefile b/background/old/Makefile @@ -1,4 +0,0 @@ -clean: - rm a.out -build: - g++ main.cpp draw.c vert.c edge.cpp util.c -lraylib diff --git a/background/old/draw.c b/background/old/draw.c @@ -1,38 +0,0 @@ -#include "raylib.h" -#include "edge.hpp" - -#define VERTEX_SIZE 5 - -void draw_edges(Edge* edges, int length) { - for(int i = 0; i < length; ++i) { - Edge e = edges[i]; - - Vertex v1 = *e.v1; - Vertex v2 = *e.v2; - - // TODO: Convert this to a function. - Vector2 v1_p; - v1_p.x = v1.x; - v1_p.y = v1.y; - Vector2 v2_p; - v2_p.x = (float)v2.x; - v2_p.y = (float)v2.y; - if(e.traversed == true) { - DrawLineEx(v1_p, v2_p, 1,WHITE); - } else { - DrawLineEx(v1_p, v2_p, 1,DARKGRAY); - } - } -} - -void draw_vertices(Vertex* vertices, int length) { - for(int i = 0; i < length; ++i) { - Vertex v = vertices[i]; - if(v.visited) { - DrawCircle(v.x,v.y,VERTEX_SIZE, WHITE); - } else { - DrawCircle(v.x,v.y,VERTEX_SIZE, GRAY); - } - } -} - diff --git a/background/old/draw.h b/background/old/draw.h @@ -1,4 +0,0 @@ -#include "edge.hpp" - -void draw_vertices(Vertex* vertices, int length); -void draw_edges(Edge* edges, int length); diff --git a/background/old/edge.cpp b/background/old/edge.cpp @@ -1,28 +0,0 @@ -#include "edge.hpp" -#include "util.h" -#include <stdlib.h> -#include <stdio.h> - -void print_edge(Edge *e) { - printf("v1.x = %i, v1.y = %i\nv2.x = %i, v2.y = %i", e->v1->x, e->v1->y, e->v2->x, e->v2->y); -} - -Edge gen_edge(int idx1, int idx2, Vertex* vertices) { - Edge e; - e.v1 = &vertices[idx1]; - e.v2 = &vertices[idx2]; - e.weight = vert_dist(e.v1, e.v2); - return e; -} - -Edge* gen_edges(Vertex* vertices, int vtCount, int edgeCount) { - Edge* edges = (Edge*)malloc(sizeof(Edge) * edgeCount); - for(int i = 0; i < edgeCount; ++i) { - int idx1 = choose_random(vtCount); - int idx2 = choose_random(vtCount); - Edge e = gen_edge(idx1,idx2, vertices); - edges[i] = e; - } - return edges; - -} diff --git a/background/old/edge.hpp b/background/old/edge.hpp @@ -1,21 +0,0 @@ -#ifndef EDGE -#define EDGE - -#include "vert.h" - -typedef struct Edge { - Vertex* v1; - Vertex* v2; - float weight; - bool traversed; - bool operator<(const Edge& other) const { - return weight < other.weight; - } - -} Edge; - -Edge gen_edge(int idx1, int idx2, Vertex* vertices); -Edge* gen_edges(Vertex* vertices, int vtCount, int edgeCount); -void print_edge(Edge* e); - -#endif diff --git a/background/old/main.cpp b/background/old/main.cpp @@ -1,135 +0,0 @@ -#include <algorithm> -#include <thread> -#include <chrono> -#include <ctime> -#include <time.h> -#include <iostream> -#include <cstdint> -#include <raylib.h> -#include <stdlib.h> -#include <time.h> -#include <unordered_map> -#include <unordered_set> -#include <vector> -#include "draw.h" - -#define VERTICES 100 -#define EDGES 1000 - -std::unordered_map<std::uintptr_t, std::vector<Edge*>> getMap(Vertex* verts, Edge* edges, int edgeCount, int vertCount) { - - std::unordered_map<std::uintptr_t, std::vector<Edge*>> res {}; - - for(int i = 0; i < vertCount; ++i) { - Vertex* vert = &verts[i]; - res[std::uintptr_t(vert)] = std::vector<Edge*>{}; - } - - - for (int i = 0; i < edgeCount; ++i) { - Edge& e = edges[i]; - res[std::uintptr_t(e.v1)].push_back(&e); - res[std::uintptr_t(e.v2)].push_back(&e); - } - - return res; -} - -void visit_vertex( - Vertex* v, - const std::vector<Edge*>& edges, - std::vector<Edge*>& visitHeap, - std::unordered_set<std::uintptr_t>& visited -) { - - v->visited = true; - - visited.insert(uintptr_t(v)); - for(Edge* edge: edges) { - visitHeap.push_back(edge); - - auto cmp = [](Edge* a, Edge* b) { - // this makes it a min heap bc < - return a->weight < b->weight; - }; - - std::push_heap(visitHeap.begin(), visitHeap.end(), cmp); - } - return; -} - -// create vertices -// create weighted edge list -// associated edges with both vertices - // undirected graph -// start with arbitrary element - // push edges into an array - // search array for smallest element - // explore -int main(void) -{ - - srand(time(0)); - InitWindow(5120, 1440, "Raylib background animation window"); - - while (!WindowShouldClose()) - { - Vertex* vertices = gen_vertices(VERTICES); - Edge* edges = gen_edges(vertices, VERTICES, EDGES); - auto mp = getMap(vertices,edges,EDGES,VERTICES); - - std::unordered_set<std::uintptr_t> visited {}; - std::vector<Edge*> visitHeap; - - visit_vertex(&vertices[0], mp[uintptr_t(&vertices[0])], visitHeap, visited); - bool done = false; - - while(!done) { - - BeginDrawing(); - ClearBackground(BLACK); - draw_edges(edges,EDGES); - draw_vertices(vertices,VERTICES); - EndDrawing(); - std::this_thread::sleep_for(std::chrono::seconds(1)); - - std::vector<Edge*> currentHeap = visitHeap; - visitHeap.clear(); - - auto cmp = [](Edge* a, Edge* b) { - return a->weight < b->weight; - }; - std::pop_heap(visitHeap.begin(), visitHeap.end(), cmp); - - Edge* vis = visitHeap.back(); - visitHeap.pop_back(); - - if(visited.find(uintptr_t(vis->v1)) == visited.end() && visited.find(uintptr_t(vis->v2)) == visited.end()) { - continue; - } - - if(visited.find(uintptr_t(vis->v1)) != visited.end() && visited.find(uintptr_t(vis->v2)) != visited.end()) { - continue; - } - - - Vertex* visiting = nullptr; - - if(visited.find(uintptr_t(vis->v1)) == visited.end()){ - visited.insert(uintptr_t(vis->v1)); - visiting = vis->v1; - } else { - visited.insert(uintptr_t(vis->v2)); - visiting = vis->v2; - } - vis->traversed = true; - visit_vertex(visiting, mp[uintptr_t(visiting)], visitHeap, visited); - } - - free(vertices); - free(edges); - } - - CloseWindow(); - return 0; -} diff --git a/background/old/util.c b/background/old/util.c @@ -1,10 +0,0 @@ -#include <assert.h> -#include <stdlib.h> - -int choose_random(int length) { - int rnd1 = ((rand() % length) + length) % length; - assert(rnd1 >= 0); - assert(rnd1 < length); - return rnd1; -} - diff --git a/background/old/util.h b/background/old/util.h @@ -1 +0,0 @@ -int choose_random(int length); diff --git a/background/old/vert.c b/background/old/vert.c @@ -1,33 +0,0 @@ -#include "vert.h" -#include <math.h> -#include <stdlib.h> -#include <stdio.h> - -Vertex gen_vertex() { - int y = rand() % 1440; - int x = rand() % 5120; - Vertex v; - v.x = x; - v.y = y; - return v; -} - -void print_vertex(Vertex* v) { - printf("x: %i, y: %i", v->x, v->y); -} - -Vertex* gen_vertices(int vtCount) { - Vertex* vertices = (Vertex*)malloc(sizeof(Vertex) * vtCount); - for(int i = 0; i < vtCount; ++i) { - Vertex v = gen_vertex(); - vertices[i] = v; - } - return vertices; - -} - -float vert_dist(Vertex* v1, Vertex* v2) { - float dx = (float)v1->x - (float)v2->x; - float dy = (float)v1->y - (float)v2->y; - return sqrt(dx*dx + dy*dy); -} diff --git a/background/old/vert.h b/background/old/vert.h @@ -1,14 +0,0 @@ -#ifndef VERT -#define VERT - -typedef struct Vert { - int x; - int y; - bool visited; - -} Vertex; -Vertex gen_vertex(); -Vertex* gen_vertices(int vtCount); -Vertex* choose_random(Vertex* vertices, int length); -float vert_dist(Vertex* v1, Vertex* v2); -#endif