├── .gitignore ├── Makefile ├── Makefile.orig ├── README.md ├── clock.txt ├── column.txt ├── column2.txt ├── column3.txt ├── corners.txt ├── dripping-pan.txt ├── endoh1.c ├── endoh1_color.c ├── endoh1_deobfuscate.c ├── evaporation.txt ├── flat.txt ├── fountain.txt ├── funnel.txt ├── funnel2.txt ├── funnel3.txt ├── glass-half-empty.txt ├── hint.css ├── hint.html ├── leidenfrost.txt ├── logo.txt ├── pour-out.txt └── tanada.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ############# 2 | ## Fluid ASCII 3 | ############# 4 | 5 | endoh1 6 | 7 | ############# 8 | ## Windows detritus 9 | ############# 10 | 11 | # Windows image file caches 12 | Thumbs.db 13 | ehthumbs.db 14 | 15 | # Folder config file 16 | Desktop.ini 17 | 18 | # Recycle Bin used on file shares 19 | $RECYCLE.BIN/ 20 | 21 | # Mac crap 22 | .DS_Store 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env make 2 | # 3 | # 2012 makefile 4 | # 5 | # This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis 6 | # is licensed under: 7 | # 8 | # Creative Commons Attribution-ShareAlike 3.0 Unported License. 9 | # 10 | # See: http://creativecommons.org/licenses/by-sa/3.0/ 11 | 12 | 13 | ################ 14 | # tool locations 15 | ################ 16 | # 17 | SHELL= /bin/bash 18 | CP= cp 19 | CPP= cpp 20 | GUNZIP= gunzip 21 | LD= ld 22 | MAKE= make 23 | RM= rm 24 | SED= sed 25 | TAR= tar 26 | TRUE= true 27 | 28 | # Set X11_LIBDIR to the directory where the X11 library resides 29 | # 30 | X11_LIBDIR= /usr/X11R6/lib 31 | 32 | # Set X11_INCLUDEDIR to the directory where the X11 include files reside 33 | # 34 | X11_INCDIR= /usr/X11R6/include 35 | 36 | # Compiler warnings 37 | # 38 | #CWARN= 39 | #CWARN= -Wall -W 40 | CWARN= -Wall -W -pedantic 41 | 42 | # compiler standard 43 | # 44 | #CSTD= 45 | #CSTD= -ansi 46 | CSTD= -std=c99 47 | 48 | # compiler bit architecture 49 | # 50 | # Some entries require 32-bitness: 51 | # ARCH= -m32 52 | # 53 | # Some entries require 64-bitess: 54 | # ARCH= -m64 55 | # 56 | # By default we assume nothing: 57 | # 58 | ARCH= 59 | 60 | # optimization 61 | # 62 | # Most compiles will safely use -O2. Some can use only -O1 or -O. 63 | # A few compilers have broken optimizers or this entry make break 64 | # under those buggy optimizers and thus you may not want anything. 65 | # 66 | #OPT= 67 | #OPT= -O 68 | #OPT= -O1 69 | OPT= -O2 70 | #OPT= -O3 71 | 72 | # Libraries needed to build 73 | # 74 | LIBS= -lm 75 | 76 | # default flags for ANSI C compilation 77 | # 78 | CFLAGS= ${CWARN} ${CSTD} ${ARCH} ${OPT} 79 | 80 | # ANSI compiler 81 | # 82 | # Set CC to the name of your ANSI compiler. 83 | # 84 | # Some entries seem to need gcc. If you have gcc, set 85 | # both CC and MAY_NEED_GCC to gcc. 86 | # 87 | # If you do not have gcc, set CC to the name of your ANSI compiler, and 88 | # set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just : 89 | # to disable such programs. 90 | # 91 | CC= cc 92 | #CC=clang 93 | MAY_NEED_GCC= gcc 94 | 95 | 96 | ############################## 97 | # Special flags for this entry 98 | ############################## 99 | # 100 | ENTRY= endoh1 101 | DATA= column.txt column2.txt column3.txt corners.txt dripping-pan.txt \ 102 | evaporation.txt flat.txt fountain.txt funnel.txt funnel2.txt \ 103 | funnel3.txt leidenfrost.txt logo.txt pour-out.txt tanada.txt 104 | ALT_OBJ= endoh1_color.o 105 | ALT_ENTRY= endoh1_color 106 | 107 | # The factor of gravity 108 | # 109 | G=1 110 | 111 | # The factor of pressure 112 | # 113 | P=4 114 | 115 | # The factor of viscosity 116 | # 117 | V=8 118 | 119 | ################# 120 | # build the entry 121 | ################# 122 | # 123 | all: ${ENTRY} ${DATA} 124 | @${TRUE} 125 | 126 | ${ENTRY}: ${ENTRY}.c 127 | ${CC} ${CFLAGS} -DG=$G -DP=$P -DV=$P $< -o $@ ${LIBS} 128 | 129 | # alternative executable 130 | # 131 | alt: ${ALT_ENTRY} 132 | @${TRUE} 133 | 134 | endoh1_deobfuscate: endoh1_deobfuscate.c 135 | ${CC} ${CFLAGS} -DG=$G -DP=$P -DV=$P $< -o $@ ${LIBS} 136 | 137 | endoh1_color: endoh1_color.c 138 | ${CC} ${CFLAGS} -DG=$G -DP=$P -DV=$P $< -o $@ ${LIBS} 139 | 140 | # data files 141 | # 142 | data: ${DATA} 143 | @${TRUE} 144 | 145 | 146 | ############### 147 | # utility rules 148 | ############### 149 | # 150 | everything: all alt 151 | 152 | clean: 153 | ${RM} -f ${ENTRY}.o ${ALT_OBJ} 154 | 155 | clobber: clean 156 | ${RM} -f ${ENTRY} ${ALT_ENTRY} 157 | 158 | nuke: clobber 159 | @${TRUE} 160 | 161 | dist_clean: nuke 162 | @${TRUE} 163 | 164 | install: 165 | @echo "Surely you're joking Mr. Feynman!" 166 | @${TRUE} 167 | 168 | # backwards compatibility 169 | # 170 | build: all 171 | @${TRUE} 172 | 173 | 174 | ################## 175 | # 133t hacker rulz 176 | ################## 177 | # 178 | love: 179 | @echo 'not war?' 180 | @${TRUE} 181 | 182 | haste: 183 | $(MAKE) waste 184 | @${TRUE} 185 | 186 | waste: 187 | @echo 'waste' 188 | @${TRUE} 189 | 190 | easter_egg: 191 | @echo you expected to mis-understand this $${RANDOM} magic 192 | @echo chongo '' "/\\oo/\\" 193 | @echo Readers shall be disallowed from not being unable to partly misunderstand this partocular final echo. 194 | 195 | # Understand the history of "I Am the Walrus" and 196 | # and in particular John Lennon's remarks on that 197 | # song and you might be confused about these next 198 | # rules in a different way. :-) 199 | # 200 | supernova: nuke 201 | @-if [ -r .code_anal ]; then \ 202 | ${RM} -f .code_anal_v3; \ 203 | else \ 204 | echo "You are not expected to understand this"; \ 205 | fi 206 | @${TRUE} 207 | 208 | deep_magic: 209 | @-if [ -r .code_anal ]; then \ 210 | ccode_analysis --deep_magic 1c2c85c7a02c55d1add91967eca491d53c101dc1 --FNV1a_hash 256-bit "${ENTRY}"; \ 211 | else \ 212 | echo "Understand different"; \ 213 | fi 214 | @${TRUE} 215 | 216 | magic: deep_magic 217 | @-if [ -r .code_anal ]; then \ 218 | ccode_analysis --mode 21701 --level 23209 --FNV1a_hash 256-bit "${ENTRY}"; \ 219 | else \ 220 | echo "These aren't the droids you're looking for Mr. Spock!"; \ 221 | fi 222 | @${TRUE} 223 | -------------------------------------------------------------------------------- /Makefile.orig: -------------------------------------------------------------------------------- 1 | # the factor of gravity 2 | G=1 3 | # the factor of pressure 4 | P=4 5 | # the factor of viscosity 6 | V=8 7 | RM= rm 8 | TRUE= true 9 | CWARN= -Wall -W -Wextra -pedantic 10 | CSTD= -std=c99 -D_BSD_SOURCE 11 | CFLAGS= ${CWARN} ${CSTD} ${ARCH} ${OPT} 12 | CC= gcc 13 | ENTRY= prog 14 | 15 | all: ${ENTRY} 16 | @${TRUE} 17 | 18 | ${ENTRY}: ${ENTRY}.c 19 | ${CC} ${CFLAGS} -DG=$G -DP=$P -DV=$P ${ENTRY}.c -o $@ -lm 20 | 21 | clean: 22 | $(RM) -f ${ENTRY} 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Most complex ASCII fluid 2 | Honorable mention 3 | 4 | Yusuke Endoh 5 | 6 | 7 | ## Usage steps: 8 | 9 | * `git clone https://github.com/LeoColomb/FluidASCII.git` 10 | * `cd FluidASCII` 11 | * `make endoh1` 12 | * `./endoh1 < configuration.txt` 13 | 14 | You can also `make endoh1_color` and run this binary instead to get colored output. 15 | 16 | ## Author's comments: 17 | ### Synopsis 18 | 19 | **DO NOT FORGET "-DG=1 -DP=4 -DV=8"** and make your terminal window larger 20 | than 80 x 25. 21 | 22 | gcc endoh1.c -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -o endoh1 -lm 23 | ./endoh1 < endoh1.c 24 | ./endoh1 < logo.txt 25 | ./endoh1 < column.txt 26 | ./endoh1 < pour-out.txt 27 | ./endoh1 < tanada.txt 28 | 29 | 30 | ### What it is 31 | 32 | ,___. ,. ,. ,. ,___. ,. ,. ,. 33 | |/--' || `' || |/--' `' || |\_. 34 | |\__. || ,. ,. ,. ,__/| |\__. ,. ,____. ,. ,. || ,_. |/-' ,_. ,__. 35 | |/--' || || || || |/-\| `--\| || |/\/\| || || || ,/-\. || ,/-\. |/-\. 36 | || || `\_/| || |\_/| ,__/| || |||||| `\_/| || `\_/\.`\_. `\_/' || `' 37 | `' `' `--' `' `---' `---' `' `'`'`' `--' `' `-'`' `-' `-' `' 38 | 39 | 40 | ,.,. ,.,. 41 | ,/\/\. ,. ,. ,. ,/\/\. ,. ,. ,__. 42 | |||#/' || `' ,_.|| |||#/' `',_.,__. || ||\\. ,. 43 | |||#\. || ,. ,. ,.,/#||| |\//\. ,.|#||##| ,. ,. || ,.,. |\/-' ,.,. ,.|\. 44 | |\/--' ||,/\.|| |||#/\/| `\#||| |||#||/\|,/\.|| ||,/'`\.|#| ,/'`\.|\/-\. 45 | `\| ||`\#||| |||#||\| ,//\/| ||`\|||||`\#||| ||`\.,/\/\|,.`\.,/'`\| `' 46 | `' `' `-'`' `'`-'`-' `-'`-' `' `'`'`' `-'`' `' `'`--'`'`' `'`' `' 47 | 48 | 49 | ,_.,_. ,. ,. ,. ,_.,_. ,. ,. ,. 50 | |#||#| || `' || |#||#| `' || ||,_. 51 | ||\/#| ||,. ,. ,.,_.,/| |\||#| ,.,_.,__.,. ,. || ,.,. |||#| ,.,. ,.,_. 52 | |||##| |||| || |||#||#| |#||#| |||#||##||| || ||,/||\.||`-',/||\.|||#\. 53 | ||`--' ||`\_.|| |||\||#| |#||#| ||||'||\|`\_.|| ||`\||#|`\.,.`\||/'||`--' 54 | `' `' |#||| `'|#||#| |#||#| `'`' `'`' |#||| `' |||/' |||| |||| `' 55 | `-'`' `-'`-' `-'`-' `-'`' `'`' `'`' `'`' 56 | 57 | 58 | This program is a fluid simulator using "Smoothed-particle hydrodynamics (SPH)" 59 | method. 60 | 61 | 62 | 63 | The SPH particles represent the fluid flow. Particles have information about 64 | the position, density, and velocity. In every simulation step, they are 65 | changed by pressure force, viscosity force, and external force (i.e., gravity). 66 | 67 | This program reads a text from standard input, and uses it as an initial 68 | configuration of the particles. The character `#` represents "wall particle" (a 69 | particle with fixed position), and any other non-space characters represent 70 | free particles. 71 | 72 | The compilation options `-DG=1 -DP=4 -DV=8` represent, respectively, the factor 73 | of gravity, pressure, and viscosity. By changing their values, you can see 74 | different fluid behavior. 75 | 76 | "Marching square"-like algorithm is used to render the particles. 77 | 78 | 79 | 80 | 81 | ### Portability 82 | 83 | The program requires a C99 compiler; it uses `complex` types and one-line 84 | comments. It also uses `usleep`, which may require `-D_BSD_SOURCE` or somewhat 85 | to build with no warning. Under these conditions, it should be portable. 86 | At least, recent compilers with `-std=c99 -Wall -W -Wextra -pedantic` says 87 | nothing. 88 | 89 | gcc -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c 90 | clang -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c 91 | 92 | I expect it to work in any Unix-like environment. VTxxx/ANSI sequences are 93 | used to clear screen and move cursor to home. 94 | 95 | I've tested with gcc-4.6.3 and clang-3.0 on Linux (Ubuntu 12.04) 96 | and gcc-4.5.3 and clang-3.1 on Cygwin. On Cygwin, gcc and clang complain about 97 | a usage of `I` (complex's imaginary unit), but I bet this is cygwin's issue; 98 | it is surely a C99 feature. 99 | 100 | 101 | ### Obfuscation w/ Spoiler 102 | 103 | First of all, the source code itself serves as an initial configuration. 104 | Preprocessing directives (such as `#include`)'s `#` serve as walls. 105 | 106 | This program uses `double complex` to represent any 2D vector. But, note that 107 | x-axis and y-axis is swapped (real axis = y-axis, imaginary axis = x-axis). 108 | The purpose of swapping is not only obfuscation, but also short coding: for 109 | example, to add gravity to total force, `force += G` suffices, rather than 110 | `force += G*I`. 111 | (Incidentally, you can exert horizontal gravity by using, such as, `-DG=I`) 112 | 113 | Every five entries of `double complex a[]` contain information of one particle: 114 | position, wall-flag, density, force, and velocity, in turn. 115 | 116 | You can use `G`, `P`, and `V` as a guide to find the calculation code of 117 | gravity, pressure, and viscosity forces. 118 | 119 | Though some assignments may look meaningless, it is actually meaningful; it 120 | extracts "integer part of real part" from a complex value by assigning (and 121 | casting) it to an integer-type variable. 122 | 123 | 124 | ### Notes about Additional Files 125 | 126 | "logo.txt" is a source of the logo in this remark file. 127 | 128 | "column.txt" is a water column collapse, which is a popular demo of SPH. 129 | 130 | "pour-out.txt" pours you a cup of tea. 131 | 132 | "tanada.txt" simulates "Terrace farming". ("Tanada" means a "terraced rice 133 | fields" in Japanese.) 134 | 135 | "clock.txt" is a "water" clock created by HAMANO Tsukasa. 136 | 137 | Other \*.txt files are due to the judges. 138 | 139 | 140 | "endoh1\_color.c" is a variant that shows the density by using terminal 256 141 | colors. 142 | 143 | 144 | ### Acknowledgment 145 | 146 | I would like to thank my wife @hirekoke for her teaching me the SPH method. 147 | 148 | The judges ordered suggested creating a color version 149 | after the judgment. 150 | 151 | The judges and HAMANO Tsukasa (The silver medalist at this IOCCC) kindly 152 | provided many configuration files. 153 | 154 | 155 | ## Judges' comments: 156 | ### To build: 157 | 158 | make endoh1 159 | 160 | ### To run: 161 | 162 | ./endoh1 < configuration.txt 163 | 164 | ### Try: 165 | 166 | ./endoh1 < endoh1.c 167 | 168 | ./endoh1 < pour-out.txt 169 | 170 | ./endoh1 < fountain.txt 171 | 172 | ### Selected Judges Remarks: 173 | 174 | Let's play Jeopardy! 175 | 176 | * A: An obfuscated program that deals with complex numbers and produces animated ASCII graphics. 177 | * Q: What is a Mandelbrot simulator? 178 | 179 | Bzzzt! 180 | 181 | Such heavily squeezed fluid simulation (this is parsed uniquely 182 | as fluids are not squeezable) has a few quirks that the judges were 183 | happy to experiment with. 184 | 185 | One configuration file was inspired by an [XKCD what if? entry](http://whatif.xkcd.com/6/). 186 | 187 | 188 | -------------------------------------------------------------------------------- 189 | 196 | -------------------------------------------------------------------------------- /clock.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | ##xxxxxxxxxxxxxxxxxxxx## 3 | ##xxxxxxxxxxxxxxxxxxxx## 4 | ##xxxxxxxxxxxxxxxxxxxx## 5 | ##xxxxxxxxxxxxxxxxxxxx## 6 | ##xxxxxxxxxxxxxxxxxxxx## 7 | ###xxxxxxxxxxxxxxxxxx### 8 | ###xxxxxxxxxxxxxxxx### 9 | ###xxxxxxxxxxxx### 10 | ### ### 11 | ### ### 12 | ### ### 13 | ### ### 14 | ### ### 15 | ### ### 16 | ### ### 17 | ### ### 18 | ## ## 19 | ## ## 20 | ## ## 21 | ## ## 22 | ## ## 23 | ######################## 24 | 25 | -------------------------------------------------------------------------------- /column.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ### ............... ### 7 | ### ................. ### 8 | ### ................. ### 9 | ### ................. ### 10 | ### ................. ### 11 | ### ................. ### 12 | ### ................. ### 13 | ### ................. ### 14 | ### ................. ### 15 | ### ................. ### 16 | ### ................. ### 17 | ### ................. ### 18 | ### ................. ### 19 | ### ................. ### 20 | ### ................. ### 21 | ### ............... ### 22 | ########################################################################## 23 | ######################################################################## 24 | -------------------------------------------------------------------------------- /column2.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ### .......... ### 6 | ### ........... ### 7 | ### ........... ### 8 | ### ........... ### 9 | ### ........... ### 10 | ### ........... ### 11 | ### ........... 12 | ### ........... 13 | ### ........... 14 | ### ........... ### 15 | ### ........... ### 16 | ### ........... ### 17 | ### ........... ### 18 | ### ........... ### 19 | ### ........... # ### 20 | ### .......... ### ### 21 | ############################################################################## 22 | ############################################################################ 23 | -------------------------------------------------------------------------------- /column3.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ### .......... ### 6 | ### .................................................................### 7 | ### ........... ### 8 | ### ........... ### 9 | ### ........... ### 10 | ### ........... ### 11 | ### ........... 12 | ### ........... 13 | ### ........... 14 | ### ........... ### 15 | ### ........... ### 16 | ### ........... ### 17 | ### ........... ### 18 | ### ........... ### 19 | ### ........... # ### 20 | ### .......... ### ### 21 | ############################################################################## 22 | ############################################################################ 23 | -------------------------------------------------------------------------------- /corners.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | # # 20 | # # 21 | # # 22 | #@ @# 23 | ############################################################################### 24 | -------------------------------------------------------------------------------- /dripping-pan.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | # # 10 | # # 11 | # @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ # 12 | #@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @# 13 | ##################################### ####################################### 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /endoh1.c: -------------------------------------------------------------------------------- 1 | # include// .IOCCC Fluid- # 2 | # include //2012 _Sim!_ # 3 | # include //|||| ,____. IOCCC- # 4 | # define h for( x=011; 2012/* # 5 | # */-1>x ++;)b[ x]//-' winner # 6 | # define f(p,e) for(/* # 7 | # */p=a; e,p10?32< x?4[/* ## 13 | ## */*r++ =w,r]= w+1,*r =r[5]= x==35, r+=9:0 ,w-I/* ## 14 | ## */:(x= w+2);; for(;; puts(o ),o=b+ 4){z(p [1]*/* ## 15 | ## */9,2) w;z(G, 3)(d*( 3-p[2] -q[2]) *P+p[4 ]*V-/* ## 16 | ## */q[4] *V)/p[ 2];h=0 ;f(p,( t=b+10 +(x=*p *I)+/* ## 17 | ## */80*( y=*p/2 ),*p+=p [4]+=p [3]/10 *!p[1]) )x=0/* ## 18 | ## */ <=x &&x<79 &&0<=y&&y<23?1[1 [*t|=8 ,t]|=4,t+=80]=1/* ## 19 | ## */, *t |=2:0; h=" '`-.|//,\\" "|\\_" "\\/\x23\n"[x/** ## 20 | ## */%80- 9?x[b] :16];;usleep( 12321) ;}return 0;}/* ## 21 | #### #### 22 | ############################################################################### 23 | **###########################################################################*/ 24 | -------------------------------------------------------------------------------- /endoh1_color.c: -------------------------------------------------------------------------------- 1 | # include// .IOCCC Fluid- # 2 | # include //2012 _Sim!_ # 3 | # include //|||| ,____. |||||| # 4 | # define c y+=( x=ctanh( -cabs/* # 5 | # */(4[t ]-=20) /2+9)* 3+3)*// # 6 | # define f(p,e) for(p/* # 7 | # */=a;e ,p (t+=12 );c 6, sprintf (t,/** ## 13 | ## */"%c" "[48%" "c5;%" "03dm" "%c",3 *9,e,c 36,e/* ## 14 | ## */?(t- b)%960 ?(15-t [11])[ "\x23" "/\\_" "\\"/* ## 15 | ## */"||" ",//|" ".-`' "]:10: 0)) y= 0020,c 01;}/* ## 16 | ## */void g( int i){7[t +=i]|= x/=2;* t+=y=p [2];/* ## 17 | ## */}int main() {for(;( x=getc (stdin ))>0;)w =10 x&& 28 | 0<= y&& 23> y?x =16 ,g( 0),g(12), 29 | g(+ 948 ),g (12 ),0 :0) ;h( 59) ;;; 30 | usleep( 12321); }return 0;} /*IOCCC '12 **/ 31 | -------------------------------------------------------------------------------- /endoh1_deobfuscate.c: -------------------------------------------------------------------------------- 1 | #include // .IOCCC Fluid- # 2 | #include //2012 _Sim!_ # 3 | #include //|||| ,____. IOCCC- # 4 | double complex a[97687], *p, *q, *r = a, w = 0, d; 5 | int x , y; 6 | char b [6856] = "\x1b[2J" "\x1b" "[1;1H ", *o = b, *t; 7 | int 8 | main() 9 | { 10 | 11 | for (; 0 < (x = getc(stdin));) 12 | w = x > 10 ? 32 < x ? 4[*r++ = w, r] = w + 1, *r = r[5] = x == 35, r += 9 : 0, w - I : (x = w + 2);; 13 | for (;; puts(o), o = b + 4) { 14 | for (p = a; p[2] = p[1] * 9, p < r; p += 5) 15 | for (q = a; w = cabs(d = *p - *q) / 2 - 1, q < r; q += 5) 16 | if (0 < (x = 1 - w)) 17 | p[2] += w * w; 18 | for (p = a; p[3] = G, p < r; p += 5) 19 | for (q = a; w = cabs(d = *p - *q) / 2 - 1, q < r; q += 5) 20 | if (0 < (x = 1 - w)) 21 | p[3] += w * (d * (3 - p[2] - q[2]) * P + p[4] * V - q[4] * V) / p[2]; 22 | for (x = 011; 2012 - 1 > x++;) 23 | b[x] = 0; 24 | for (p = a; (t = b + 10 + (x = *p * I) + 80 * (y = *p / 2), *p += p[4] += p[3] / 10 * !p[1]), p < r; p += 5) 25 | x = 0 <= x && x < 79 && 0 <= y && y < 23 ? 1[1[*t |= 8, t] |= 4, t += 80] = 1, *t |= 2 : 0; 26 | for (x = 011; 2012 - 1 > x++;) 27 | b[x] = " '`-.|//,\\" "|\\_" "\\/\x23\n"[x % 80 - 9 ? x[b] : 16];; 28 | 29 | usleep(12321); 30 | } return 0; 31 | } 32 | -------------------------------------------------------------------------------- /evaporation.txt: -------------------------------------------------------------------------------- 1 | @ 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | # # 20 | # # 21 | # # 22 | # # 23 | ############################################################################### 24 | -------------------------------------------------------------------------------- /flat.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | # # 10 | # # 11 | # # 12 | #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# 13 | ############################################################################### 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /fountain.txt: -------------------------------------------------------------------------------- 1 | 2 | x 3 | x 4 | x 5 | x 6 | x 7 | x 8 | x 9 | x 10 | x 11 | x 12 | x 13 | x 14 | x 15 | x 16 | x 17 | x 18 | x 19 | x 20 | ### x ### 21 | ### x ### 22 | ### x ### 23 | ############# 24 | -------------------------------------------------------------------------------- /funnel.txt: -------------------------------------------------------------------------------- 1 | # # 2 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 3 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 4 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 5 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 6 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 7 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 8 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 9 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# 10 | #xxxxxxxxxxxxxxxxxxxxxxxxxxxx# 11 | #xxxxxxxxxxxxxxxxxxxxxxxxxx# 12 | #xxxxxxxxxxxxxxxxxxxxxxxx# 13 | #xxxxxxxxxxxxxxxxxxxxxx# 14 | #xxxxxxxxxxxxxxxxxxxx# 15 | #xxxxxxxxxxxxxxxxxx# 16 | #xxxxxxxxxxxxxxxx# 17 | #xxxxxxxxxxxxxx# 18 | #xxxxxxxxxxxx# 19 | #xxxxxxxxxx# 20 | #xxxxxxxx# 21 | #xxxxxx# 22 | #xxxx# 23 | #### 24 | -------------------------------------------------------------------------------- /funnel2.txt: -------------------------------------------------------------------------------- 1 | ## ## 2 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 3 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 4 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 5 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 6 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 7 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 8 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 9 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## 10 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxx## 11 | ##xxxxxxxxxxxxxxxxxxxxxxxxxx## 12 | ##xxxxxxxxxxxxxxxxxxxxxxxx## 13 | ##xxxxxxxxxxxxxxxxxxxxxx## 14 | ##xxxxxxxxxxxxxxxxxxxx## 15 | ##xxxxxxxxxxxxxxxxxx## 16 | ##xxxxxxxxxxxxxxxx## 17 | ##xxxxxxxxxxxxxx## 18 | ##xxxxxxxxxxxx## 19 | ##xxxxxxxxxx## 20 | ##xxxxxxxx## 21 | ##xxxxxx## 22 | ##xxxx## 23 | ###### 24 | -------------------------------------------------------------------------------- /funnel3.txt: -------------------------------------------------------------------------------- 1 | ### ### 2 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 3 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 4 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 5 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 6 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 7 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 8 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 9 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### 10 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxx### 11 | ###xxxxxxxxxxxxxxxxxxxxxxxxxx### 12 | ###xxxxxxxxxxxxxxxxxxxxxxxx### 13 | ###xxxxxxxxxxxxxxxxxxxxxx### 14 | ###xxxxxxxxxxxxxxxxxxxx### 15 | ###xxxxxxxxxxxxxxxxxx### 16 | ###xxxxxxxxxxxxxxxx### 17 | ###xxxxxxxxxxxxxx### 18 | ###xxxxxxxxxxxx### 19 | ###xxxxxxxxxx### 20 | ###xxxxxxxx### 21 | ###xxxxxx### 22 | ###xxxx### 23 | ######## 24 | ######## 25 | -------------------------------------------------------------------------------- /glass-half-empty.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ###.......................### 5 | ###.......................### 6 | ###.......................### 7 | ###.......................### 8 | ###.......................### 9 | ###.......................### 10 | ###.......................### 11 | ###.......................### 12 | ### ### 13 | ### ### 14 | ### ### 15 | ### ### 16 | ### ### 17 | ### ### 18 | ### ### 19 | ### ### 20 | ### ### 21 | ############################# 22 | ############################# 23 | -------------------------------------------------------------------------------- /hint.css: -------------------------------------------------------------------------------- 1 | * { 2 | font-family: Helvetica Neue, Helvetica, Arial, sans-serif; 3 | } 4 | body { 5 | max-width: 50em; 6 | margin: 0 auto; 7 | color: #111; 8 | } 9 | 10 | pre, code { 11 | font-family: Monaco, Courier New, monospace; 12 | font-size: 12px; 13 | } 14 | 15 | h1 { 16 | font-size: 40px; 17 | font-weight: bold; 18 | letter-spacing: -1px; 19 | margin-bottom: -5px; 20 | } 21 | h1 code { 22 | font-size: 40px; 23 | } 24 | 25 | h2 { 26 | color: rgb(43,105,145); 27 | font-weight: bold; 28 | margin-bottom: -5px; 29 | } 30 | h2 code { 31 | font-size: 22px; 32 | } 33 | 34 | h3 { 35 | /* color: rgb(43,105,145); */ 36 | font-weight: bold; 37 | margin-bottom: -5px; 38 | } 39 | h3 code { 40 | font-size: 16px; 41 | } 42 | 43 | a { 44 | color: blue; 45 | text-decoration: underline; 46 | } 47 | a:visited { 48 | color: navy; 49 | } 50 | a:hover { 51 | text-decoration: underline; 52 | } 53 | 54 | pre { 55 | border-radius: 10px; 56 | -webkit-border-radius: 10px; 57 | -moz-border-radius: 10px; 58 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.3); 59 | -webkit-box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.3); 60 | -moz-box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.3); 61 | border-width: 1px; 62 | border-color: rgb(16,48,0); 63 | border-style: solid; 64 | padding: 0.6em; 65 | padding-left: 1em; 66 | margin-left: 5%; 67 | margin-right: 8%; 68 | background-color: rgb(16,48,0); 69 | overflow: auto; 70 | color: rgb(75,224,0); 71 | } 72 | 73 | p, li { 74 | font-size: 14px; 75 | line-height: 18px; 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /hint.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | Most complex ASCII fluid - Honorable mention 10 | 11 | 12 |

Most complex ASCII fluid - Honorable mention

13 | 14 |

Yusuke Endoh
15 | mame@tsg.ne.jp

16 | 17 |

Judges' comments:

18 | 19 |

To build:

20 | 21 |
make endoh1
 22 | 
23 | 24 |

To run:

25 | 26 |
./endoh1 < configuration.txt
 27 | 
28 | 29 |

Try:

30 | 31 |
./endoh1 < endoh1.c
 32 | 
 33 | ./endoh1 < pour-out.txt
 34 | 
 35 | ./endoh1 < fountain.txt
 36 | 
37 | 38 |

Selected Judges Remarks:

39 | 40 |

Let’s play Jeopardy!

41 | 42 |
    43 |
  • A: An obfuscated program that deals with complex numbers and produces animated ASCII graphics.
  • 44 |
  • Q: What is a Mandelbrot simulator?
  • 45 |
46 | 47 | 48 |

Bzzzt!

49 | 50 |

Such heavily squeezed fluid simulation (this is parsed uniquely 51 | as fluids are not squeezable) has a few quirks that the judges were 52 | happy to experiment with.

53 | 54 |

One configuration file was inspired by an XKCD what if? entry.

55 | 56 |

Author’s comments:

57 | 58 |

Synopsis

59 | 60 |

DO NOT FORGET “-DG=1 -DP=4 -DV=8” and make your terminal window larger 61 | than 80 x 25.

62 | 63 |
gcc endoh1.c -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -o endoh1 -lm
 64 | ./endoh1 < endoh1.c
 65 | ./endoh1 < logo.txt
 66 | ./endoh1 < column.txt
 67 | ./endoh1 < pour-out.txt
 68 | ./endoh1 < tanada.txt
 69 | 
70 | 71 |

What it is

72 | 73 |
,___. ,.       ,.    ,.   ,___. ,.              ,.       ,.
 74 | |/--' ||       `'    ||   |/--' `'              ||       |\_.
 75 | |\__. || ,. ,. ,. ,__/|   |\__. ,. ,____. ,. ,. ||  ,_.  |/-'  ,_.  ,__.
 76 | |/--' || || || || |/-\|   `--\| || |/\/\| || || || ,/-\. ||   ,/-\. |/-\.
 77 | ||    || `\_/| || |\_/|   ,__/| || |||||| `\_/| || `\_/\.`\_. `\_/' || `'
 78 | `'    `'  `--' `' `---'   `---' `' `'`'`'  `--' `'  `-'`' `-'  `-'  `'
 79 | 
 80 | 
 81 |  ,.,.                      ,.,.
 82 | ,/\/\. ,.       ,.    ,.  ,/\/\. ,.              ,.      ,__.
 83 | |||#/' ||       `' ,_.||  |||#/' `',_.,__.       ||      ||\\.        ,.
 84 | |||#\. || ,. ,. ,.,/#|||  |\//\. ,.|#||##| ,. ,. || ,.,. |\/-' ,.,. ,.|\.
 85 | |\/--' ||,/\.|| |||#/\/|  `\#||| |||#||/\|,/\.|| ||,/'`\.|#|  ,/'`\.|\/-\.
 86 | `\|    ||`\#||| |||#||\|  ,//\/| ||`\|||||`\#||| ||`\.,/\/\|,.`\.,/'`\| `'
 87 |  `'    `' `-'`' `'`-'`-'  `-'`-' `' `'`'`' `-'`' `' `'`--'`'`' `'`'  `'
 88 | 
 89 | 
 90 | ,_.,_. ,.       ,.    ,.  ,_.,_. ,.              ,.      ,.
 91 | |#||#| ||       `'    ||  |#||#| `'              ||      ||,_.
 92 | ||\/#| ||,.  ,. ,.,_.,/|  |\||#| ,.,_.,__.,.  ,. || ,.,. |||#| ,.,. ,.,_.
 93 | |||##| ||||  || |||#||#|  |#||#| |||#||##|||  || ||,/||\.||`-',/||\.|||#\.
 94 | ||`--' ||`\_.|| |||\||#|  |#||#| ||||'||\|`\_.|| ||`\||#|`\.,.`\||/'||`--'
 95 | `'     `' |#||| `'|#||#|  |#||#| `'`' `'`' |#||| `' |||/' |||| |||| `'
 96 |           `-'`'   `-'`-'  `-'`-'           `-'`'    `'`'  `'`' `'`'
 97 | 
