From 89312254e3eb1aa496dff15f2d503e97f3c985f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20W=C3=BChrer?= Date: Sun, 26 Apr 2026 15:47:41 +0200 Subject: fire --- bin/fire | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man/man1/fire.1 | 59 +++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100755 bin/fire create mode 100644 man/man1/fire.1 diff --git a/bin/fire b/bin/fire new file mode 100755 index 0000000..b9c6c98 --- /dev/null +++ b/bin/fire @@ -0,0 +1,173 @@ +#!/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