You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
8.5 KiB
HTML

11 years ago
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="hint.css">
<title>Most complex ASCII fluid - Honorable mention</title>
</head>
<body>
<h1>Most complex ASCII fluid - Honorable mention</h1>
<p>Yusuke Endoh<br>
<a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x6d;&#x61;&#x6d;&#101;&#64;&#116;&#115;&#x67;&#x2e;&#x6e;&#101;&#46;&#x6a;&#112;">&#109;&#97;&#x6d;&#101;&#64;&#116;&#x73;&#x67;&#46;&#110;&#101;&#46;&#x6a;&#112;</a></p>
<h2>Judges' comments:</h2>
<h3>To build:</h3>
<pre><code>make endoh1
</code></pre>
<h3>To run:</h3>
<pre><code>./endoh1 &lt; configuration.txt
</code></pre>
<h3>Try:</h3>
<pre><code>./endoh1 &lt; endoh1.c
./endoh1 &lt; pour-out.txt
./endoh1 &lt; fountain.txt
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Let&rsquo;s play Jeopardy!</p>
<ul>
<li>A: An obfuscated program that deals with complex numbers and produces animated ASCII graphics.</li>
<li>Q: What is a Mandelbrot simulator?</li>
</ul>
<p>Bzzzt!</p>
<p>Such heavily squeezed fluid simulation (this is parsed uniquely
as fluids are not squeezable) has a few quirks that the judges were
happy to experiment with.</p>
<p>One configuration file was inspired by an <a href="http://whatif.xkcd.com/6/">XKCD what if? entry</a>.</p>
<h2>Author&rsquo;s comments:</h2>
<h3>Synopsis</h3>
<p><strong>DO NOT FORGET &ldquo;-DG=1 -DP=4 -DV=8&rdquo;</strong> and make your terminal window larger
than 80 x 25.</p>
<pre><code>gcc endoh1.c -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -o endoh1 -lm
./endoh1 &lt; endoh1.c
./endoh1 &lt; logo.txt
./endoh1 &lt; column.txt
./endoh1 &lt; pour-out.txt
./endoh1 &lt; tanada.txt
</code></pre>
<h3>What it is</h3>
<pre><code>,___. ,. ,. ,. ,___. ,. ,. ,.
|/--' || `' || |/--' `' || |\_.
|\__. || ,. ,. ,. ,__/| |\__. ,. ,____. ,. ,. || ,_. |/-' ,_. ,__.
|/--' || || || || |/-\| `--\| || |/\/\| || || || ,/-\. || ,/-\. |/-\.
|| || `\_/| || |\_/| ,__/| || |||||| `\_/| || `\_/\.`\_. `\_/' || `'
`' `' `--' `' `---' `---' `' `'`'`' `--' `' `-'`' `-' `-' `'
,.,. ,.,.
,/\/\. ,. ,. ,. ,/\/\. ,. ,. ,__.
|||#/' || `' ,_.|| |||#/' `',_.,__. || ||\\. ,.
|||#\. || ,. ,. ,.,/#||| |\//\. ,.|#||##| ,. ,. || ,.,. |\/-' ,.,. ,.|\.
|\/--' ||,/\.|| |||#/\/| `\#||| |||#||/\|,/\.|| ||,/'`\.|#| ,/'`\.|\/-\.
`\| ||`\#||| |||#||\| ,//\/| ||`\|||||`\#||| ||`\.,/\/\|,.`\.,/'`\| `'
`' `' `-'`' `'`-'`-' `-'`-' `' `'`'`' `-'`' `' `'`--'`'`' `'`' `'
,_.,_. ,. ,. ,. ,_.,_. ,. ,. ,.
|#||#| || `' || |#||#| `' || ||,_.
||\/#| ||,. ,. ,.,_.,/| |\||#| ,.,_.,__.,. ,. || ,.,. |||#| ,.,. ,.,_.
|||##| |||| || |||#||#| |#||#| |||#||##||| || ||,/||\.||`-',/||\.|||#\.
||`--' ||`\_.|| |||\||#| |#||#| ||||'||\|`\_.|| ||`\||#|`\.,.`\||/'||`--'
`' `' |#||| `'|#||#| |#||#| `'`' `'`' |#||| `' |||/' |||| |||| `'
`-'`' `-'`-' `-'`-' `-'`' `'`' `'`' `'`'
</code></pre>
<p>This program is a fluid simulator using &ldquo;Smoothed-particle hydrodynamics (SPH)&rdquo;
method.</p>
<p><a href="http://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics">http://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics</a></p>
<p>The SPH particles represent the fluid flow. Particles have information about
the position, density, and velocity. In every simulation step, they are
changed by pressure force, viscosity force, and external force (i.e., gravity).</p>
<p>This program reads a text from standard input, and uses it as an initial
configuration of the particles. The character <code>#</code> represents &ldquo;wall particle&rdquo; (a
particle with fixed position), and any other non-space characters represent
free particles.</p>
<p>The compilation options <code>-DG=1 -DP=4 -DV=8</code> represent, respectively, the factor
of gravity, pressure, and viscosity. By changing their values, you can see
different fluid behavior.</p>
<p>&ldquo;Marching square&rdquo;-like algorithm is used to render the particles.</p>
<p><a href="http://en.wikipedia.org/wiki/Marching_squares">http://en.wikipedia.org/wiki/Marching_squares</a></p>
<h3>Portability</h3>
<p>The program requires a C99 compiler; it uses <code>complex</code> types and one-line
comments. It also uses <code>usleep</code>, which may require <code>-D_BSD_SOURCE</code> or somewhat
to build with no warning. Under these conditions, it should be portable.
At least, recent compilers with <code>-std=c99 -Wall -W -Wextra -pedantic</code> says
nothing.</p>
<pre><code>gcc -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c
clang -DG=1 -DP=4 -DV=8 -D_BSD_SOURCE -std=c99 -Wall -W -Wextra -pedantic endoh1.c
</code></pre>
<p>I expect it to work in any Unix-like environment. VTxxx/ANSI sequences are
used to clear screen and move cursor to home.</p>
<p>I&rsquo;ve tested with gcc-4.6.3 and clang-3.0 on Linux (Ubuntu 12.04)
and gcc-4.5.3 and clang-3.1 on Cygwin. On Cygwin, gcc and clang complain about
a usage of <code>I</code> (complex&rsquo;s imaginary unit), but I bet this is cygwin&rsquo;s issue;
it is surely a C99 feature.</p>
<h3>Obfuscation w/ Spoiler</h3>
<p>First of all, the source code itself serves as an initial configuration.
Preprocessing directives (such as <code>#include</code>)&rsquo;s <code>#</code> serve as walls.</p>
<p>This program uses <code>double complex</code> to represent any 2D vector. But, note that
x-axis and y-axis is swapped (real axis = y-axis, imaginary axis = x-axis).
The purpose of swapping is not only obfuscation, but also short coding: for
example, to add gravity to total force, <code>force += G</code> suffices, rather than
<code>force += G*I</code>.
(Incidentally, you can exert horizontal gravity by using, such as, <code>-DG=I</code>)</p>
<p>Every five entries of <code>double complex a[]</code> contain information of one particle:
position, wall-flag, density, force, and velocity, in turn.</p>
<p>You can use <code>G</code>, <code>P</code>, and <code>V</code> as a guide to find the calculation code of
gravity, pressure, and viscosity forces.</p>
<p>Though some assignments may look meaningless, it is actually meaningful; it
extracts &ldquo;integer part of real part&rdquo; from a complex value by assigning (and
casting) it to an integer-type variable.</p>
<h3>Notes about Additional Files</h3>
<p>&ldquo;logo.txt&rdquo; is a source of the logo in this remark file.</p>
<p>&ldquo;column.txt&rdquo; is a water column collapse, which is a popular demo of SPH.</p>
<p>&ldquo;pour-out.txt&rdquo; pours you a cup of tea.</p>
<p>&ldquo;tanada.txt&rdquo; simulates &ldquo;Terrace farming&rdquo;. (&ldquo;Tanada&rdquo; means a &ldquo;terraced rice
fields&rdquo; in Japanese.)</p>
<p>&ldquo;clock.txt&rdquo; is a &ldquo;water&rdquo; clock created by HAMANO Tsukasa.</p>
<p>Other *.txt files are due to the judges.</p>
<p>&ldquo;endoh1_color.c&rdquo; is a variant that shows the density by using terminal 256
colors.</p>
<h3>Acknowledgment</h3>
<p>I would like to thank my wife @hirekoke for her teaching me the SPH method.</p>
<p>The judges <strike>ordered</strike> suggested creating a color version
after the judgment.</p>
<p>The judges and HAMANO Tsukasa (The silver medalist at this IOCCC) kindly
provided many configuration files.</p>
<hr />
<!--
(c) Copyright 1984-2012, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
[judges]: http://www.ioccc.org/judges.html
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
-->
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2012,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>