Commit b3bef593 authored by John A's avatar John A

Merge branch 'noshift'

parents 6d354f36 4e0430db
......@@ -21,7 +21,7 @@ infinite=0
termSize=1
termColors=0
leafChars='&'
leafStrs='&'
baseType=1
message=""
......@@ -90,7 +90,7 @@ while true; do
;;
-c|--leaf)
leafChars="$2"
leafStrs="$2"
shift 2
;;
......@@ -248,7 +248,7 @@ R='\e[0m'
# create ascii base in lines
case "$baseType" in
1)
width=15
width=14
art="\
${Gray}:${Green}___________${DarkBrown}./~~\\.${Green}___________${Gray}:
\\ /
......@@ -273,17 +273,26 @@ for line in $art; do
baseHeight=$(( baseHeight + 1 ))
done
# create leafchars list
for char in $(printf '%s' "$leafChars" | tr , '\n'); do
charList+=("$char")
# create leafArray
declare -A leafArray
leafArrayLen=0
# parse each string in comma-separated $leafStrs
for str in $(printf '%s' "$leafStrs" | tr , '\n'); do
leafArray[$leafArrayLen,0]=${#str} # first item in sub-array is length
# for character in string, add to the sub-array
for (( i=0; i < ${#str}; i++ )); do
leafArray[$leafArrayLen,$((i+1))]="${str:$i:1}"
done
leafArrayLen=$((leafArrayLen+1))
done
charListLen="${#charList[@]}"
setGeometry() {
if ((nfetch)) && ((termSize)); then
geometry="$(tput cols),$(tput lines)" # geometry must use tput in this mode
elif ((termSize)); then
geometry="$((COLUMNS - 1)),$LINES" # these vars automatically update
geometry="$COLUMNS,$LINES" # these vars automatically update
fi
cols="$(printf '%s' "$geometry" | cut -d ',' -f1)" # width; X
rows="$(printf '%s' "$geometry" | cut -d ',' -f2)" # height; Y
......@@ -321,7 +330,7 @@ init() {
iter=1
for line in $art; do
filler=""
for (( i=0; i < (cols / 2 - width); i++)); do
for (( i=0; i <= (cols / 2 - width); i++)); do
filler+=" "
done
base+="${filler}${line}"
......@@ -367,6 +376,7 @@ branch() {
local life=$4
local dx=0
local dy=0
local chars=()
branches=$((branches + 1))
......@@ -477,7 +487,7 @@ branch() {
fi
fi
else # we're past max branches but want to branch
char='<->'
chars=('<->')
fi
# implement dx,dy
......@@ -500,48 +510,60 @@ branch() {
case $type in
trunk)
if [ $dx -lt 0 ]; then
char='\\'
chars=('\\')
elif [ $dx -eq 0 ]; then
char='/|'
chars=('/' '|')
elif [ $dx -gt 0 ]; then
char='/'
chars=('/')
fi
[ $dy -eq 0 ] && char='/~' # not growing
#[ $dy -lt 0 ] && char='/~' # growing
[ $dy -eq 0 ] && chars=('/' '~') # not growing
#[ $dy -lt 0 ] && chars=('/' '~') # growing
;;
# shoots tend to look horizontal
shootLeft)
case $dx in
[-3,-1]) char='\\|' ;;
[0]) char='/|' ;;
[1,3]) char='/' ;;
[-3,-1]) chars=('\\' '|') ;;
[0]) chars=('/' '|') ;;
[1,3]) chars=('/') ;;
esac
#[ $dy -lt 0 ] && char='/~' # growing up
[ $dy -gt 0 ] && char='/' # growing down
[ $dy -eq 0 ] && char='\\_' # not growing
#[ $dy -lt 0 ] && chars=('/' '~') # growing up
[ $dy -gt 0 ] && chars=('/') # growing down
[ $dy -eq 0 ] && chars=('\\' '_') # not growing
;;
shootRight)
case $dx in
[-3,-1]) char='\\|' ;;
[0]) char='/|' ;;
[1,3]) char='/' ;;
[-3,-1]) chars=('\\' '|') ;;
[0]) chars=('/' '|') ;;
[1,3]) chars=('/') ;;
esac
#[ $dy -lt 0 ] && char='' # growing up
[ $dy -gt 0 ] && char='\\' # growing down
[ $dy -eq 0 ] && char='_/' # not growing
#[ $dy -lt 0 ] && chars=('') # growing up
[ $dy -gt 0 ] && chars=('\\') # growing down
[ $dy -eq 0 ] && chars=('_' '/') # not growing
;;
esac
# randomly choose leaf character from list
# randomly choose leaf character
if [ $life -lt 4 ]; then
char="${charList[ $((RANDOM % charListLen)) ]}"
chars=()
randIndex=$((RANDOM % leafArrayLen))
# add each char in our randomly chosen list to our chars
for (( i=0; i < ${leafArray[$randIndex,0]}; i++)); do
chars+=("${leafArray[$randIndex,$((i+1))]}")
done
fi
# [ $life -eq 0 ] && chars=('&' '&') # eh, maybe
((verbose)) && printf '%b\n' "$life:\t$x, $y: $char"
grid[$y,$x]="${color}${char}" # put character in grid
# add this/these character(s) to our grid
index=0
for char in "${chars[@]}"; do
grid[$y,$((x+index))]="${color}${char}"
index=$((index+1))
done
# add this line to our list of "edited lines"
found=0
......@@ -563,15 +585,23 @@ display() {
output=""
for (( row=0; row < rows; row++)); do
line=""
line=()
# ensure this line actually has characters in it before parsing it
for item in "${changed[@]}"; do
if [ "$row" = "$item" ]; then
for (( col=0; col < cols; col++ )); do
((live)) && printf '%b' '\e[0;0H ' # this prints a space at 0,0 and is necessary
line+="${grid[$row,$col]}" # grab the character from our grid
# grab the character from our grid
char="${grid[$row,$col]}"
#[ $col -gt 0 ] && plc="${line[ $((col-1)) ]}"
# if there were more than 2 characters last time, cut the last one down
#if [ "${#char}" -gt 1 ] && [ "${#plc}" -gt 10 ]; then
#line[ $((col-1)) ] = "${plc/\e.*/}"
# line="${line/*\\e/\\e}"
#fi
line["$col"]="$char"
done
fi
done
......@@ -584,7 +614,8 @@ display() {
# add our message unless line is blank
((flag_m)) && [ ! "$line" = "" ] && line+=' \t'"${R}${gridMessage[$row]}"
output+="$line"'\n'
IFS=''
output+="${line[*]}"'\n'
done
output+="$base" # add the ascii-art base we generated earlier
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment