abg

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

commit 45a468e79e13ac4011546ad6d74767cd2a3e56df
parent 47516ee486c84e802c2105ba875f0a06cb3aae3c
Author: Andrew Laack <andrew@laack.co>
Date:   Mon, 14 Sep 2026 15:23:28 -0500

Updated prims algorithm file to write to shm and invoke feh to set x11 bg. Started working on a similar graph implementation in c with raylib

Diffstat:
Abackground/Makefile | 2++
Abackground/draw.c | 31+++++++++++++++++++++++++++++++
Abackground/draw.h | 4++++
Abackground/edge.c | 27+++++++++++++++++++++++++++
Abackground/edge.h | 11+++++++++++
Abackground/main.c | 28++++++++++++++++++++++++++++
Abackground/util.c | 10++++++++++
Abackground/util.h | 1+
Abackground/vert.c | 26++++++++++++++++++++++++++
Abackground/vert.h | 8++++++++
Mgraph/prim.py | 10++++++++--
11 files changed, 156 insertions(+), 2 deletions(-)

diff --git a/background/Makefile b/background/Makefile @@ -0,0 +1,2 @@ +build: + g++ main.c draw.c vert.c edge.c util.c -lraylib diff --git a/background/draw.c b/background/draw.c @@ -0,0 +1,31 @@ +#include "raylib.h" +#include "edge.h" +#include <stdio.h> + +#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; + 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]; + DrawCircle(v.x,v.y,VERTEX_SIZE, WHITE); + } +} + diff --git a/background/draw.h b/background/draw.h @@ -0,0 +1,4 @@ +#include "edge.h" + +void draw_vertices(Vertex* vertices, int length); +void draw_edges(Edge* edges, int length); diff --git a/background/edge.c b/background/edge.c @@ -0,0 +1,27 @@ +#include "edge.h" +#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]; + 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/edge.h b/background/edge.h @@ -0,0 +1,11 @@ +#include "vert.h" + +typedef struct Edge { + Vertex* v1; + Vertex* v2; + +} Edge; + +Edge gen_edge(int idx1, int idx2, Vertex* vertices); +Edge* gen_edges(Vertex* vertices, int vtCount, int edgeCount); +void print_edge(Edge* e); diff --git a/background/main.c b/background/main.c @@ -0,0 +1,28 @@ +#include "raylib.h" +#include <stdlib.h> +#include <time.h> +#include "draw.h" + +#define VERTICES 100 +#define EDGES 1000 + +int main(void) +{ + srand(time(0)); + Vertex* vertices = gen_vertices(VERTICES); + Edge* edges = gen_edges(vertices, VERTICES, EDGES); + InitWindow(5120, 1440, "Raylib background animation window"); + + while (!WindowShouldClose()) + { + BeginDrawing(); + ClearBackground(BLACK); + draw_edges(edges,EDGES); + draw_vertices(vertices,VERTICES); + EndDrawing(); + } + + CloseWindow(); + free(vertices); + return 0; +} diff --git a/background/util.c b/background/util.c @@ -0,0 +1,10 @@ +#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/util.h b/background/util.h @@ -0,0 +1 @@ +int choose_random(int length); diff --git a/background/vert.c b/background/vert.c @@ -0,0 +1,26 @@ +#include "vert.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; + +} diff --git a/background/vert.h b/background/vert.h @@ -0,0 +1,8 @@ +typedef struct Vert { + int x; + int y; + +} Vertex; +Vertex gen_vertex(); +Vertex* gen_vertices(int vtCount); +Vertex* choose_random(Vertex* vertices, int length); diff --git a/graph/prim.py b/graph/prim.py @@ -1,9 +1,12 @@ import pygame +import os import time import heapq import random import math +os.environ["SDL_VIDEODRIVER"] = "dummy" + pygame.init() display = pygame.display.set_mode((5120,1440)) @@ -100,8 +103,6 @@ while True: if item is None: pygame.display.update() -# if len(visited_vertices) == VERTICES: -# pygame.image.save(display, "out.jpg") break new_vertex = item.v2 if item.v1 in visited_vertices else item.v1 @@ -111,5 +112,10 @@ while True: for edge in graph[new_vertex]: heapq.heappush(edge_heap, edge) + dir_name = "/dev/shm/bg/" + if not os.path.exists(dir_name): + os.mkdir(dir_name) + pygame.image.save(display, dir_name + "out.png") + os.system("/usr/bin/feh --no-fehbg --bg-tile '/dev/shm/bg/out.png' ") time.sleep(.1) pygame.display.update()