Fix and add alt code to 2006/sloane

Alt code uses usleep() with the macro Z (default 65000 but one can
override it - I explain in the README.md how to do this) to let one see
in modern systems what is going on. This also allows for those (like
myself) who don't like to see text (or other things) zooming by very
rapidly. The former is more important for most people I'd think. It
didn't even occur to me what was going on until I slowed it down and the
award title didn't mean anything to me until after it either though I
read about this entry a long time ago. But still the latter part is
useful as well.

Format fix README.md.

Fix compilation in some systems: compilation issue is that some
systems (looking at fedora and CentOS linux and probably others) don't
link in lm by default.

The other issue is what the author stated - that not using certain
includes might cause problems. To not ruin the format of the code I
added -include ... to the Makefile.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-30 09:59:04 -07:00
1 parent ae310f9372
commit afe7bc1a17
3 files changed
+84 -20

No files matched your search

+8 -5
View File
@@ -58,11 +58,11 @@ ARCH=
# Defines that are needed to compile
#
CDEFINE=
CDEFINE= -DZ=65000
# Include files that are needed to compile
#
CINCLUDE=
CINCLUDE= -include math.h -include stdio.h
# Optimization
#
@@ -74,7 +74,7 @@ CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# Libraries needed to build
#
LIBS=
LIBS= -lm
# C compiler to use
#
@@ -115,8 +115,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 $@ ${LIBS}
# data files
#
data: ${DATA}
+44 -15
View File
@@ -1,9 +1,7 @@
# Homer's Favorite
Andy Sloane
1041 Seneca St.
Hartford, WI 53027
US
Andy Sloane
US
## To build:
@@ -15,7 +13,10 @@ make
work with clang which is stricter on the type of args to main(). Curiously
although clang requires the types of args to be strictly correct it allows for
only one arg which he made it as the second arg was not used and this allows for
a closer match to the original format of the entry. Thank you Cody for your
a closer match to the original format of the entry. He also made sure that the
Makefile links in `libm` as not all systems do this by default. Since the author
suggested that the lack of certain `#include`s might break the program in some
systems he added `-include ...` to the Makefile as well. Thank you Cody for your
assistance!
@@ -28,6 +29,10 @@ assistance!
WARNING: if you are easily overstimulated with fast movement or have
photosensitivity please be careful running this entry!
An alternatively version of this entry exists so that one can actually see what
is going on. This is also more ideal for those who are overstimulated by fast
movements. See the alternate code section below.
## Try:
@@ -35,6 +40,30 @@ photosensitivity please be careful running this entry!
echo "Do or do not. There is no try."
```
### Alternate code:
The alternate version, provided by [Cody Boone
Ferguson](/winners.html#Cody_Boone_Ferguson), uses `usleep()` so one can enjoy
the entry with modern systems and which will not be too stimulating for those
who have a problem with fast moving text (like himself). It uses the `Z` macro
as the parameter to `usleep()` which you can override. The default is
`-DZ=65000`. To compile with the default:
```sh
make alt
```
If you wish to override the sleep value try something like:
```sh
make CDEFINE="-DZ=70000" clobber alt
```
Use `sloane.alt` as you would `sloane` above.
Thank you Cody!
## Judges' Comments:
Looks almost good enough to eat, dunnit? I suppose you could argue that,
@@ -43,13 +72,14 @@ at first blush, this looks like a self-reproducing program.
## Author's remarks:
This program doesn't require any special build options, other than that it
uses sin and cos and hence requires the math library.
uses `sin()` and `cos()` and hence requires the math library.
You will almost certainly get a compiler warning because I declared a bunch
of global ints without types. The code looks better this way, though, I
think. There are also no #includes, so there may be warnings for
undeclared references to printf, etc. There's a chance that my failure to
include math.h or declare sin or cos will make the donut not render
think. There are also no `#include`s, so there may be warnings for
undeclared references to `printf()`, etc. There's a chance that my failure to
include `math.h` or declare `sin()` or `cos()` will make the
[donut](https://en.wikipedia.org/wiki/Doughnut) not render
properly -- it's worked on every system I've tried so far though.
You will need some kind of VT100-ish emulation; so while this compiles and
@@ -59,12 +89,11 @@ The shape of the source gives a hint about its output: it's a little
animation of a shaded donut rotating over an infinite checkerboard. Like
many IOCCC entries, it is thus self-documenting.
I wanted to create something as "pure" as I could - meaning that the
entire source code is shaped into a work of art, without being prefixed
by any #define hacks, or even #includes, _and_ is portable enough to not
require any special libraries to do the animating. I achieved this with
two standard escape codes for clearing the screen and moving the cursor
back to the top-left.
I wanted to create something as "pure" as I could - meaning that the entire
source code is shaped into a work of art, without being prefixed by any
`#define` hacks, or even `#includes`, _and_ is portable enough to not require
any special libraries to do the animating. I achieved this with two standard
escape codes for clearing the screen and moving the cursor back to the top-left.
The donut isn't raytraced. It's much simpler than that.
+32
View File
@@ -0,0 +1,32 @@
_,x,y,o ,N;char b[1920] ;p(n,c)
{for(;n --;x++) c==10?y +=80,x=
o-1:x>= 0?80>x? c !='~'?b
[y+x]=c :0: 0:0;}c(
q,l,r) char*l,*r;{while (q>=0)q
=("E" "?yYrIxC{e^}KhE>[|LXbj}" "dOVsJ"
"@" "idOV{Yab[bW}[bW}\\qFywyv{D" "ma\\A"
"" "Ztq?Lyw>e{|Zq>Y\\gq\\qI[tYBe{w" "yvDZE\
vBA[`_" "Lo>}KcqdYrWqKxzKtW]|DXRwsfcUaT\\\
KXw{Y" "RsFwsFwsFw{zaqyaz|FmMpyaoyI\\]cuUw{J"
[_/6] -62>>_++%6&1?r[q]:l[q])-99;return q;}E(a
){for (o=x=a,y=0,_=0;_ <1006;)a=" /\\\n"
"~|_."[c(6,"b" "cd\\a[g","^`" "_e"
"]fh")+8], p( "#$%" "&'()*+,-.1"[ c(11
,"_ac[]\\YZi" "jkm", "`bd^efghXWlV" )+13
]-34,a);}main (k ){ float z[1920] ,A=0
,B=0 ,i,j; puts("" "\x1b" "[2J");for(;;
) { float e=sin(A ), n= sin(B),g=cos(
A),m =cos(B);for(k =0;k< 1840;k++)y=-k
/80- 10,o=41+(k%80- 40)*1.3/y+n,N=
A-100.0/y, b[k]= ".#"[o+N&1],z[k] =0;E(
80-(int)(9*B)%250);for(j=0;6.28>j;j+=0.07 )for(
i=0;6.28>i;i+=0.02) { float c=sin(i),d =cos(j
),f=sin(j),h=d+2,D=15/(c*h*e+f*g+5 ),l=cos
(i),t=c *h*g-f*e;x=40+2*D*(l*h*m-t*n),y= 12
+D*(l*h *n+t*m),o=x+80*y,N=8*((f*e-c *d*
g)*m-c* d*e-f*g-l*d*n);if(D>z[o] )z[o]
=D,b[o] =" ..,,-++=#$@"[ N>0?N:0
] ; } printf(
"\x1b[" "H" );usleep(Z);for(k =1;1841
>k;k++) putchar (k%80?b [k]:10)
; A += 0.053;B +=0.037 ; } }