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
212 lines
8.5 KiB
HTML
<!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="mailto:mame@tsg.ne.jp">mame@tsg.ne.jp</a></p>
|
|
|
|
<h2>Judges' comments:</h2>
|
|
|
|
<h3>To build:</h3>
|
|
|
|
<pre><code>make endoh1
|
|
</code></pre>
|
|
|
|
<h3>To run:</h3>
|
|
|
|
<pre><code>./endoh1 < configuration.txt
|
|
</code></pre>
|
|
|
|
<h3>Try:</h3>
|
|
|
|
<pre><code>./endoh1 < endoh1.c
|
|
|
|
./endoh1 < pour-out.txt
|
|
|
|
./endoh1 < fountain.txt
|
|
</code></pre>
|
|
|
|
<h3>Selected Judges Remarks:</h3>
|
|
|
|
<p>Let’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’s comments:</h2>
|
|
|
|
<h3>Synopsis</h3>
|
|
|
|
<p><strong>DO NOT FORGET “-DG=1 -DP=4 -DV=8”</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 < endoh1.c
|
|
./endoh1 < logo.txt
|
|
./endoh1 < column.txt
|
|
./endoh1 < pour-out.txt
|
|
./endoh1 < tanada.txt
|
|
</code></pre>
|
|
|
|
<h3>What it is</h3>
|
|
|
|
<pre><code>,___. ,. ,. ,. ,___. ,. ,. ,.
|
|
|/--' || `' || |/--' `' || |\_.
|
|
|\__. || ,. ,. ,. ,__/| |\__. ,. ,____. ,. ,. || ,_. |/-' ,_. ,__.
|
|
|/--' || || || || |/-\| `--\| || |/\/\| || || || ,/-\. || ,/-\. |/-\.
|
|
|| || `\_/| || |\_/| ,__/| || |||||| `\_/| || `\_/\.`\_. `\_/' || `'
|
|
`' `' `--' `' `---' `---' `' `'`'`' `--' `' `-'`' `-' `-' `'
|
|
|
|
|
|
,.,. ,.,.
|
|
,/\/\. ,. ,. ,. ,/\/\. ,. ,. ,__.
|
|
|||#/' || `' ,_.|| |||#/' `',_.,__. || ||\\. ,.
|
|
|||#\. || ,. ,. ,.,/#||| |\//\. ,.|#||##| ,. ,. || ,.,. |\/-' ,.,. ,.|\.
|
|
|\/--' ||,/\.|| |||#/\/| `\#||| |||#||/\|,/\.|| ||,/'`\.|#| ,/'`\.|\/-\.
|
|
`\| ||`\#||| |||#||\| ,//\/| ||`\|||||`\#||| ||`\.,/\/\|,.`\.,/'`\| `'
|
|
`' `' `-'`' `'`-'`-' `-'`-' `' `'`'`' `-'`' `' `'`--'`'`' `'`' `'
|
|
|
|
|
|
,_.,_. ,. ,. ,. ,_.,_. ,. ,. ,.
|
|
|#||#| || `' || |#||#| `' || ||,_.
|
|
||\/#| ||,. ,. ,.,_.,/| |\||#| ,.,_.,__.,. ,. || ,.,. |||#| ,.,. ,.,_.
|
|
|||##| |||| || |||#||#| |#||#| |||#||##||| || ||,/||\.||`-',/||\.|||#\.
|
|
||`--' ||`\_.|| |||\||#| |#||#| ||||'||\|`\_.|| ||`\||#|`\.,.`\||/'||`--'
|
|
`' `' |#||| `'|#||#| |#||#| `'`' `'`' |#||| `' |||/' |||| |||| `'
|
|
`-'`' `-'`-' `-'`-' `-'`' `'`' `'`' `'`'
|
|
</code></pre>
|
|
|
|
<p>This program is a fluid simulator using “Smoothed-particle hydrodynamics (SPH)”
|
|
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 “wall particle” (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>“Marching square”-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’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’s imaginary unit), but I bet this is cygwin’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>)’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 “integer part of real part” from a complex value by assigning (and
|
|
casting) it to an integer-type variable.</p>
|
|
|
|
<h3>Notes about Additional Files</h3>
|
|
|
|
<p>“logo.txt” is a source of the logo in this remark file.</p>
|
|
|
|
<p>“column.txt” is a water column collapse, which is a popular demo of SPH.</p>
|
|
|
|
<p>“pour-out.txt” pours you a cup of tea.</p>
|
|
|
|
<p>“tanada.txt” simulates “Terrace farming”. (“Tanada” means a “terraced rice
|
|
fields” in Japanese.)</p>
|
|
|
|
<p>“clock.txt” is a “water” clock created by HAMANO Tsukasa.</p>
|
|
|
|
<p>Other *.txt files are due to the judges.</p>
|
|
|
|
<p>“endoh1_color.c” 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>© 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> <!--<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>
|
|
|