Created
March 2, 2024 18:03
-
-
Save artyom-poptsov/a1964d081d8e1d09701b88b2cdbc7327 to your computer and use it in GitHub Desktop.
This is an experimental program that draws a rhomb-shaped glitch-riden object in the GNU/Linux console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (C) 2024 Artyom V. Poptsov <poptsov.artyom@gmail.com> | |
Mastodon: https://fosstodon.org/@avp | |
GitHub: https://github.com/artyom-poptsov | |
Home page: https://memory-heap.org | |
Copying and distribution of this file, with or without modification, | |
are permitted in any medium without royalty provided the copyright | |
notice and this notice are preserved. This file is offered as-is, | |
without any warranty. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <time.h> | |
static const char BG = ' '; | |
static const char FG = '0'; | |
static void draw_triangle(int height, int offset_x, int start, int end, int step) { | |
int width = height * 2; | |
int center = height; | |
int color1 = rand() % 100 ? rand() % 10 : 0; | |
for (int i = start; i != end; i += step) { | |
int glitch = rand() % 10; | |
if (glitch == 1) { | |
for (int j = 0; j < offset_x - (rand() % 10); j++) { | |
putchar(' '); | |
} | |
} else { | |
for (int j = 0; j < offset_x; j++) { | |
putchar(' '); | |
} | |
} | |
if (glitch == 2) { | |
int glitch_offset = rand() % 10; | |
for (int g = 0; g < glitch_offset; g++) { | |
putchar(BG); | |
} | |
} | |
for (int j = 0; j <= width; j++) { | |
int color2 = rand() % 37 + 1; | |
char fg = FG + rand() % 10; | |
if ((j <= (center - i)) || (j >= (center + i))) { | |
printf("%c%c", BG, BG); | |
} else { | |
printf("\033[%d;%dm%c%c\033[0m", color1, color2, BG, fg); | |
} | |
} | |
putchar('\n'); | |
} | |
} | |
static void draw(int offset_x, int offset_y, int height) { | |
for (int i = 0; i < offset_y; i++) { | |
putchar('\n'); | |
} | |
draw_triangle(height, offset_x, 0, height, 1); | |
draw_triangle(height, offset_x, height, 0, -1); | |
} | |
int main(int argc, char* argv[]) { | |
const int OFFSET_X = 80; | |
const int OFFSET_Y = 5; | |
int height = atoi(argv[1]); | |
srand(time(0)); | |
time_t start_time = time(0); | |
int offset_x = OFFSET_X; | |
int offset_y = OFFSET_Y; | |
int h = height; | |
while (1) { | |
time_t diff = time(0) - start_time; | |
if (diff % 2 == 0) { | |
int n = rand() % 4; | |
offset_x = OFFSET_X - n; | |
offset_y = OFFSET_Y - n; | |
h = height + n; | |
} else { | |
offset_x = OFFSET_X; | |
offset_y = OFFSET_Y; | |
h = height; | |
} | |
system("clear"); | |
draw(offset_x, offset_y, h); | |
usleep(20000 * 2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment