-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
39 lines (37 loc) · 1014 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
int main(int argc, char** argv)
{
uint16_t width = 120;
uint16_t height = 30;
float aspect = (float)width / height;
float pixelAspect = 11.0f / 24.0f;
char gradient[] = " .a@";
int gradientSize = 3;
char* screen = (char*)calloc(width * height + 1, sizeof (char));
screen[width * height] = '\0';
for (int t = 0; t < 10000; ++t)
{
for (uint16_t i = 0; i < width; ++i) {
for (uint16_t j = 0; j < height; ++j) {
float x = (float)i / width * 2.0f - 1.0f;
float y = (float)j / height * 2.0f - 1.0f;
x *= aspect * pixelAspect;
x += sin(t * 0.001);
char pixel = ' ';
float dist = sqrt(x * x + y * y);
int color = (int)(1.0f / dist);
if (color < 0) color = 0;
else if (color > gradientSize) color = gradientSize;
pixel = gradient[color];
//if (x * x + y * y < 0.5) pixel = '@';
screen[i + j * width] = pixel;
}
}
printf("%s", screen);
}
getchar();
return EXIT_SUCCESS;
}