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.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-22 07:03:46 -08:00
1 parent a42fc7e12a
commit cefc45f635
4 files changed
+192 -3

No files matched your search

+5 -2
View File
@@ -114,8 +114,8 @@ OBJ= ${PROG}.o
DATA= DATA=
TARGET= ${PROG} TARGET= ${PROG}
# #
ALT_OBJ= ALT_OBJ= ${PROG}.alt.o
ALT_TARGET= ALT_TARGET= ${PROG}.alt
################# #################
@@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c
alt: data ${ALT_TARGET} alt: data ${ALT_TARGET}
@${TRUE} @${TRUE}
${PROG}.alt: ${PROG}.alt.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
# data files # data files
# #
data: ${DATA} data: ${DATA}
+37 -1
View File
@@ -4,6 +4,9 @@
make 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: ## To use:
@@ -25,6 +28,34 @@ manipulate animated GIFs - to slow down the animation and to compress the GIFs
generated by the entry). 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: ## Judges' remarks:
If your system is one of those that distinguish between text and binary 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] ./persano p q [num frames]
``` ```
### DESCRIPTION ### 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 non-intersecting curve on the surface of a
[torus](https://en.wikipedia.org/wiki/Torus) in R3 that winds `p` times around [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 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! Please view the code with 8-character tabs!
### OUTPUT FORMAT ### OUTPUT FORMAT
The program writes fully valid GIF 89 streams. 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 The GIF format supports only a limited number of bits per pixel, so the
program uses ordered dithering to emulate full RGB output. program uses ordered dithering to emulate full RGB output.
### PORTABILITY ### PORTABILITY
The program was tested on Linux, with gcc 3.1; Cygwin, with gcc 3.3; and 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 distinguish between text and binary streams; however, since hardly
anyone uses such systems in this day and age, this is a minor issue. [4] anyone uses such systems in this day and age, this is a minor issue. [4]
### EXERCISES FOR THE READER ### EXERCISES FOR THE READER
1. (1 point) The surface is composed of many small polygons. Try to make it 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 3. (5 points) Locate the famous transcendental constant
[π](https://en.wikipedia.org/wiki/Pi) in the code. [π](https://en.wikipedia.org/wiki/Pi) in the code.
### FOOTNOTES ### FOOTNOTES
[1] You can call such a transformation an "ambient isotopy" if you want to [1] You can call such a transformation an "ambient isotopy" if you want to
+142
View File
@@ -0,0 +1,142 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <io.h>
#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<<k - 1), k - 1,
n + (1<<6-2 * k)*(4 - g&3));
}
Z
O(_ c)
{
B[++S] = c,
(S > 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<s ;i++,*a+=d )m(i);
}Z G(_ i ){R w=-Y (P*s),
x=f(P*s), y=Y(Q*s ),z=f
(Q*s);F( v,k[o] =(k<2
)*(x+3)*( k?y:z) -!(k-2 )*w)N(
v);F(d,P* (k?k- 1?x:w*y:w*z )+Q*(k?
k-1?0:*o:- o[1]) )N(d),w=*d**v+d[1]
*v[1]+d[2] *v[2 ];F(v,k[v]-w
*d[k])N(v),q =&C[
i],M(&t,H,K); }Z W
(char*s){*s&&( W(s
+1),u(*s-98*(*s>
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;y<e;y++){X(i
=e;i;)*(I[--i])=0;X(;i<4
*H*H;i++)X(*l=k=0;k-5;k++
,a=b)if(b=C[(i/H+((k^k/
2)&1))%(4*H)][(i+(k/2&1
))%H],k&&y<*a^y<*b){X(
h=0;h<4;h++)h[x]=a[h
+2]+(b[h+2]-a[h+2])
*(y-*a)/(*b-*a),h?
*l&&(d[h]=(l[h]
-h [x])/w):(w=1+
fabs (*l-(*x=(_)*x)
) ); X(q=I+(_)*x;
*l&& w--;q+=2*(
*x<* l)-1)X(**q
>C[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;i<e;i++ ,O(*r?c:
127),g=g<e-1 ?g+1:(O(e/
2),130))X(r=&I[ i][3],c=0,j
=2;j+1;j--,r--)k=3|!( j-1)*4,m=*r*k+
(63*( *r*k-(_)(*r*k))>D[(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: */
+8
View File
@@ -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. 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])) ## [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: Cody added the saved (with the `SAVE` command) BASIC program `PET` which was: