#!/bin/bash ### # ASCII fire # TODO: # Better gradient for cooling flame. r=$'\e[31m' y=$'\e[33m' br=$'\e[1;31m' by=$'\e[1;33m' c=$'\e[0m' bs=$'\e[1;30m' #w=$'\e[37m' flame_gradient=( # "$w#$c" "$by@$c" "$by#$c" "$y#$c" "$y@$c" "$br@$c" "$br#$c" "$r#$c" # "$bs($c" # "$bs($c" # "$bs)$c" # "$bs.$c" " " ) # TODO: Use 256 color palette. declare -ia cells=() ## # init tput clear n_rows=$(tput lines) n_cols=$(tput cols) printf 'rows: %d\ncols: %d\n' "$n_rows" "$n_cols" #for cell in $(seq 0 $(((n_rows * n_cols) - 1))) for ((cell=0;cell=n_cols;--cell)) do cell_l=${cells[$cell-$n_cols-1]} cell_b=${cells[$cell-$n_cols]} # cell_l from previous iteration. cell_r=${cells[$cell-$n_cols+1]} # cell_b from previous iteration. # The flames cool between rows. cells[cell]=$(((cell_l+cell_b+cell_r)/3-(256/n_rows))) [[ ${cells[cell]} -lt 0 ]] && cells[cell]=0 done } print_all(){ # Wrong order. This burns downwards. declare -i cell for cell in "${cells[@]}" do num_to_cell $cell done } print_rows(){ declare -i row for ((row=n_rows-1;row>=0;--row)) do # Print rows top to bottom: tput cup $((n_rows-row)) 0 print_row $row # Print rows bottom to top: # tput cup $row 0 # print_row $((n_rows-1-row)) done # TODO: # It should be more efficient to print all at once. } print_row(){ declare -i row=$1 declare -i cell for ((cell=row*n_cols;cell<(row+1)*n_cols;++cell)) do num_to_cell "${cells[cell]}" done } test_fire() { # Saturate base row. for ((cell=0;cell