From 1d8c7abf09c7a85e97d017462acb801150844c3f Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 18 Nov 2023 09:50:06 -0800 Subject: [PATCH] Add alt versions to 2004/gavin + format/typo check There already was one alt version which I found from the author's website about the entry; they used the version for development and it's unobfuscated. But two new ones were added. The most important feature is that it allows one to change the image size along with the anti-alias setting at compile time. This is gavare.alt.c. The second version (which also has the size/anti-alias changes) should theoretically work for Windows. This is gavare.alt2.c and running make alt will not try and compile it as most it'll fail on sane systems. Instead try make alt2. Both of these versions have some form of protection with the size/anti-alias setting and one does not have to define all three to get it to compile due to '#ifndef..#elif..#endif' in the code. The README.md file has been format/typo fixed. --- 2004/gavare/.gitignore | 1 + 2004/gavare/Makefile | 15 +++++++-- 2004/gavare/README.md | 66 +++++++++++++++++++++++++++++++-------- 2004/gavare/gavare.alt.c | 48 ++++++++++++++++++++++++++++ 2004/gavare/gavare.alt2.c | 31 ++++++++++++++++++ thanks-for-fixes.md | 22 +++++++++++-- 6 files changed, 164 insertions(+), 19 deletions(-) create mode 100644 2004/gavare/gavare.alt.c create mode 100644 2004/gavare/gavare.alt2.c diff --git a/2004/gavare/.gitignore b/2004/gavare/.gitignore index 799811607..467749a32 100644 --- a/2004/gavare/.gitignore +++ b/2004/gavare/.gitignore @@ -1,4 +1,5 @@ gavare +gavare.alt ioccc_ray.ppm gavare.r3 gavare.orig diff --git a/2004/gavare/Makefile b/2004/gavare/Makefile index 2406d83ae..4a380e434 100644 --- a/2004/gavare/Makefile +++ b/2004/gavare/Makefile @@ -58,7 +58,7 @@ ARCH= # Defines that are needed to compile # -CDEFINE= +CDEFINE= -DXX=1024 -DYY=768 -DAA=3 # Include files that are needed to compile # @@ -114,8 +114,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= ${PROG}.r3.o -ALT_TARGET= ${PROG}.r3 +ALT_OBJ= ${PROG}.r3.o ${PROG}.alt.o +ALT_TARGET= ${PROG}.r3 ${PROG}.alt ################# @@ -138,6 +138,15 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +alt2: ${PROG}.alt2 + @${TRUE} + +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + +${PROG}.alt2: ${PROG}.alt2.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/2004/gavare/README.md b/2004/gavare/README.md index e5d6b87c1..9dd9f9911 100644 --- a/2004/gavare/README.md +++ b/2004/gavare/README.md @@ -4,6 +4,9 @@ make ``` +There are three alternate versions; see [alternate code](#alternate-code) below +for more details. + ## To use: @@ -18,27 +21,61 @@ make ./gavare > ioccc_ray.ppm ``` - ## Alternate code: -The author provided [on their web page for the -entry](https://gavare.se/ioccc/ioccc_gavare.c.html) an unobfuscated version that was used -during development, which we have included in the file -[gavare.r3.c](gavare.r3.c). To compile, try: +The alt code, [gavare.alt.c](gavare.alt.c), allows you to change the size of the +image as well as the anti-alias setting, when compiling. +The author also provided [on their web page for the +entry](https://gavare.se/ioccc/ioccc_gavare.c.html) an unobfuscated version that +was used during development, which we have included in the file +[gavare.r3.c](gavare.r3.c). + +Finally, there's an untested version for Windows, +[gavare.alt2.c](gavare.alt2.c), that sets binary mode on `stdout`. + + +### Alternate build: + +To build the configurable and unobfuscated versions: ```sh make alt ``` -Use `gavare.r3` as you would `gavare` above. +To change the default size from 1024x768 try: + +```sh +make clobber CDEFINE="-DXX=640 -DYY=480" alt +``` + +You might also wish to change the anti-alias setting: + +```sh +make clobber CDEFINE="-DAA=2" alt +``` + +This is not possible with the author's version but it is with the Windows +version (see below). + +As the Windows version will not compile on most viewers' systems we do not build +it with `make alt`; instead try: + +```sh +make alt2 +``` + + +### Alternate use: + +Use `gavare.alt`, `gavare.r3` or `gavare.alt2` as you would `gavare` above. ## Judges' remarks: For users of systems that distinguish between text and binary mode (you know who you are), add a library call that specifies binary mode -for stdout as the first statement of `main()`, +for `stdout` as the first statement of `main()`, or use `freopen("ioccc_ray.ppm", "wb", stdout);` and do not use redirection. A freely distributable command-line version of Microsoft Visual C @@ -55,15 +92,17 @@ It is possible to write some kinds of programs in C without using reserved words. For very short and trivial programs, it usually isn't very hard to write a variant using no reserved words, but with this program I want to show that also non-trivial programs can be written this way. This IOCCC -entry contains no reserved words (I don't count 'main' as a reserved word, +entry contains no reserved words (I don't count `main` as a reserved word, although the compiler gives it special meaning) and no preprocessor directives. -The program is a small ray-tracer. The first line of the source code may -be modified if you want the resulting image to be of some other resolution -than the predefined. The `A` value is an anti-alias factor. Setting it to -`1` disables the anti-aliasing feature (this makes the output look bad), but -setting it too high makes the trace take a lot more time to complete. +The program is a small +[ray-tracer](https://en.wikipedia.org/wiki/Ray_tracing_(graphics)). The first +line of the source code may be modified if you want the resulting image to be of +some other resolution than the predefined. The `A` value is an anti-alias +factor. Setting it to `1` disables the anti-aliasing feature which makes the +output look bad, but setting it too high makes the trace take a lot more time +to complete. The ppm image can then be viewed using an image viewer of your own choice. (Running the ray-tracer may take several minutes, even on fast machines, @@ -75,6 +114,7 @@ declarations are implicit. There will no doubt be _lots_ of warnings, no matter which compiler is used. Still, the source code should be word- length-independent and endianness-independent. + ### Humor Another reason for writing code without using reserved words is that many diff --git a/2004/gavare/gavare.alt.c b/2004/gavare/gavare.alt.c new file mode 100644 index 000000000..510b5ffd5 --- /dev/null +++ b/2004/gavare/gavare.alt.c @@ -0,0 +1,48 @@ +#ifndef XX +#define XX 1024 +#elif XX < 1 +#undef XX +#define XX 1024 +#endif + +#ifndef YY +#define YY 768 +#elif YY < 1 +#undef YY +#define YY 768 +#endif + +#ifndef AA +#define AA 3 +#elif AA < 1 +#define AA 3 +#endif + +X=XX; Y=YY; A=AA; + +J=0;K=-10;L=-7;M=1296;N=36;O=255;P=9;_=1<<15;E;S;C;D;F(b){E="1""111886:6:??AAF" +"FHHMMOO55557799@@>>>BBBGGIIKK"[b]-64;C="C@=::C@@==@=:C@=:C@=:C5""31/513/5131/" +"31/531/53"[b ]-64;S=b<22?9:0;D=2;}I(x,Y,X){Y?(X^=Y,X*X>x?(X^=Y):0, I (x,Y/2,X +)):(E=X); }H(x){I(x, _,0);}p;q( c,x,y,z,k,l,m,a, b){F(c +);x-=E*M ;y-=S*M ;z-=C*M ;b=x* x/M+ y*y/M+z +*z/M-D*D *M;a=-x *k/M -y*l/M-z *m/M; p=((b=a*a/M- +b)>=0?(I (b*M,_ ,0),b =E, a+(a>b ?-b:b)): -1.0);}Z;W;o +(c,x,y, z,k,l, m,a){Z=! c? -1:Z;c <44?(q(c,x ,y,z,k, +l,m,0,0 ),(p> 0&&c!= a&& (p0 +&&Z>=0? (e+=h*W/M,f+=i*W/M,g+=j*W/M,F(Z),u=e-E*M,v=f-S*M,w=g-C*M,b=(-2*u-2*v+w) +/3,H(u*u+v*v+w*w),b/=D,b*=b,b*=200,b/=(M*M),V=Z,E!=0?(u=-u*M/E,v=-v*M/E,w=-w*M/ +E):0,E=(h*u+i*v+j*w)/M,h-=u*E/(M/2),i-=v*E/(M/2),j-=w*E/(M/2),n(e,f,g,h,i,j,d-1 +,Z,0,0),Q/=2,T/=2, U/=2,V=V<22?7: (V<30?1:(V<38?2:(V<44?4:(V==44?6:3)))) +,Q+=V&1?b:0,T +=V&2?b :0,U+=V &4?b:0) :(d==P?(g+=2 +,j=g>0?g/8:g/ 20):0,j >0?(U= j *j/M,Q =255- 250*U/M,T=255 +-150*U/M,U=255 -100 *U/M):(U =j*j /M,UO? O: Q;T=T<0? 0:T>O?O:T;U=U<0?0: +U>O?O:U;}R;G;B ;t(x,y ,a, b){n(M*J+M *40*(A*x +a)/X/A-M*20,M*K,M +*L-M*30*(A*y+b)/Y/A+M*15,0,M,0,P, -1,0,0);R+=Q ;G+=T;B +=U;++a +#include +#include +X=XX; Y=YY; A=AA; + +J=0;K=-10;L=-7;M=1296;N=36;O=255;P=9;_=1<<15;E;S;C;D;F(b){E="1""111886:6:??AAF" +"FHHMMOO55557799@@>>>BBBGGIIKK"[b]-64;C="C@=::C@@==@=:C@=:C@=:C5""31/513/5131/" +"31/531/53"[b ]-64;S=b<22?9:0;D=2;}I(x,Y,X){Y?(X^=Y,X*X>x?(X^=Y):0, I (x,Y/2,X +)):(E=X); }H(x){I(x, _,0);}p;q( c,x,y,z,k,l,m,a, b){F(c +);x-=E*M ;y-=S*M ;z-=C*M ;b=x* x/M+ y*y/M+z +*z/M-D*D *M;a=-x *k/M -y*l/M-z *m/M; p=((b=a*a/M- +b)>=0?(I (b*M,_ ,0),b =E, a+(a>b ?-b:b)): -1.0);}Z;W;o +(c,x,y, z,k,l, m,a){Z=! c? -1:Z;c <44?(q(c,x ,y,z,k, +l,m,0,0 ),(p> 0&&c!= a&& (p0 +&&Z>=0? (e+=h*W/M,f+=i*W/M,g+=j*W/M,F(Z),u=e-E*M,v=f-S*M,w=g-C*M,b=(-2*u-2*v+w) +/3,H(u*u+v*v+w*w),b/=D,b*=b,b*=200,b/=(M*M),V=Z,E!=0?(u=-u*M/E,v=-v*M/E,w=-w*M/ +E):0,E=(h*u+i*v+j*w)/M,h-=u*E/(M/2),i-=v*E/(M/2),j-=w*E/(M/2),n(e,f,g,h,i,j,d-1 +,Z,0,0),Q/=2,T/=2, U/=2,V=V<22?7: (V<30?1:(V<38?2:(V<44?4:(V==44?6:3)))) +,Q+=V&1?b:0,T +=V&2?b :0,U+=V &4?b:0) :(d==P?(g+=2 +,j=g>0?g/8:g/ 20):0,j >0?(U= j *j/M,Q =255- 250*U/M,T=255 +-150*U/M,U=255 -100 *U/M):(U =j*j /M,UO? O: Q;T=T<0? 0:T>O?O:T;U=U<0?0: +U>O?O:U;}R;G;B ;t(x,y ,a, b){n(M*J+M *40*(A*x +a)/X/A-M*20,M*K,M +*L-M*30*(A*y+b)/Y/A+M*15,0,M,0,P, -1,0,0);R+=Q ;G+=T;B +=U;++a