From 2e99bb2a2015f0cd16346ba1e09bdbdc23da4ed6 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 18 Nov 2023 12:32:02 -0800 Subject: [PATCH] Add 2004/schnitzi/try.sh + make it use fgets() Format/typo check README.md file. I also slowed down the animations as well as in modern systems they go too fast, especially the Star Wars scrolling text one. --- 2004/schnitzi/README.md | 42 +++++++++++++------------------------ 2004/schnitzi/schnitzi.c | 3 ++- 2004/schnitzi/schnitzi.inp0 | 2 +- 2004/schnitzi/schnitzi.inp1 | 2 +- 2004/schnitzi/try.sh | 26 +++++++++++++++++++++++ thanks-for-fixes.md | 11 +++++++++- 6 files changed, 55 insertions(+), 31 deletions(-) create mode 100755 2004/schnitzi/try.sh diff --git a/2004/schnitzi/README.md b/2004/schnitzi/README.md index 8366e7a92..560f3b836 100644 --- a/2004/schnitzi/README.md +++ b/2004/schnitzi/README.md @@ -8,36 +8,20 @@ make ## To use: ```sh -./schnitzi +./schnitzi /dev/null| vi -./schnitzi /dev/null| vi +./try.sh ``` -For others, create an output file and use your system -pasteboard/selection/cut buffer to "input" the output into vi: - -```sh -./schnitzi schnitzi.out0 -./schnitzi schnitzi.out1 -``` NOTE: if you're one of those who don't know how to exit `vi` :-) don't worry as it will exit for you. -NOTE: this entry will make vi(m) swap files in the current working directory. -You might wish to clean them up. We could say how but lest there is another file -that matches the glob we won't. In any event vi swap files start with a dot -followed by the file name followed by another dot followed by `s` and two more -letters like. If no file is opened it will not have the file name but just be -e.g. `.swp`. When a second letter has no remaining availabilities it goes to -another one e.g. `u`. - ## Judges' remarks: @@ -64,9 +48,10 @@ string contains cursor navigation commands, you can go back and overwrite things that were already inserted earlier in string, anywhere on the screen. Can you see where this is going? + ### ANIMATION! -The program takes input from stdin which defines the animated +The program takes input from `stdin` which defines the animated elements (sprites) that appear on the screen. For each sprite, you can specify exactly when and how long it will appear, and which direction it is moving. Also, the sprite can oscillate between @@ -75,16 +60,17 @@ Forgive me, animators, if I'm mangling the terminology. Sprites which appear later in the input file will be drawn in front of sprites which appear earlier. -The output, to stdout, is a string which, when pasted into vi, will -perform the animation defined in the input. (The vi editor is a -common (and ancient) editor that should be available on most Unix, -Linux, Solaris, and Mac OS X machines; you can get it on Windows -by installing Cygwin, which is how I do it.) +The output, written to `stdout`, is a string which, when pasted into vi, will +perform the animation defined in the input. (The vi editor is a common (and +ancient) editor that should be available on most Unix, Linux, Solaris, and macOS +systems; you can get it on Windows by installing Cygwin, which is how I do +it.) + ### THE INPUT It's easiest to place the input in a file, so you can redirect it -to stdin when running the program. What follows is a detailed +to `stdin` when running the program. What follows is a detailed description of the input file format. The first line is specified thusly: @@ -93,12 +79,12 @@ The first line is specified thusly: [duration] [timefactor] ``` -The first parameter, duration, defines how long the animation will run. The +The first parameter, `duration`, defines how long the animation will run. The second, `timefactor`, is used as sort of a fudge factor for machines that run too fast to see the animation. A `timefactor` of 0 means, "run the animation as fast as you can". On a pretty fast machine, I've had to set it as high as 2000 to get the animation to slow down sufficiently. Note that the higher the -`timefactor`, the longer the output string that you'll have to copy- and-paste, +`timefactor`, the longer the output string that you'll have to copy and paste, as extra characters are necessary to "waste time" between frames. Following the first line parameters, you may have up to nine @@ -139,6 +125,7 @@ Input is terminated by end of file. Duh. Two samples input files are included; one a nice pastoral park scene, the other a bit of scrolling text. + ### RUNNING THE ANIMATION Try one of these methods to get the animation to run: @@ -164,6 +151,7 @@ is a right-click menu option on the top window bar. 3. Memorize the output, and type it into vi really really fast. + ### A FINAL NOTE I would like to remind the Pixar Animation Studios that I retain diff --git a/2004/schnitzi/schnitzi.c b/2004/schnitzi/schnitzi.c index 15d36f47b..c6e7e1cda 100644 --- a/2004/schnitzi/schnitzi.c +++ b/2004/schnitzi/schnitzi.c @@ -1,4 +1,5 @@ #include +#define gets(x) fgets((x),100,stdin) #define l "==================================================" #define m " " int _( @@ -6,7 +7,7 @@ float x, float y){ return x>=0&&x<50&&y>=0&&y<20;} int main (){ -char a[2][20][51],c[9][4][51][51],d[100]; +char a[2][20][51],c[9][4][100][100],d[100]; int e,f,g,h=0,i,j=0,k,b=0,n[9],o[9],p[9],x[9],y[9],q[9],r,s,t; float u[9],v[9],w[9],z[9]; printf ("i%s\033Yppppppppppppppppppp1G0",l); diff --git a/2004/schnitzi/schnitzi.inp0 b/2004/schnitzi/schnitzi.inp0 index b1ea4df59..732ae574c 100644 --- a/2004/schnitzi/schnitzi.inp0 +++ b/2004/schnitzi/schnitzi.inp0 @@ -1,4 +1,4 @@ -100 1000 +100 2000 0 1000 0 10 0.0 0.0 50 2 1 ------------------------------\~~~~~~~~~~~~~~~~~~~ \__________________ diff --git a/2004/schnitzi/schnitzi.inp1 b/2004/schnitzi/schnitzi.inp1 index bd5ab7412..af82e608c 100644 --- a/2004/schnitzi/schnitzi.inp1 +++ b/2004/schnitzi/schnitzi.inp1 @@ -1,4 +1,4 @@ -30 2000 +30 10000 0 100 10 25 0.0 -1.0 25 4 1 A long time ago, in a diff --git a/2004/schnitzi/try.sh b/2004/schnitzi/try.sh new file mode 100755 index 000000000..00fe66539 --- /dev/null +++ b/2004/schnitzi/try.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2004/schnitzi +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + + +echo "$ ./schnitzi &2 +./schnitzi &2 +./schnitzi