Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Last active December 13, 2015 22:29
Show Gist options
  • Save lokedhs/4984763 to your computer and use it in GitHub Desktop.
Save lokedhs/4984763 to your computer and use it in GitHub Desktop.
A version of mandelbrot.sh originally written by Benjamin Staffin here: https://gist.github.com/benley/4984040 This version is plain "sh" without any bash-specific code. You have to be extremely patient to actually run it.
#!/bin/sh
#
# Mandelbrot in plain sh without any bash-specific features
#
# Original version by Benjamin Staffin:
# https://gist.github.com/benley/4984040
#
L=99
P=100000000
Q=`expr $P / 100`
X=`expr $Q \* 320 / \( \`tput cols\` - 1 \)`
Y=`expr $Q \* 210 / \`tput lines\``
y=`expr $Q \* -105`
v=`expr $Q \* -220`
x=$v
while [ $y -lt `expr 105 \* $Q` ] ; do
while [ $x -lt $P ] ; do
a=0
b=0
i=0
c=0
while [ \( `expr $a \* $a + $b \* $b` -lt `expr 4 \* $P \* $P` \) -a \( $i -lt $L \) ] ; do
i=`expr $i + 1`
c=$a
a=`expr \( $a \* $a - $b \* $b \) / $P + $x`
b=`expr 2 \* $b \* $c / $P + $y`
done
i=`expr $i + 1`
if [ $i -ge $L ] ; then
j=0
else
j=`expr $i % 16`
fi
if [ $j -gt 7 ] ; then
tput smso
else
tput rmso
fi
tput setaf `expr $i % 8`
x=`expr $x + $X`
echo -n "#"
done
tput sgr0
x=$v
y=`expr $y + $Y`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment