Created
October 26, 2024 14:10
-
-
Save mdriscoll93/c7ca6fcc88aab61c41e075b0d630e89f to your computer and use it in GitHub Desktop.
conifers at the command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env bash | |
| # just in case your default repositories don't contain `tree` | |
| trap "tput reset; tput cnorm; exit" 2 | |
| # setup | |
| clear | |
| tput civis | |
| tree_height=20 # Set tree height | |
| col_center=$(($(tput cols) / 2)) # Center | |
| base_row=$(($(tput lines) / 2 + tree_height / 2)) # Position bottom tree | |
| # trunk | |
| tput sgr0; tput setaf 130 | |
| for ((i=0; i<3; i++)); do | |
| tput cup $((base_row + i)) $col_center | |
| echo 'mWm' | |
| done | |
| # green | |
| draw_tree_row() { | |
| local row=$1 | |
| local width=$2 | |
| local start_col=$((col_center - width / 2)) # Center row | |
| tput setaf 2 # Set color to green | |
| tput bold | |
| tput cup $row $start_col | |
| for ((j=0; j<width; j++)); do | |
| echo -n "*" | |
| done | |
| tput sgr0 | |
| } | |
| # draw tree | |
| for ((i=tree_height; i>=1; i--)); do | |
| width=$((2 * i - 1)) | |
| row=$((base_row - (tree_height - i))) | |
| draw_tree_row $row $width | |
| sleep 0.1 # growing effect | |
| done | |
| tput cnorm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment