Pseudosphere

Joined 16 January 2024
6,454 bytes added ,  20:27, 19 April 2024
no edit summary
Line 250: Line 250:  
** [[Nim (Easy Mode)]]
 
** [[Nim (Easy Mode)]]
 
*** [[Nim (Easy Mode) (Easy Mode)]]
 
*** [[Nim (Easy Mode) (Easy Mode)]]
 +
*** [[Nim (Easy Mode) (Cheat Mode)]]
 +
** [[Nim (Pedantic Mode)]]
 
* [[Calculator 2.0]]
 
* [[Calculator 2.0]]
 
* [[Notakto]]
 
* [[Notakto]]
Line 255: Line 257:  
* [[:/]]
 
* [[:/]]
 
* [[:/home]]
 
* [[:/home]]
 +
* [[ℝ²]]
 +
* [[Game of Life]]
    
==Scripts I made for pages==
 
==Scripts I made for pages==
Line 265: Line 269:     
<b>THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL I BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</b>
 
<b>THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL I BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</b>
 +
===Bad Coding Practices Warning===
 +
Unfortunately, I usually don't comment my code. I might fix this at some point...
 
===[[Rotating CSS Tesseract|Tesseract]] CSS generator===
 
===[[Rotating CSS Tesseract|Tesseract]] CSS generator===
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 601: Line 607:  
print(elementContainer)
 
print(elementContainer)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
===radio.c===
 +
<syntaxhighlight lang="c">
 +
#include <assert.h>
 +
#include <stdio.h>
 +
#include <stdlib.h>
 +
#include <string.h>
 +
 +
#include <unistd.h>
 +
 +
#ifdef WHITESPACE
 +
#define LIVECONST_DEFAULT "background-color: red !important;"
 +
#define DEAD_DEFAULT "background-color: #300;"
 +
#define LIVE_DEFAULT "background-color: red;"
 +
#define STR_LIVE "\n.%s%s {\n\t%s\n}"
 +
#define SEP fputs(", ", stdout)
 +
#define STR_100 ", 100%"
 +
#define STR_A "\n.%s%s {\n\tanimation: %s step-end infinite %s%s;\n}\n@keyframes %s%s {\n\t"
 +
#else
 +
#define LIVECONST_DEFAULT "background-color:red!important"
 +
#define DEAD_DEFAULT "background-color:#300"
 +
#define LIVE_DEFAULT "background-color:red"
 +
#define STR_LIVE ".%s%s{%s}"
 +
#define SEP putchar(',')
 +
#define STR_100 ",100%"
 +
#define STR_A ".%s%s{animation:%s step-end infinite %s%s}@keyframes %s%s{"
 +
#endif
 +
 +
typedef struct link {
 +
struct link* next;
 +
unsigned char data[];
 +
} link_t;
 +
 +
static const char base64[] = {
 +
'-', '0', '1', '2', '3', '4', '5', '6',
 +
'7', '8', '9', 'A', 'B', 'C', 'D', 'E',
 +
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
 +
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
 +
'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b',
 +
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
 +
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
 +
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
 +
};
 +
 +
static link_t start;
 +
 +
static void stdout_err() {
 +
fputs("I/O error on stdout\n", stderr);
 +
exit(EXIT_FAILURE);
 +
}
 +
 +
