How to resolve the algorithm Write language name in 3D ASCII step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Write language name in 3D ASCII step by step in the UNIX Shell programming language

Table of Contents

Problem Statement

Write/display a language's name in 3D ASCII.

(We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Write language name in 3D ASCII step by step in the UNIX Shell programming language

Source code in the unix programming language

#!/usr/bin/env bash
mapfile -t name <
Aimhacks
EOF

main() {
  banner3d_1 "${name[@]}"
  echo
  banner3d_2 "${name[@]}"
  echo
  banner3d_3 "${name[@]}"
}

space() {
  local -i n i
  (( n=$1 )) || n=1
  if (( n < 1 )); then n=1; fi
  for ((i=0; i
    printf ' '
  done
  printf '\n'
}

banner3d_1() {
  local txt i
  mapfile -t txt < <(printf '%s\n' "$@" | sed -e 's,#,__/,g' -e 's/ /   /g')
  for i in "${!txt[@]}"; do
    printf '%s%s\n' "$(space $(( ${#txt[@]} - i )))" "${txt[i]}"
  done
}

banner3d_2() {
  local txt i line line2
  mapfile -t txt < <(printf '%s \n' "$@")
  for i in "${!txt[@]}"; do
    line=${txt[i]}
    line2=$(printf '%s%s' "$(space $(( 2 * (${#txt[@]} - i) )))" "$(sed -e 's, ,   ,g' -e 's,#,///,g' -e 's,/ ,/\\,g' <<<"$line")")
    printf '%s\n%s\n' "$line2" "$(tr '/\\' '\\/' <<<"$line2")"
  done
}

banner3d_3() {
  # hard-coded fancy one
  cat <<'EOF'
  ______________      ___________    ___________   ____       ____␣
 /             /\    /          |\  /|          \ |\   \     |\   \
/_____________/  /| /___________||  ||___________\| \___\    |  \___\␣
|             \ / |/             \  /             | |   |    |  |   |
|   ________   |  |   ________   |  |    _________| |   |    |  |   |
|   |  |___|   |  |   | |____|   |  |   |_______  | |   |____|  |   |
|   | /    |   | /|   | /    |   |  |   |       \ | |   |     \ |   |
|   |/_____|   |/ |   |/_____|   |  |   |________\| |   |______\|   |
|              / /|              |  |             \ |               |
|    ______   \ / |    _______   |  \_________    | |    ________   |
|   |  |___|   |  |   | |    |   |  _________/|   | |   |    |  |   |
|   | /    |   |  |   | |    |   | |         ||   | |   |    |  |   |
|   |/_____|   | /|   | |    |   | |_________|/   | |   |     \ |   |
|              |/ |   | |    |   | |              | |   |      \|   |
|_____________/   |___|/     |___| |_____________/ \|___|       |___|
EOF
}

main "$@"


  

You may also check:How to resolve the algorithm Program name step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Sorting algorithms/Shell sort step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Inverted index step by step in the jq programming language
You may also check:How to resolve the algorithm Search a list step by step in the Ursala programming language
You may also check:How to resolve the algorithm String append step by step in the Lambdatalk programming language