Browse Source

first commit of the snakelogan cursive banner writer

master
crunk 9 months ago
commit
db5df67d9e
3 changed files with 128 additions and 0 deletions
  1. +4
    -0
      collection
  2. +123
    -0
      snakelogan
  3. +1
    -0
      thesnake

+ 4
- 0
collection View File

@ -0,0 +1,4 @@
//#!/bin/zsh
iconv -f cp437 -t utf-8 < input.ans > output.txt ;
sed -e "s/.\{80\}/&\n\r/" < input.txt > output.txt

+ 123
- 0
snakelogan View File

@ -0,0 +1,123 @@
#!/bin/zsh
_STTY=$(stty -g) # Save current terminal setup
#printf "\e[2J" # clear screen, set cursos at beginning
stty -echo -icanon # Turn off line buffering
# VARIABLES
typeset -A IMAGE
X=0
Y=24
snake='═'
vertical=false
forward=true
upward=true
function start_the_snake() {
rm thesnake
for i in {0..29}
do
for j in {0..79}
do
IMAGE["${i};${j}"]=' ' ; printf ${IMAGE["${i};${j}"]}
done
done
}
function save_the_snake() {
for i in {0..29}
do
for j in {0..79}
do
printf ${IMAGE["${i};${j}"]}
done
done >> thesnake
}
function show_the_snake() {
clear
for i in {0..29}
do
for j in {0..79}
do
printf ${IMAGE["${i};${j}"]}
done
done
}
function at_exit() {
printf "\e[?9l" # Turn off mouse reading
printf "\e[?12l\e[?25h" # Turn on cursor
stty "$_STTY" # reinitialize terminal settings
clear
exit
}
#═ ║╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟
#╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬
function move_snake_up() {
if [ "$vertical" = false ] ; then
if [ "$forward" = true ] ; then
snake='╝'
else
snake='╚'
fi
IMAGE["${Y};${X}"]=$snake ; Y=$((Y-1)) ; vertical=true ; upward=true
else
snake='║' ; IMAGE["${Y};${X}"]=$snake ; Y=$((Y-1))
fi
}
function move_snake_down() {
if [ "$vertical" = false ] ; then
if [ "$forward" = true ] ; then
snake='╗'
else
snake='╔'
fi
IMAGE["${Y};${X}"]=$snake ; Y=$((Y+1)) ; vertical=true ; upward=false
else
snake='║' ; IMAGE["${Y};${X}"]=$snake ; Y=$((Y+1))
fi
}
function move_snake_forward() {
if [ "$vertical" = true ] ; then
if [ "$upward" = true ] ; then
snake='╔'
else
snake='╚'
fi
IMAGE["${Y};${X}"]=$snake ; X=$((X+1)) ; vertical=false ; forward=true
else
snake='═' ; IMAGE["${Y};${X}"]=$snake ; X=$((X+1))
fi
}
function move_snake_backward() {
if [ "$vertical" = true ] ; then
if [ "$upward" = true ] ; then
snake='╗'
else
snake='╝'
fi
IMAGE["${Y};${X}"]=$snake ; X=$((X-1)) ; vertical=false ; forward=false
else
snake='═' ; IMAGE["${Y};${X}"]=$snake ; X=$((X-1))
fi
}
# Main #
start_the_snake
while read -s -k 1 cr;
do
case "$cr" in
w) move_snake_up ; show_the_snake ;;
s) move_snake_down ; show_the_snake ;;
a) move_snake_backward ; show_the_snake ;;
d) move_snake_forward ; show_the_snake ;;
q) save_the_snake && at_exit ;;
esac
done

+ 1
- 0
thesnake View File

@ -0,0 +1 @@
════

Loading…
Cancel
Save