Advertisement
kaQnub

create_POV_data_files with metric / imp

Jan 19th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # create_POV_data_files
  4.  
  5. cd "$(dirname "$0")"
  6. clear
  7. echo ""; echo "Welcome! Let's make some POV images!"; echo ""
  8. # replace whitespace in source filename with underscores
  9. find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done
  10. have_logo=0
  11. height_only=0
  12. # get quantity of .png files and build array to print if multiples
  13. files=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
  14. pngs=$(find . -type f -name '*.png')
  15.  
  16. if [ "$files" -ge 2 ]; then
  17.     echo "OOPS! Too many .png image files found!"
  18.     echo ""
  19.     for strip in ${pngs[@]}; do
  20.         basename="${strip##*/}"
  21.         echo "${basename[*]}"
  22.     done
  23.     echo ""
  24.     echo "There needs to be only ONE source .png image in the pov_tools folder."
  25.     echo ""
  26.     echo "Press 'r' - to remove ALL FILES with 'preview' in the name. "
  27.     echo "    If the additional filenames do not contain 'preview',"
  28.     echo "    manually delete all files except your source image."
  29.     echo ""
  30.     echo "Press q to quit."
  31.     read -n 1 -r -s -p $'Press any other key to start over.\n' fix
  32.     case $fix in
  33.         r) make clean;
  34.             echo ""
  35.             echo "Files containing *preview* deleted if they existed"
  36.             read -n 1 -r -s -p $'Press any key to continue.\n'
  37.             exec "./create_POV_data_files";;
  38.         q) exit;;
  39.         *) exec "./create_POV_data_files";;
  40.     esac
  41. fi
  42.  
  43. if [ "$files" -lt 1 ]; then
  44.     echo "OOPS! No .png image files found!"
  45.     echo ""
  46.     echo "Let's download an example Star Wars Logo for you to try :)"
  47.     echo "DOWNLOADING: 1024px-Star_Wars_Logo.svg.png .........."
  48.     echo ""
  49.     echo ""
  50.     wget https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1024px-Star_Wars_Logo.svg.png&>/dev/null &
  51.     logo=$"1024px-Star_Wars_Logo.svg.png"
  52.     have_logo=1
  53.     echo "Press q to quit, or"
  54.     read -n 1 -r -s -p $'press any other key to continue...\n' delay
  55.     if [ "$delay" = "q" ]; then exit; fi
  56. fi
  57.  
  58. echo ""
  59. case $have_logo in
  60.     1) echo "Found the following source image file: $logo"
  61.         echo ""
  62.         image="$logo";;
  63.     0)  source=$(find . -type f -name '*.png')
  64.         for strip in ${source[@]}; do
  65.             sourcebase="${strip##*/}"
  66.         done
  67.         echo "Found the following source image file: ${sourcebase[*]}"
  68.         echo ""
  69.         # check for multiples and for filename contains 'preview'
  70.         recheck=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
  71.         if [[ $sourcebase == *"preview"* ]]; then
  72.             echo "OOPS! Source file name can not contain 'preview'."
  73.             echo "Please use a different file name."
  74.             echo "Press q to quit, or"
  75.             read -n 1 -r -s -p $'press any key to try again.\n' retry
  76.             if [ "$retry" = "q" ]; then exit; fi
  77.             exec "./create_POV_data_files"
  78.         elif [ $recheck -ge 2 ]; then
  79.             exec "./create_POV_data_files"
  80.         fi
  81.         image="$sourcebase";;
  82. esac
  83.  
  84. valid_option=0
  85.  
  86. while [ "$valid_option" != "1" ]
  87. do
  88.     echo "Please select the settings you want to create the POV image with: "
  89.     echo "1 - Preset 1 (HEIGHT=144, LENGTH=36, OFFSET=18) default"
  90.     echo "2 - Preset 2 (HEIGHT=97,  LENGTH=63, OFFSET=50)"
  91.     echo "3 - Preset 3 (HEIGHT=72,  LENGTH=50, OFFSET=15)"
  92.     echo "4 - Height entry only"
  93.     echo "5 - custom options"
  94.     echo "q - to quit"
  95.     read -n 1 -r -s -p $"" option
  96.     case $option in
  97.         "") echo "! Some option is needed. Please try again";   echo "";;
  98.         1)  make IMAGE=$image OPTIONS="--height=144 --length=36 --offset=18" HEIGHT=144; exit;;
  99.         2)  make IMAGE=$image OPTIONS="--height=97 --length=63 --offset=50" HEIGHT=97; exit;;
  100.         3)  make IMAGE=$image OPTIONS="--height=72 --length=50 --offset=15" HEIGHT=72; exit;;
  101.         4)  height_only=1; valid_option=1;echo ""; echo "Height entry only";;
  102.         5)  valid_option=1; echo ""; echo "custom options";;
  103. #       6)
  104. #       7) ------ ADDITIONAL USER PRESETS CAN BE ADDED HERE -------
  105. #       8)       or move 4 & 5 down to keep them all together
  106.         *[q*]*) exit;;
  107.         *)  echo ""; echo "! Not a valid option, Please try again,"; echo "or type q to quit. "; echo "";;
  108.     esac
  109. done
  110.  
  111. validinput=0
  112.  
  113. while [ "$validinput" != "1" ]
  114. do
  115.     echo ""
  116.     read -p "How many pixels are in your blade? (min 30, ENTER for default 144) " height
  117.     #calc_len=$(( bc <<< "scale=0; $height * 100 / 2.54 / 144.0" ))
  118.     #calc_len_cm=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3")
  119.     #calc_len_inch=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3")
  120.     if [[ $height == "" ]]; then height=144; length=36; offset=18; validinput=1; echo "ENTER";
  121.     elif [[ $height == "q" ]]; then exit
  122.     elif [[ $height -lt 30 ]]; then
  123.         echo "! Minimum amount of pixels is 30, try again."
  124.     elif [[ $height -gt 300 ]] && [[ $height -le 576 ]]; then
  125.         echo "Are you sure there's that many pixels?? (y/n)"
  126.         read -n 1 -r -s -p "" too_many
  127.         if [[ $too_many == "y" ]]; then validinput=1; else echo ""; fi
  128.     elif [[ $height -gt 576 ]]; then
  129.         echo "! That is not a valid number or d."
  130.         echo "  Please try again or type 'q' to quit."
  131.         echo ""
  132.     elif [[ $height =~ ^[0-9]{1,3}$ ]]; then validinput=1
  133.     fi
  134. done
  135.  
  136. if [ $height_only != 1 ]; then
  137.     validinput=0
  138.     while [ "$validinput" != "1" ]
  139.     do
  140.         #read -p "What is your preferred unit of measuring distance? (i - inch, c - cm)" unit
  141.         #if [[ $unit == "q" ]]; then exit
  142.         #elif [[ $unit == "i" ]]; then calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1
  143.         #elif [[ $unit == "c" ]]; then calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1
  144.         #else
  145.         #   echo "! That is not a valid option."
  146.         #   echo "  Please choose inches or cm or type 'q' to quit."
  147.         #   echo ""
  148.         #fi
  149.         echo ""
  150.         echo "What is your preferred unit of measuring distance? (i - inch, c - cm)"
  151.         read -n 1 -r -s -p $"" unit
  152.         case $unit in
  153.             "") echo "! Some option is needed. Please try again";   echo "";;
  154.             i)  calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1;echo "INCH";;
  155.             c)  calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1;echo "CM";;
  156.             *[q*]*) exit;;
  157.             *)  echo ""; echo "! Not a valid option, Please choose inches or cm,"; echo "or type q to quit. "; echo "";;
  158.         esac
  159.     done
  160.     validinput=0
  161.     while [ "$validinput" != "1" ]
  162.     do
  163.         echo ""
  164.         read -p "How long is your blade? (min 5, ENTER for default $calc_len) " length
  165.         if [[ $length == "" ]]; then length=$calc_len validinput=1
  166.         elif [[ $length == "q" ]]; then exit
  167.         elif [[ $length -lt 5 ]]; then
  168.             echo "! Minimum length is 5, try again."; echo ""
  169.         elif [[ $length -gt 60 ]]; then
  170.             echo "Are you sure your blade is that long?? (y/n) "
  171.             read -n 1 -r -s -p "" too_long
  172.             if [[ $too_long == "y" ]]; then validinput=1; else echo ""; fi 
  173.         elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
  174.         else
  175.             echo "! That is not a valid number or d."
  176.             echo "  Please try again or type 'q' to quit."
  177.             echo ""
  178.         fi
  179.     done
  180.  
  181.     validinput=0
  182.     while [ "$validinput" != "1" ]
  183.     do
  184.         echo "How long is your arm?"
  185.         read -p "(hand to pivot point: shoulder/elbow/wrist) (min 5, ENTER for default $offset_default) " offset
  186.         if [[ $offset == "" ]]; then  offset=$offset_default validinput=1
  187.         elif [[ $offset == "q" ]]; then exit
  188.         elif [[ $offset -lt 5 ]]; then
  189.             echo "! Minimum offset is 5, try again."; echo ""
  190.         elif [[ $offset -gt 40 ]]; then
  191.             echo "Are you sure your arm is that long?? (y/n) "
  192.             read -n 1 -r -s -p "" long_arm
  193.             if [[ $long_arm == "y" ]]; then validinput=1; else echo ""; fi 
  194.         elif [[ $offset =~ ^[0-9]{1,3}$ ]]; then validinput=1
  195.         else
  196.             echo "! That is not a valid number or d."
  197.             echo "  Please try again or type 'q' to quit."
  198.             echo ""
  199.         fi
  200.     done
  201. else # height_only
  202.     length=36 offset=18
  203. fi
  204. make IMAGE=$image OPTIONS="--height=$height  --length=$length --offset=$offset" HEIGHT=$height
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement