From cefc45f6354d87dbd76ff390aeab73dcb4bd9592 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 22 Nov 2023 07:03:46 -0800 Subject: [PATCH] Add alt code to 2005/persano + format/typo checks The alt code should (though untested) work in Windows which distinguishes between text and binary. It uses the Windows functions _fileno() and _setmode() to set binary mode on stdout. The README.md file has been format/typo checked. --- 2005/persano/Makefile | 7 +- 2005/persano/README.md | 38 +++++++++- 2005/persano/persano.alt.c | 142 +++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 8 +++ 4 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 2005/persano/persano.alt.c diff --git a/2005/persano/Makefile b/2005/persano/Makefile index 02bf83de3..28f619b87 100644 --- a/2005/persano/Makefile +++ b/2005/persano/Makefile @@ -114,8 +114,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/2005/persano/README.md b/2005/persano/README.md index 2ef3394f3..4e302eb35 100644 --- a/2005/persano/README.md +++ b/2005/persano/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version of this entry which should work for Windows by +setting binary mode on `stdout`. See [alternate code](#alternate-code) below. + ## To use: @@ -25,6 +28,34 @@ manipulate animated GIFs - to slow down the animation and to compress the GIFs generated by the entry). +## Alternate code: + +This (untested as we have no Windows system) version uses the Windows API +functions `_setmode()` and `_fileno(3)` to set binary mode on `stdout` which should +let it work with Windows. + + +### Alternate build: + +``` +make alt +``` + +### Alternate use: + +Use `persano.alt` as you would `persano` above. + + +### Alternate try: + +```sh +./persano.alt 3 16 > knot3-16.gif +``` + +Follow the same instructions, using different tools if necessary, as the above +try section. + + ## Judges' remarks: If your system is one of those that distinguish between text and binary @@ -52,9 +83,10 @@ knots](https://en.wikipedia.org/wiki/Torus_knot) to standard output. ./persano p q [num frames] ``` + ### DESCRIPTION -A (p,q)-[torus knot](https://en.wikipedia.org/wiki/Torus_knot) is a closed, +A `(p,q)`-[torus knot](https://en.wikipedia.org/wiki/Torus_knot) is a closed, non-intersecting curve on the surface of a [torus](https://en.wikipedia.org/wiki/Torus) in R3 that winds `p` times around one cycle of the torus and `q` times around the other. `p` and `q` should be @@ -83,6 +115,7 @@ output; since the number of frames is not specified, an animation with Please view the code with 8-character tabs! + ### OUTPUT FORMAT The program writes fully valid GIF 89 streams. @@ -98,6 +131,7 @@ to GIF overhead. The GIF format supports only a limited number of bits per pixel, so the program uses ordered dithering to emulate full RGB output. + ### PORTABILITY The program was tested on Linux, with gcc 3.1; Cygwin, with gcc 3.3; and @@ -109,6 +143,7 @@ It should also be mentioned that the program won't work on systems that distinguish between text and binary streams; however, since hardly anyone uses such systems in this day and age, this is a minor issue. [4] + ### EXERCISES FOR THE READER 1. (1 point) The surface is composed of many small polygons. Try to make it @@ -119,6 +154,7 @@ smoother by increasing the number of polygons. 3. (5 points) Locate the famous transcendental constant [π](https://en.wikipedia.org/wiki/Pi) in the code. + ### FOOTNOTES [1] You can call such a transformation an "ambient isotopy" if you want to diff --git a/2005/persano/persano.alt.c b/2005/persano/persano.alt.c new file mode 100644 index 000000000..f6f0c107d --- /dev/null +++ b/2005/persano/persano.alt.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include + +#define H 20 + +#define X for +#define F(v,b) X(k = 0; k < 3; k++) v[k] = b; + +typedef double R, V[3], U[4], (*J)(R); +typedef void Z; +typedef int _; + +V o, d, v; +R (*q)[H][6], C[4*H][H][6], sr = 15, br = 25, A, s, t; +_ P, Q, g, S, k, e = 256, (*u)(_) = putchar, D[64]; +J f = cos, Y = sin; +char B[256]; + +Z +T(_ *p, _ k, _ n) +{ + _ g; + + *p = n; + + X(g = 0; k && g < 4; g++) + T(p + (9 & (g * 4|g))*(1< e-2 || c==129) && (*B = S, S = fwrite(B, S+1, 1, stdout) - 1); +} + + + + + + + Z N + (R*v){R w=sqrt + (*v**v +1[v]*v[1] + +v[2]*2[v]);F(v,v[k] + /w)}Z K(_ j){V + n,p ;R*b=(* + q) [j],w=f + (A),x= + Y(A); + F(p, + br*o[ + k]+sr + * (n[ k] =f(t)*k[v]+ + Y(t)*(v[(k+1)%3]* d[( k+2)%3]-v[(k+2)% + 3]*d[(k+1)%3])))*b++=p[1 ]+e/ 2,*b++=-*p*x+ + p[2]*w-e*e,*b++=(*p*w+p[2]*x)+e/2;F( b,fabs(*n + *!!k+n[1]*( k<2)+n[2])/sqrt(2+ !(k-1))) + }Z M(R*a,_ s,Z(*m)(_)){_ i;R d= + pow(25/log (36),4)/s/ 377;X( + *a=i=0;i + 97)));}Z E(_ z){R + *r,*a,*b;U*q,l,x,d + ,I[256];_ i,j,m,c,y, + w,h,Y=sizeof l;fputc( + 46,stderr),M(&s,4*H,G), + W("ibcbcbbbbb,"),g=130, + O(e/2);X(y=0;yC[i /H][i%H][1 + ]&&( memcpy(*q, + x,Y),* *q=C[i/H][ + i%H][1 ]),h=1;h< + 4;h++)x [h]+=h[d]; + memcpy(l ,x,Y);}X( + i=0;iD[(y*8&56)+(i&7) + ]), c<<=k/4+2,c|=(m|-(m>k))& + k;} O(129);u(0);}_ + + + +main(_ c, char **v) +{ + if (c < 3) + return fprintf(stderr, "Usage: %s P Q [F]\n", *v), 1; + + _setmode(_fileno(stdout), _O_BINARY); + + P = atoi(v[1]), + Q = atoi(v[2]), + + T(D, 3, 0); + + W("bb\346cbcba98FIG"); + + X(; k < 384; k++) + u(k / 3<<("gdb"[k%3] - 97) | 31 | (k % 3!=1)<<5); + + W("bbbce0.2EPACSTEN\x0b\xff!"), + + M(&A, c > 3 ? atoi(v[3]) : 40, E), + + u(59); + + return 0; +} + +/* vi:set ts=8: */ diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 4c3dc6598..774ac3de8 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3023,6 +3023,14 @@ how https is set up, in which case just enjoy it for what it was. But there might be some command line that will let it work that way. +## [2005/persano](2005/persano/persano.c) ([README.md](2005/persano/README.md])) + +Cody added the (untested) [alternate +code](2005/persano/README.md#alternate-code) which should work for Windows as it +sets binary mode on `stdout`. It is untested as Cody has no Windows system to +test it on. + + ## [2005/sykes](2005/sykes/sykes.c) ([README.md](2005/sykes/README.md])) Cody added the saved (with the `SAVE` command) BASIC program `PET` which was: