2021-04-01 14:46:41 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2023-06-09 00:21:22 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) 2020-2023 Devine Lu Linvega
|
2021-04-01 14:46:41 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-04-02 00:44:23 -04:00
|
|
|
int
|
|
|
|
clamp(int val, int min, int max)
|
|
|
|
{
|
|
|
|
return (val >= min) ? (val <= max) ? val : max : min;
|
|
|
|
}
|
|
|
|
|
2021-04-01 14:46:41 -04:00
|
|
|
int
|
2023-06-09 00:21:22 -04:00
|
|
|
cinu(char c)
|
2021-04-01 14:46:41 -04:00
|
|
|
{
|
2023-06-09 00:21:22 -04:00
|
|
|
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[])
|
|
|
|
{
|
2023-06-09 01:11:49 -04:00
|
|
|
int seg, offset, i;
|
|
|
|
double segf;
|
2023-06-09 00:21:22 -04:00
|
|
|
if(argc < 2) {
|
|
|
|
printf("usage: circle128 length\n", argc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
seg = sint(argv[1]);
|
2023-06-09 01:11:49 -04:00
|
|
|
segf = (double)seg;
|
|
|
|
offset = seg / 4;
|
2022-06-09 12:19:15 -04:00
|
|
|
printf("%d points on a circle128:\n\n", seg);
|
|
|
|
for(i = 0; i < seg; ++i) {
|
2021-04-02 00:44:23 -04:00
|
|
|
double cx = 128, cy = 128, r = 128;
|
2022-06-09 12:19:15 -04:00
|
|
|
double pos = (i - offset) % seg;
|
|
|
|
double deg = (pos / segf) * 360.0;
|
2021-04-01 14:46:41 -04:00
|
|
|
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");
|
2021-04-02 00:44:23 -04:00
|
|
|
printf("%02x%02x ", (Uint8)clamp(x, 0x00, 0xff), (Uint8)clamp(y, 0x00, 0xff));
|
2021-04-01 14:46:41 -04:00
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
return 0;
|
|
|
|
}
|