98 | 99 |

This program is a fluid simulator using “Smoothed-particle hydrodynamics (SPH)” 100 | method.

101 | 102 |

http://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics

103 | 104 |

The SPH particles represent the fluid flow. Particles have information about 105 | the position, density, and velocity. In every simulation step, they are 106 | changed by pressure force, viscosity force, and external force (i.e., gravity).

107 | 108 |

This program reads a text from standard input, and uses it as an initial 109 | configuration of the particles. The character # represents “wall particle” (a 110 | particle with fixed position), and any other non-space characters represent 111 | free particles.

112 | 113 |

The compilation options -DG=1 -DP=4 -DV=8 represent, respectively, the factor 114 | of gravity, pressure, and viscosity. By changing their values, you can see 115 | different fluid behavior.

116 | 117 |

“Marching square”-like algorithm is used to render the particles.

118 | 119 |

http://en.wikipedia.org/wiki/Marching_squares

120 | 121 |

Portability

122 | 123 |

The program requires a C99 compiler; it uses complex types and one-line 124 | comments. It also uses usleep, which may require -D_BSD_SOURCE or somewhat 125 | to build with no warning. Under these conditions, it should be portable. 126 | At least, recent compilers with -std=c99 -Wall -W -Wextra -pedantic says 127 | nothing.

