Skip to content

Instantly share code, notes, and snippets.

@banhbaochi3n
Created March 5, 2025 12:37
Show Gist options
  • Save banhbaochi3n/61a3d67b880a68112bd60faa17212f39 to your computer and use it in GitHub Desktop.
Save banhbaochi3n/61a3d67b880a68112bd60faa17212f39 to your computer and use it in GitHub Desktop.
Event horizon
#include <stdio.h>
#include <math.h>
#define WIDTH 30
#define HEIGHT 30
int main() {
float w = WIDTH;
float h = HEIGHT;
for (int col = 0; col < HEIGHT; ++col) {
for (int row = 0; row < WIDTH; ++row) {
float x = col;
float y = row;
float cx = (2 * x - w) / h;
float cy = (2 * y - h) / h;
float d = sqrtf(cx * cx + cy * cy);
d -= 0.5;
d += 0.01 * h / (2 * (x - y) + h - w);
d = fabsf(d);
d = 0.1 / d;
char c = " -+=<@#"[(int)floorf(d / (1 + d) * 7)];
printf("%c%c", c, c);
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment