commit ade58a229a638a84462ce843a281f1e09fe53f08
parent fe10cfecef99e004b7827ea2d7ec273b6074fa4c
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 8 Jun 2023 21:21:22 -0700
(tables.c) Renamed to circle128.c
Diffstat:
4 files changed, 71 insertions(+), 60 deletions(-)
diff --git a/etc/circle128/build.sh b/etc/circle128/build.sh
@@ -0,0 +1,7 @@
+#!/bin/sh -e
+
+clang-format -i circle128.c
+rm -f circle128
+cc -lm circle128 -o circle128.c
+circle128 128
+
diff --git a/etc/circle128/circle128.c b/etc/circle128/circle128.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <math.h>
+
+/*
+Copyright (c) 2020-2023 Devine Lu Linvega
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE.
+*/
+
+#define PI 3.14159265358979323846
+
+typedef unsigned char Uint8;
+
+int
+clamp(int val, int min, int max)
+{
+ return (val >= min) ? (val <= max) ? val : max : min;
+}
+
+int
+cinu(char c)
+{
+ return c >= '0' && c <= '9';
+}
+
+int
+sint(char *s)
+{
+ int i = 0, num = 0;
+ while(s[i] && cinu(s[i]))
+ num = num * 10 + (s[i++] - '0');
+ return num;
+}
+
+int
+main(int argc, char *argv[])
+{
+ int seg = 12, offset = seg / 4, i;
+ double segf = (double)seg;
+ if(argc < 2) {
+ printf("usage: circle128 length\n", argc);
+ return 1;
+ }
+ seg = sint(argv[1]);
+ printf("%d points on a circle128:\n\n", seg);
+ for(i = 0; i < seg; ++i) {
+ double cx = 128, cy = 128, r = 128;
+ double pos = (i - offset) % seg;
+ double deg = (pos / segf) * 360.0;
+ double rad = deg * (PI / 180);
+ double x = cx + r * cos(rad);
+ double y = cy + r * sin(rad);
+ if(i > 0 && i % 8 == 0)
+ printf("\n");
+ printf("%02x%02x ", (Uint8)clamp(x, 0x00, 0xff), (Uint8)clamp(y, 0x00, 0xff));
+ }
+ printf("\n\n");
+ return 0;
+}
diff --git a/etc/tables/build.sh b/etc/tables/build.sh
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-echo "Formatting.."
-clang-format -i tables.c
-
-echo "Cleaning.."
-rm -f ../../bin/tables
-
-echo "Building.."
-mkdir -p ../../bin
-cc -lm tables.c -o ../../bin/tables
-
-echo "Assembling.."
-../../bin/tables
-
-echo "Done."
diff --git a/etc/tables/tables.c b/etc/tables/tables.c
@@ -1,44 +0,0 @@
-#include <stdio.h>
-#include <math.h>
-
-/*
-Copyright (c) 2020 Devine Lu Linvega
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE.
-*/
-
-#define PI 3.14159265358979323846
-
-typedef unsigned char Uint8;
-
-int
-clamp(int val, int min, int max)
-{
- return (val >= min) ? (val <= max) ? val : max : min;
-}
-
-int
-main()
-{
- int seg = 1024, offset = seg / 4, i;
- double segf = 1024.0;
- printf("%d points on a circle128:\n\n", seg);
- for(i = 0; i < seg; ++i) {
- double cx = 128, cy = 128, r = 128;
- double pos = (i - offset) % seg;
- double deg = (pos / segf) * 360.0;
- double rad = deg * (PI / 180);
- double x = cx + r * cos(rad);
- double y = cy + r * sin(rad);
- if(i > 0 && i % 8 == 0)
- printf("\n");
- printf("%02x%02x ", (Uint8)clamp(x, 0x00, 0xff), (Uint8)clamp(y, 0x00, 0xff));
- }
- printf("\n\n");
- return 0;
-}