128 | 129 |
gcc -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c
130 | clang -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c
131 | 
132 | 133 |

I expect it to work in any Unix-like environment. VTxxx/ANSI sequences are 134 | used to clear screen and move cursor to home.

135 | 136 |

I’ve tested with gcc-4.6.3 and clang-3.0 on Linux (Ubuntu 12.04) 137 | and gcc-4.5.3 and clang-3.1 on Cygwin. On Cygwin, gcc and clang complain about 138 | a usage of I (complex’s imaginary unit), but I bet this is cygwin’s issue; 139 | it is surely a C99 feature.

140 | 141 |

Obfuscation w/ Spoiler

142 | 143 |

First of all, the source code itself serves as an initial configuration. 144 | Preprocessing directives (such as #include)’s # serve as walls.

145 | 146 |

This program uses double complex to represent any 2D vector. But, note that 147 | x-axis and y-axis is swapped (real axis = y-axis, imaginary axis = x-axis). 148 | The purpose of swapping is not only obfuscation, but also short coding: for 149 | example, to add gravity to total force, force += G suffices, rather than 150 | force += G*I. 151 | (Incidentally, you can exert horizontal gravity by using, such as, -DG=I)

152 | 153 |

Every five entries of double complex a[] contain information of one particle: 154 | position, wall-flag, density, force, and velocity, in turn.

155 | 156 |

You can use G, P, and V as a guide to find the calculation code of 157 | gravity, pressure, and viscosity forces.

158 | 159 |

Though some assignments may look meaningless, it is actually meaningful; it 160 | extracts “integer part of real part” from a complex value by assigning (and 161 | casting) it to an integer-type variable.

162 | 163 |

Notes about Additional Files

164 | 165 |

“logo.txt” is a source of the logo in this remark file.

166 | 167 |

“column.txt” is a water column collapse, which is a popular demo of SPH.

168 | 169 |

“pour-out.txt” pours you a cup of tea.

170 | 171 |

“tanada.txt” simulates “Terrace farming”. (“Tanada” means a “terraced rice 172 | fields” in Japanese.)

173 | 174 |

“clock.txt” is a “water” clock created by HAMANO Tsukasa.

175 | 176 |

Other *.txt files are due to the judges.

177 | 178 |

“endoh1_color.c” is a variant that shows the density by using terminal 256 179 | colors.

180 | 181 |

Acknowledgment

182 | 183 |

I would like to thank my wife @hirekoke for her teaching me the SPH method.

184 | 185 |

The judges ordered suggested creating a color version 186 | after the judgment.

187 | 188 |

The judges and HAMANO Tsukasa (The silver medalist at this IOCCC) kindly 189 | provided many configuration files.

190 | 191 |
192 | 193 | 200 | 201 | 202 | 203 | 207 | 208 |
Creative Commons License

© Copyright 1984-2012, 204 | Leo Broukhis, Simon Cooper, Landon Curt Noll 205 | - All rights reserved
206 | This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

 
209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /leidenfrost.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | # # 20 | # # 21 | # # 22 | # @ # 23 | ############################################################################### 24 | -------------------------------------------------------------------------------- /logo.txt: -------------------------------------------------------------------------------- 1 | 2 | @@@@ @ @ @ @@@@ @ @ @ 3 | @ @ @ @ @ @@@ 4 | @@@@ @ @ @ @ @@@@ @@@@ @ @@@@@ @ @ @ @@ @ @@ @@@ 5 | @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 6 | @ @ @@@ @ @@@@ @@@@ @ @ @ @ @@@ @ @@ @ @@ @@ @ 7 | 8 | 9 | 10 | 11 | 12 | # # 13 | ##### ##### 14 | ###### ###### 15 | ####### ####### 16 | ######## ######## 17 | ######### ######### 18 | ########## ########## 19 | ## ## 20 | -------------------------------------------------------------------------------- /pour-out.txt: -------------------------------------------------------------------------------- 1 | 2 | ### . . . . . . . . . . . ### 3 | ###.......................### 4 | ### . . . . . . . . . . . ### 5 | ###.......................### 6 | ### . . . . . . . . . . . ### 7 | ###.......................### 8 | ### . . . . . . . . . . . ### 9 | ###.......................### 10 | ### . . . . . . . . . . . ### 11 | ###.......................### 12 | ### . . . . . . . . . . . ### 13 | ###.......................## 14 | ### . . . . . . . . . . . ## 15 | ###....................... ### 16 | ################################# ## ## 17 | ############################### ## ## 18 | ## ## 19 | ########### 20 | -------------------------------------------------------------------------------- /tanada.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## 4 | ##. . . . . . . . 5 | ##.................. 6 | ##. . . . . . . . . . .. 7 | ##....................... 8 | ##. . . . . . . . . . . .. 9 | ##........................## 10 | ##. . . . . . . . . . . ..## 11 | ############################ ## 12 | ## ## 13 | ############ ## 14 | ## ## 15 | ############ ## 16 | ## ## 17 | ############ ## 18 | ## ## 19 | ############ 20 | --------------------------------------------------------------------------------