Paint16b: A 16 byte paint program written in 12 lines
<i>SHPaint</i> -- ANSI Art editor programmed in bash, written in 179 lines.[0,1]<p><pre><code>  #!&#x2F;bin&#x2F;bash
  #
  #  Author: Martin &quot;BruXy&quot; Bruchanov, bruxy at regnet.cz
  #
  
  # Check input first
  if [ ! $# -eq 1 ] || [ &quot;$1&quot; == &quot;-h&quot;] || [ &quot;$1&quot; == &quot;--help&quot; ] ; then
  	printf &quot;Usage:\n&quot;	
  	printf &quot;\t$0 saved_image\n&quot;
  	printf &quot;\n\tImage data will be saved into given filename, if file exist\n&quot;
  	printf &quot;\tit will be displayed and ready to edit!\n&quot;
      printf &quot;\tHit &lt;Ctrl-C&gt; any time to quit the program.\n&quot;
  	exit 1
  fi
  
  ##################
  # Initialization #
  ##################
  
  IMAGE_FILE=$1
  _STTY=$(stty -g)    # Save current terminal setup
  printf   &quot;\e[2J&quot;    # clear screen, set cursos at beginning
  stty -echo -icanon  # Turn off line buffering
  printf &quot;\e[?9h&quot;     # Enable terminal mouse reading
  printf &quot;\e[?25l&quot;    # Turn of cursor 
  printf &quot;\e]0;-=[ ShPaint ]=-\007&quot;
  
  # Hash array with image data,
  # ... key is &quot;$Y;$X&quot;,
  # ... value ANSI colors and brush &quot;b;F;Bm&quot;
  declare -A IMAGE  
  
  # Defaults
  BRUSHES=(       )
  FG=( {30..37} )
  BG=( {40..47} ) # 49 ... default background
  X=0 
  Y=0
  ERASE=0
  BRUSH=${BRUSHES[3]}
  FG_COLOR=&quot;1;${FG[7]}&quot;
  BG_COLOR=49
  
  #############
  # Functions #
  #############
  
  function save_image() {
  	printf &quot;\e[2J&quot; &gt; $IMAGE_FILE
  	for i in ${!IMAGE[@]}
  	do
  		printf &quot;\e[${i}f\e[${IMAGE[$i]}\e[0m&quot;
  	done &gt;&gt; $IMAGE_FILE
  	# set cursor under the image
  	printf &quot;\e[$(tput lines);1f&quot; &gt;&gt; $IMAGE_FILE
  }
  
  function at_exit() {
  	printf &quot;\e[?9l&quot;          # Turn off mouse reading
  	printf &quot;\e[?12l\e[?25h&quot;  # Turn on cursor
  	stty &quot;$_STTY&quot;            # reinitialize terminal settings
  	clear
  	echo &quot;Thank for using ansipaint!&quot;
  	if [ ! -z &quot;$IMAGE_FILE&quot; ] ; then 
  		echo &quot;Your image is saved as &#x27;$IMAGE_FILE&#x27;.&quot;
  		save_image
  	fi
  	exit
  }
  
  # X = $1, Y = $2
  function set_pos() {
   	echo -en  &quot;\e[$2;$1f&quot;
  }
  
  function show_pos() {
  	set_pos 65 1
  	printf &quot;x,y = =,=&quot; $X $Y
  }
  
  function show_brush() {
  	set_pos 70 2 
  	printf &quot;[ \e[${FG_COLOR};${BG_COLOR}m$BRUSH\e[0m ]&quot;
  }
  
  function process_click() {
  #	X=$1 Y=$2
  	# set foreground color
  	if [ $Y -eq 1 ] || [ $Y -eq 2 ] ; then
  		if [ $X -gt 2 ] &amp;&amp; [ $X -lt 28 ] ; then
  			FG_COLOR=&quot;$[Y-1];${FG[$[(X-4)&#x2F;3]]}&quot;
  			ERASE=0
  		fi
  	fi
  	
  	# set background color
  	if [ $Y -eq 1 ] &amp;&amp; [ $X -gt 34 ] ; then
  		if [ $X -gt 34 ] &amp;&amp; [ $X -lt 59 ] ; then
  			BG_COLOR=&quot;${BG[$[X-35]&#x2F;3]}&quot;
  			ERASE=0
  		else
  			BG_COLOR=&quot;49&quot;
  			ERASE=0
  		fi
  	fi	
  
  	# set brush
  	if [ $Y -eq 2 ] &amp;&amp; [ $X -gt 36 ] &amp;&amp; [ $X -le 51 ] ; then
  		BRUSH=${BRUSHES[$[(X-37)&#x2F;2]]}
  		ERASE=0
  	fi
  
  	# set erase
  	if [ $Y -eq 2 ] &amp;&amp; [ $X -ge 54 ] &amp;&amp; [ $X -le 62 ] ; then
  		BRUSH=&quot; &quot;
  		BG_COLOR=&quot;49&quot;
  		ERASE=1
  	fi
  
  	# DEBUG
  	# set_pos 0 25
  	# printf &quot;$FG_COLOR $BG_COLOR $BRUSH&quot;
  }
  
  function draw_menu() {
  	set_pos 1 1; echo &quot;FG: &quot;
  	for i in ${FG[*]}
  	do
  		set_pos $[(i-30)*3+4] 1
  		echo -en &quot;\e[${i}m\e[0m&quot;	
  		set_pos $[(i-30)*3+4] 2
  		echo -en &quot;\e[1;${i}m\e[0m&quot;	
  	done
  
  	set_pos 30 1; echo &quot;BG: &quot;
  	for i in ${BG[*]}
  	do 
  		set_pos $[(i-40)*3+35] 1
  		echo -en &quot;\e[${i}m   \e[0m&quot;	
  	done
  	echo &quot;   |&quot; # default background (49)
  
  	set_pos 30 2; echo -en &quot;Brush: ${BRUSHES[*]}&quot;
  	printf &quot;  [ Erase ]&quot;
  	show_brush
  }
  
  function load_image() {
  	if [ -f $IMAGE_FILE ] ; then 
  		data=$(sed -e &#x27;s&#x2F;\x1b&#x2F;E&#x2F;g;s&#x2F;E\[0m&#x2F;\n&#x2F;g;s&#x2F;E\[2J&#x2F;&#x2F;&#x27; $IMAGE_FILE | \
  			sed -n -e &#x27;s&#x2F;E\[\(.*\)fE\[\(.*m.\)&#x2F;IMAGE[&quot;\1&quot;]=&quot;\2&quot;&#x2F; p&#x27;)
  		eval $data
  		cat &lt; $IMAGE_FILE
  	fi
  }
  
  ##########
  #  MAIN  #
  ##########
  trap at_exit ERR EXIT 
  load_image
  draw_menu
  while :
  do 
  	read -N 6 click
  	mouse=( `echo -en ${click#???} | hexdump -v  -e&#x27;1&#x2F;1 &quot; %u&quot;&#x27;` )
  	X=$[ ${mouse[0]} - 32]	Y=$[ ${mouse[1]} - 32]
  	process_click
  	show_pos 
  	show_brush
  	if [ $Y -gt 2 ] ; then	
  		echo -en  &quot;\e[${Y};${X}f\e[${FG_COLOR};${BG_COLOR}m$BRUSH\e[0m&quot;
  		if [ $ERASE -eq 0 ] ; then
  			IMAGE[&quot;${Y};${X}&quot;]=&quot;${FG_COLOR};${BG_COLOR}m$BRUSH&quot;
  		else
  			unset IMAGE[&quot;${Y};${X}&quot;]
  		fi
  	fi
  done
  
</code></pre>
[0] <a href="http:&#x2F;&#x2F;bruxy.regnet.cz&#x2F;web&#x2F;linux&#x2F;EN&#x2F;ansi-art-sh-paint" rel="nofollow">http:&#x2F;&#x2F;bruxy.regnet.cz&#x2F;web&#x2F;linux&#x2F;EN&#x2F;ansi-art-sh-paint</a><p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=aoAMxMukgPY" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=aoAMxMukgPY</a>