Advertisement
kaQnub

create_POV_data_files PR :)

Jan 20th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.18 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. preset=0
  13. # get quantity of .png files and build array to print if multiples
  14. files=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
  15. pngs=$(find . -type f -name '*.png')
  16.  
  17. if [ "$files" -ge 2 ]; then
  18.     echo "OOPS! Too many .png image files found!"
  19.     echo ""
  20.     for strip in ${pngs[@]}; do
  21.         no_path="${strip##*/}"
  22.         echo ${no_path[*]}
  23.     done
  24.     echo ""
  25.     echo "There needs to be only ONE source .png image in the pov_tools folder."
  26.     echo ""
  27.     echo "Type 'r' - to remove ALL FILES with 'preview' in the name. "
  28.     echo "  If the additional filenames do not contain 'preview',"
  29.     echo "  manually delete all files except your source image."
  30.     echo ""
  31.     echo "Type q to quit."
  32.     read -p $'Press ENTER to start over.\n' fix
  33.     case $fix in
  34.         r) rm *preview*.png;
  35.             echo ""
  36.             echo "Files containing *preview* deleted if they existed"
  37.             read -n 1 -r -s -p $'Press any key to continue.\n'
  38.             exec "./create_POV_data_files";;
  39.         q) exit;;
  40.         *) exec "./create_POV_data_files";;
  41.     esac
  42. fi
  43.  
  44. if [ "$files" -lt 1 ]; then
  45.     echo "OOPS! No .png image files found!"
  46.     echo ""
  47.     echo "Let's download an example Star Wars Logo for you to try :)"
  48.     echo "DOWNLOADING: 1024px-Star_Wars_Logo.svg.png .........."
  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.         sourcebase="${logo%.*}"
  63.         image="$logo";;
  64.     0)  source=$(find . -type f -name '*.png')
  65.         for strip in ${source[@]}; do
  66.             sourcename="${strip##*/}"
  67.             sourcebase="${sourcename%.*}"
  68.         done
  69.         echo "Found the following source image file: ${sourcename[*]}"
  70.         echo ""
  71.         # check for multiples and for filename contains 'preview'
  72.         recheck=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
  73.         if [[ $sourcename == *"preview"* ]]; then
  74.             echo "OOPS! Source file name can not contain 'preview'."
  75.             echo "Please use a different file name."
  76.             echo "Press q to quit, or"
  77.             read -n 1 -r -s -p $'press any key to try again.\n' retry
  78.             if [ "$retry" = "q" ]; then exit; fi
  79.             exec "./create_POV_data_files"
  80.         elif [ $recheck -ge 2 ]; then
  81.             exec "./create_POV_data_files"
  82.         fi
  83.         image="$sourcename";;
  84. esac
  85.  
  86. valid_option=0
  87.  
  88. while [[ "$valid_option" != 1 ]]
  89. do
  90.     echo "Please select the settings you want to create the POV image with: "
  91.     echo "1 - Preset 1 (HEIGHT=144, LENGTH=39, OFFSET=18)"
  92.     echo "2 - Preset 2 (HEIGHT=97,  LENGTH=63, OFFSET=50)"
  93.     echo "3 - Preset 3 (HEIGHT=72,  LENGTH=50, OFFSET=15)"
  94.     echo "4 - Preset 4 (HEIGHT=72,  LENGTH=50, OFFSET=39)"
  95.     echo "5 - Height entry only"
  96.     echo "6 - Custom options"
  97.     echo "q - to quit"
  98.     read option
  99.     case $option in
  100.         "") echo "! Some option is needed. Please try again"; echo "";;
  101.         1)  make IMAGE=$image OPTIONS="--height=144 --length=39 --offset=18"; HEIGHT=144 preset=1 valid_option=1;;
  102.         2)  make IMAGE=$image OPTIONS="--height=97 --length=63 --offset=50"; HEIGHT=97 preset=1 valid_option=1;;
  103.         3)  make IMAGE=$image OPTIONS="--height=72 --length=50 --offset=15"; HEIGHT=72 preset=1 valid_option=1;;
  104.         4)  make IMAGE=$image OPTIONS="--height=72 --length=50 --offset=39"; HEIGHT=72 preset=1 valid_option=1;;
  105.         5)  height_only=1; valid_option=1;;
  106.         6)  valid_option=1;;
  107. #       7) ------ ADDITIONAL USER PRESETS CAN BE ADDED HERE LIKE THIS-------
  108. #       8) make IMAGE=$image OPTIONS="--height=H --length=L --offset=O"; HEIGHT=H preset=1 valid_option=1;;
  109. #       9)       or move 5 & 6 down to keep them all together
  110. #       *) H is amount of pixels in your blade,
  111. #       *) L is the length of that blade in the unit of the distance of your choosing (most common inches or centimeters)
  112. #       *) O is offset - the distance (same unit as L) from the bottom of the blade to the fulcrum (e.g. the joint you are swinging with)
  113.         *[q*]*) exit;;
  114.         *)  echo ""
  115.             echo "! Not a valid option, Please try again,"
  116.             echo "or type q to quit. "; echo "";;
  117.     esac
  118. done
  119.  
  120. validinput=0
  121.  
  122. while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  123. do
  124.     echo ""
  125.     echo "How many pixels are in your blade? (Press ENTER for default 144) "
  126.     read  height
  127.     if [[ $height == "" ]]; then height=144 length=39 offset=18 validinput=1; echo "Default 144"
  128.     elif [[ $height == "q" ]]; then exit
  129.     elif [[ $height -gt 264 ]] && [[ $height -le 576 ]]; then
  130.         read -p "Are you sure there's that many pixels?? (y/n)" too_many
  131.         if [[ $too_many == "y" ]]; then validinput=1; else echo ""; fi
  132.     elif [[ $height -gt 576 ]]; then
  133.         echo "! That is likely impossible."
  134.         echo "  Please try again or type 'q' to quit."; echo ""
  135.     elif [[ $height =~ ^[0-9]{1,3}$ ]]; then validinput=1
  136.     fi
  137. done
  138.  
  139. if [ $height_only != 1 ]; then
  140.     validinput=0
  141.     while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  142.     do
  143.         echo ""
  144.         echo "What is your preferred unit of measuring distance? (i - inches, c - cm) "
  145.         read pref
  146.         case $pref in
  147.             "") echo "! Some option is needed. Please try again"; echo "";;
  148.             i)  calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1; units="inches"; echo "";;
  149.             c)  calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1; units="centimeters"; echo "";;
  150.             *[q*]*) exit;;
  151.             *)  echo ""
  152.                 echo "! Not a valid option, Please choose inches or cm,"
  153.                 echo "or type q to quit. "; echo "";;
  154.         esac
  155.     done
  156.  
  157.     validinput=0
  158.     while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  159.     do
  160.         echo "How many "$units" is your blade? (Press ENTER for calculated default $calc_len) "
  161.         read length
  162.         if [[ $units == "inches" ]]; then max=48; else max=122; fi
  163.         if [[ $length == "" ]]; then length=$calc_len validinput=1; echo "Default $calc_len"
  164.         elif [[ $length == "q" ]]; then exit
  165.         elif [[ $length -gt $max ]]; then
  166.             read -p "Are you sure your blade is that long?? (y/n) " too_long
  167.             if [[ $too_long == "y" ]]; then validinput=1; else echo ""; fi
  168.         elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
  169.         else
  170.             echo "! That is likely impossible."
  171.             echo "  Please try again or type 'q' to quit."
  172.             echo ""
  173.         fi
  174.     done
  175.  
  176.     validinput=0
  177.     while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  178.     do
  179.         echo ""
  180.         echo "How many "$units" is the distance from the bottom of the blade to the fulcrum?"
  181.         echo "(The fulcrum is usually the swinging joint) (Press ENTER for default $offset_default)"
  182.         read offset
  183.         if [[ $units == "inches" ]]; then max=30; else max=76; fi
  184.         if [[ $offset == "" ]]; then  offset=$offset_default validinput=1; echo "Default $offset_default"
  185.         elif [[ $offset == "q" ]]; then exit
  186.         elif [[ $offset -gt $max ]]; then
  187.             read -p "Are you sure this distance is that long?? (y/n) " long_distance
  188.             if [[ $long_distance == "y" ]]; then validinput=1; else echo ""; fi
  189.         elif [[ $offset =~ ^[0-9]{1,3}$ ]]; then validinput=1
  190.         else
  191.             echo "! That is likely impossible."
  192.             echo "  Please try again or type 'q' to quit."
  193.             echo ""
  194.         fi
  195.     done
  196. else # height_only
  197.     length=39 offset=18
  198. fi
  199.  
  200. if [ $preset == 0 ]; then make IMAGE=$image OPTIONS="--height=$height  --length=$length --offset=$offset"; HEIGHT=$height; fi
  201. mv ./preview.png ./"${sourcebase}"_"${HEIGHT}"_preview.png
  202. mv ./image.h ../styles/"${sourcebase}"_"${HEIGHT}"_FC_POV_data.h
  203. mv ./image_pgm.h ../styles/"${sourcebase}"_"${HEIGHT}"_SC_POV_data.h
  204. mv ./image_8bit.h ../styles/"${sourcebase}"_"${HEIGHT}"_8b_POV_data.h
  205. echo ""
  206. echo ""
  207. echo "Conversion DONE! Find your files as shown below."
  208. echo ""
  209. echo "preview image:"
  210. echo "  ProffieOS/pov_tools/"$sourcebase"_"$HEIGHT"_preview.png"
  211. echo "Full color image data file:"
  212. echo "  ProffieOS/styles/"$sourcebase"_"$HEIGHT"_FC_POV_data.h"
  213. echo "Single color image data file:"
  214. echo "  ProffieOS/styles/"$sourcebase"_"$HEIGHT"_SC_POV_data.h"
  215. echo "256 color image data file:"
  216. echo "  ProffieOS/styles/"$sourcebase"_"$HEIGHT"_8b_POV_data.h"
  217. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement