From 86a34865a37c2a1379df075fcf526d4bfb50217e Mon Sep 17 00:00:00 2001 From: art Date: Mon, 17 Oct 2022 09:00:38 -0400 Subject: [PATCH 1/2] Updated with new features --- lavat.c | 72 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/lavat.c b/lavat.c index b7baa0f..d45e3d3 100644 --- a/lavat.c +++ b/lavat.c @@ -7,13 +7,13 @@ #include #include -typedef struct ball { +typedef struct { int x; int y; int dx; int dy; } Ball; - +static char *custom = NULL; static short color = TB_DEFAULT; static int nballs = 10; static short speedMult = 1; @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { rim = 0; time_t t; - Ball *balls = (Ball *)malloc(sizeof(Ball) * nballs); + Ball *balls = malloc(sizeof(Ball) * nballs); struct tb_event event = {0}; @@ -85,26 +85,50 @@ int main(int argc, char *argv[]) { (y - balls[k].y) * (y - balls[k].y))); } } - - if (sum[0] > radius) { - if (sum[1] > radius) { - tb_printf(i, j, color | TB_BOLD, 0, "█"); - } else { - tb_printf(i, j, color | TB_BOLD, 0, "▀"); - } - } else if (sum[1] > radius) { - tb_printf(i, j, color | TB_BOLD, 0, "▄"); - } - - if (rim) { - if (sum[0] > innerRadius) { - if (sum[1] > innerRadius) { - tb_printf(i, j, color, 0, "█"); + if (!custom) { + if (sum[0] > radius) { + if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, "█"); } else { - tb_printf(i, j, color | TB_BOLD, color, "▄"); + tb_printf(i, j, color | TB_BOLD, 0, "▀"); + } + } else if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, "▄"); + } + + if (rim) { + if (sum[0] > innerRadius) { + if (sum[1] > innerRadius) { + tb_printf(i, j, color, 0, "█"); + } else { + tb_printf(i, j, color | TB_BOLD, color, "▄"); + } + } else if (sum[1] > innerRadius) { + tb_printf(i, j, color | TB_BOLD, color, "▀"); + } + } + } + else { + if (sum[0] > radius) { + if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, custom); + } else { + tb_printf(i, j, color | TB_BOLD, 0, custom); + } + } else if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, custom); + } + + if (rim) { + if (sum[0] > innerRadius) { + if (sum[1] > innerRadius) { + tb_printf(i, j, color, 0, custom); + } else { + tb_printf(i, j, color | TB_BOLD, color, custom); + } + } else if (sum[1] > innerRadius) { + tb_printf(i, j, color | TB_BOLD, color, custom); } - } else if (sum[1] > innerRadius) { - tb_printf(i, j, color | TB_BOLD, color, "▀"); } } } @@ -128,7 +152,7 @@ int parse_options(int argc, char *argv[]) { if (argc == 1) return 1; int c; - while ((c = getopt(argc, argv, ":c:s:r:R:b:h")) != -1) { + while ((c = getopt(argc, argv, ":c:s:r:R:b:F:h")) != -1) { switch (c) { case 'c': if (strcmp(optarg, "red") == 0) { @@ -179,6 +203,9 @@ int parse_options(int argc, char *argv[]) { return 0; } break; + case 'F': + custom = optarg; + break; case 'h': print_help(); return 0; @@ -211,6 +238,7 @@ void print_help() { " This option does not work with the default color\n" " -b NBALLS Set the number of metaballs in the simulation, from " "2 to 20. (default: 10)\n" + " -F CHARS Allows for a custom set of chars to be used\n" " -h Print help.\n" "From a tty the rim will not work well.\n"); } From fc4815ba6cd979e3ac518f43dafcdf5e8ce509fc Mon Sep 17 00:00:00 2001 From: art Date: Mon, 17 Oct 2022 09:17:02 -0400 Subject: [PATCH 2/2] Added "3d" feature --- lavat.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/lavat.c b/lavat.c index d45e3d3..149bb20 100644 --- a/lavat.c +++ b/lavat.c @@ -6,7 +6,7 @@ #include #include #include - +#include typedef struct { int x; int y; @@ -19,7 +19,7 @@ static int nballs = 10; static short speedMult = 1; static short rim = 0; static float radius = 100; - +static bool ova = false; int parse_options(int argc, char *argv[]); void print_help(); @@ -85,7 +85,29 @@ int main(int argc, char *argv[]) { (y - balls[k].y) * (y - balls[k].y))); } } - if (!custom) { + if (ova) { + if (sum[0] > radius) { + if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, "%e"); + } else { + tb_printf(i, j, color | TB_BOLD, 0, "%e"); + } + } else if (sum[1] > radius) { + tb_printf(i, j, color | TB_BOLD, 0, "%e"); + } + + if (rim) { + if (sum[0] > innerRadius) { + if (sum[1] > innerRadius) { + tb_printf(i, j, color, 0, "%e"); + } else { + tb_printf(i, j, color | TB_BOLD, color, "%e"); + } + } else if (sum[1] > innerRadius) { + tb_printf(i, j, color | TB_BOLD, color, "%e"); + } + } + } else if (!custom) { if (sum[0] > radius) { if (sum[1] > radius) { tb_printf(i, j, color | TB_BOLD, 0, "█"); @@ -107,8 +129,7 @@ int main(int argc, char *argv[]) { tb_printf(i, j, color | TB_BOLD, color, "▀"); } } - } - else { + } else { if (sum[0] > radius) { if (sum[1] > radius) { tb_printf(i, j, color | TB_BOLD, 0, custom); @@ -152,7 +173,7 @@ int parse_options(int argc, char *argv[]) { if (argc == 1) return 1; int c; - while ((c = getopt(argc, argv, ":c:s:r:R:b:F:h")) != -1) { + while ((c = getopt(argc, argv, ":c:s:r:R:b:F:th")) != -1) { switch (c) { case 'c': if (strcmp(optarg, "red") == 0) { @@ -206,6 +227,9 @@ int parse_options(int argc, char *argv[]) { case 'F': custom = optarg; break; + case 't': + ova = true; + break; case 'h': print_help(); return 0; @@ -238,7 +262,8 @@ void print_help() { " This option does not work with the default color\n" " -b NBALLS Set the number of metaballs in the simulation, from " "2 to 20. (default: 10)\n" - " -F CHARS Allows for a custom set of chars to be used\n" + " -F CHARS Allows for a custom set of chars to be used\n" + " -t Toggles a 3d appearance\n" " -h Print help.\n" "From a tty the rim will not work well.\n"); }