int main(int argc, char* argv[]) {
 +
const char* liveconst = LIVECONST_DEFAULT;
 +
const char* deadprop = DEAD_DEFAULT;
 +
const char* liveprop = LIVE_DEFAULT;
 +
const char* prefix = "X";
 +
const char* time = "1s";
 +
unsigned int framesize = 256;
 +
for (int c; (c = getopt(argc, argv, "L:c:d:l:o:p:s:t:")) != -1;) switch ((char)c) {
 +
case 'L':
 +
liveconst = optarg;
 +
continue;
 +
case 'd':
 +
deadprop = optarg;
 +
continue;
 +
case 'l':
 +
liveprop = optarg;
 +
continue;
 +
case 'o':
 +
if (freopen(optarg, "wb", stdout) != NULL) continue;
 +
perror("Could not create/open output file");
 +
return EXIT_FAILURE;
 +
case 'p':
 +
prefix = optarg;
 +
continue;
 +
case 's':
 +
framesize = atoi(optarg);
 +
if (framesize && framesize <= 65536) continue;
 +
fprintf(stderr, "Frame size must be in range [1,65536], but got \"%s\"\n", optarg);
 +
return EXIT_FAILURE;
 +
case 't':
 +
time = optarg;
 +
}
 +
if (optind < argc && freopen(argv[optind], "r", stdin) == NULL) {
 +
perror("Could not open input file");
 +
return EXIT_FAILURE;
 +
}
 +
size_t len = strlen(deadprop);
 +
#ifdef WHITESPACE
 +
char deadstr[len + 11];
 +
deadstr[0] = ' ';
 +
deadstr[1] = '{';
 +
deadstr[2] = '\n';
 +
deadstr[3] = '\t';
 +
deadstr[4] = '\t';
 +
memcpy(deadstr + 5, deadprop, len);
 +
deadstr[len + 5] = '\n';
 +
deadstr[len + 6] = '\t';
 +
deadstr[len + 7] = '}';
 +
deadstr[len + 8] = '\n';
 +
deadstr[len + 9] = '\t';
 +
deadstr[len + 10] = 0;
 +
#else
 +
char deadstr[len + 3];
 +
deadstr[0] = '{';
 +
memcpy(deadstr + 1, deadprop, len);
 +
deadstr[len + 1] = '}';
 +
deadstr[len + 2] = 0;
 +
#endif
 +
len = strlen(liveprop);
 +
#ifdef WHITESPACE
 +
char livestr[len + 10];
 +
livestr[0] = ' ';
 +
livestr[1] = '{';
 +
livestr[2] = '\n';
 +
livestr[3] = '\t';
 +
livestr[4] = '\t';
 +
memcpy(livestr + 5, liveprop, len);
 +
livestr[len + 5] = '\n';
 +
livestr[len + 6] = '\t';
 +
livestr[len + 7] = '}';
 +
livestr[len + 8] = '\n';
 +
livestr[len + 9] = 0;
 +
#else
 +
char livestr[len + 3];
 +
livestr[0] = '{';
 +
memcpy(livestr + 1, liveprop, len);
 +
livestr[len + 1] = '}';
 +
livestr[len + 2] = 0;
 +
#endif
 +
link_t* end = &start;
 +
unsigned int n = 0;
 +
unsigned int k = 0;
 +
for (int c; (c = getchar()) != EOF;) {
 +
switch ((char)c) {
 +
default:
 +
continue;
 +
case 'X':
 +
end->data[k++] = 1;
 +
break;
 +
case '.':
 +
end->data[k++] = 0;
 +
}
 +
if (k == framesize) {
 +
k = 0;
 +
if (++n == 65536) {
 +
while ((c = getchar()) != EOF) switch ((char)c) {
 +
case 'X':
 +
case '.':
 +
fputs("Too many frames (>65536)\n", stdout);
 +
return EXIT_FAILURE;
 +
}
 +
break;
 +
}
 +
link_t* l = calloc(1, sizeof(link_t*) + framesize);
 +
if (l == NULL) {
 +
fputs("Could not allocate memory\n", stderr);
 +
return EXIT_FAILURE;
 +
}
 +
end->next = l;
 +
end = l;
 +
}
 +
}
 +
if (ferror(stdin)) {
 +
fputs("I/O error on input", stderr);
 +
return EXIT_FAILURE;
 +
}
 +
if (!n || (n == 1 && !k)) {
 +
fputs("EOF on input before second frame\n", stderr);
 +
return EXIT_FAILURE;
 +
}
 +
if (k) n++;
 +
unsigned int buflen = (n + 1) >> 1;
 +
unsigned short dead_buffer[buflen];
 +
unsigned short live_buffer[buflen];
 +
union {unsigned int block; char bytes[4];} buf;
 +
for (unsigned int i = 0; i != framesize; i++) {
 +
end = &start;
 +
unsigned short depth = 0;
 +
unsigned short dead = 0;
 +
unsigned short live = 0;
 +
unsigned char x;
 +
unsigned char prev = 2;
 +
do {
 +
assert(depth < n);
 +
x = end->data[i];
 +
if (x != prev) {
 +
prev = x;
 +
if (x) {
 +
assert(live < buflen);
 +
live_buffer[live++] = depth;
 +
}
 +
else {
 +
assert(dead < buflen);
 +
dead_buffer[dead++] = depth;
 +
}
 +
}
 +
end = end->next;
 +
} while (++depth != n);
 +
buf.block = 0;
 +
assert((i & 0x003f) < 64);
 +
buf.bytes[0] = base64[i & 0x003f];
 +
if (i & 0xffc0) {
 +
assert((i >> 6 & 0x003f) < 64);
 +
buf.bytes[1] = base64[i >> 6 & 0x003f];
 +
if (i & 0xf000) {
 +
assert(i >> 12 < 64);
 +
buf.bytes[2] = base64[i >> 12];
 +
}
 +
}
 +
if (!dead) {
 +
printf(STR_LIVE, prefix, buf.bytes, liveconst);
 +
continue;
 +
}
 +
if (!live) continue;
 +
if (printf(STR_A, prefix, buf.bytes, time, prefix, buf.bytes, prefix, buf.bytes) < 0) stdout_err();
 +
depth = 0;
 +
goto dead_loop;
 +
do {
 +
if (SEP < 0) stdout_err();
 +
dead_loop:
 +
assert(depth < dead);
 +
if (printf("%.55f%%", (float)(dead_buffer[depth++] * 100) / n) < 0) stdout_err();
 +
} while (depth != dead);
 +
if ((x && fputs(STR_100, stdout) < 0) || fputs(deadstr, stdout)) stdout_err();
 +
depth = 0;
 +
goto live_loop;
 +
do {
 +
if (SEP < 0) stdout_err();
 +
live_loop:
 +
assert(depth < live);
 +
if (printf("%.55f%%", (float)(live_buffer[depth++] * 100) / n) < 0) stdout_err();
 +
} while (depth != live);
 +
if ((!x && fputs(STR_100, stdout) < 0) || fputs(livestr, stdout)) stdout_err();
 +
if (putchar('}') < 0) stdout_err();
 +
}
 +
return EXIT_SUCCESS;
 +
}
 +
</syntaxhighlight>
 +
[[Game of Life]]: <code>./radio -L "background-color:#000!important" -d "background-color:#FFF" -l "background-color:#000" -o biglife.css -s 1444 -t 16s {{Tooltip|biglife.txt|A big file full of raw cell states}}</code>
    
==Kepler–Poinsot polyhedra==
 
==Kepler–Poinsot polyhedra==
1,154

edits