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