Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # create_POV_data_files
- cd "$(dirname "$0")"
- clear
- echo ""; echo "Welcome! Let's make some POV images!"; echo ""
- # replace whitespace in source filename with underscores
- find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done
- have_logo=0
- height_only=0
- # get quantity of .png files and build array to print if multiples
- files=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
- pngs=$(find . -type f -name '*.png')
- if [ "$files" -ge 2 ]; then
- echo "OOPS! Too many .png image files found!"
- echo ""
- for strip in ${pngs[@]}; do
- basename="${strip##*/}"
- echo "${basename[*]}"
- done
- echo ""
- echo "There needs to be only ONE source .png image in the pov_tools folder."
- echo ""
- echo "Press 'r' - to remove ALL FILES with 'preview' in the name. "
- echo " If the additional filenames do not contain 'preview',"
- echo " manually delete all files except your source image."
- echo ""
- echo "Press q to quit."
- read -n 1 -r -s -p $'Press any other key to start over.\n' fix
- case $fix in
- r) make clean;
- echo ""
- echo "Files containing *preview* deleted if they existed"
- read -n 1 -r -s -p $'Press any key to continue.\n'
- exec "./create_POV_data_files";;
- q) exit;;
- *) exec "./create_POV_data_files";;
- esac
- fi
- if [ "$files" -lt 1 ]; then
- echo "OOPS! No .png image files found!"
- echo ""
- echo "Let's download an example Star Wars Logo for you to try :)"
- echo "DOWNLOADING: 1024px-Star_Wars_Logo.svg.png .........."
- echo ""
- echo ""
- wget https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1024px-Star_Wars_Logo.svg.png&>/dev/null &
- logo=$"1024px-Star_Wars_Logo.svg.png"
- have_logo=1
- echo "Press q to quit, or"
- read -n 1 -r -s -p $'press any other key to continue...\n' delay
- if [ "$delay" = "q" ]; then exit; fi
- fi
- echo ""
- case $have_logo in
- 1) echo "Found the following source image file: $logo"
- echo ""
- image="$logo";;
- 0) source=$(find . -type f -name '*.png')
- for strip in ${source[@]}; do
- sourcebase="${strip##*/}"
- done
- echo "Found the following source image file: ${sourcebase[*]}"
- echo ""
- # check for multiples and for filename contains 'preview'
- recheck=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
- if [[ $sourcebase == *"preview"* ]]; then
- echo "OOPS! Source file name can not contain 'preview'."
- echo "Please use a different file name."
- echo "Press q to quit, or"
- read -n 1 -r -s -p $'press any key to try again.\n' retry
- if [ "$retry" = "q" ]; then exit; fi
- exec "./create_POV_data_files"
- elif [ $recheck -ge 2 ]; then
- exec "./create_POV_data_files"
- fi
- image="$sourcebase";;
- esac
- valid_option=0
- while [ "$valid_option" != "1" ]
- do
- echo "Please select the settings you want to create the POV image with: "
- echo "1 - Preset 1 (HEIGHT=144, LENGTH=36, OFFSET=18) default"
- echo "2 - Preset 2 (HEIGHT=97, LENGTH=63, OFFSET=50)"
- echo "3 - Preset 3 (HEIGHT=72, LENGTH=50, OFFSET=15)"
- echo "4 - Height entry only"
- echo "5 - custom options"
- echo "q - to quit"
- read -n 1 -r -s -p $"" option
- case $option in
- "") echo "! Some option is needed. Please try again"; echo "";;
- 1) make IMAGE=$image OPTIONS="--height=144 --length=36 --offset=18" HEIGHT=144; exit;;
- 2) make IMAGE=$image OPTIONS="--height=97 --length=63 --offset=50" HEIGHT=97; exit;;
- 3) make IMAGE=$image OPTIONS="--height=72 --length=50 --offset=15" HEIGHT=72; exit;;
- 4) height_only=1; valid_option=1;echo ""; echo "Height entry only";;
- 5) valid_option=1; echo ""; echo "custom options";;
- # 6)
- # 7) ------ ADDITIONAL USER PRESETS CAN BE ADDED HERE -------
- # 8) or move 4 & 5 down to keep them all together
- *[q*]*) exit;;
- *) echo ""; echo "! Not a valid option, Please try again,"; echo "or type q to quit. "; echo "";;
- esac
- done
- validinput=0
- while [ "$validinput" != "1" ]
- do
- echo ""
- read -p "How many pixels are in your blade? (min 30, ENTER for default 144) " height
- #calc_len=$(( bc <<< "scale=0; $height * 100 / 2.54 / 144.0" ))
- #calc_len_cm=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3")
- #calc_len_inch=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3")
- if [[ $height == "" ]]; then height=144; length=36; offset=18; validinput=1; echo "ENTER";
- elif [[ $height == "q" ]]; then exit
- elif [[ $height -lt 30 ]]; then
- echo "! Minimum amount of pixels is 30, try again."
- elif [[ $height -gt 300 ]] && [[ $height -le 576 ]]; then
- echo "Are you sure there's that many pixels?? (y/n)"
- read -n 1 -r -s -p "" too_many
- if [[ $too_many == "y" ]]; then validinput=1; else echo ""; fi
- elif [[ $height -gt 576 ]]; then
- echo "! That is not a valid number or d."
- echo " Please try again or type 'q' to quit."
- echo ""
- elif [[ $height =~ ^[0-9]{1,3}$ ]]; then validinput=1
- fi
- done
- if [ $height_only != 1 ]; then
- validinput=0
- while [ "$validinput" != "1" ]
- do
- #read -p "What is your preferred unit of measuring distance? (i - inch, c - cm)" unit
- #if [[ $unit == "q" ]]; then exit
- #elif [[ $unit == "i" ]]; then calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1
- #elif [[ $unit == "c" ]]; then calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1
- #else
- # echo "! That is not a valid option."
- # echo " Please choose inches or cm or type 'q' to quit."
- # echo ""
- #fi
- echo ""
- echo "What is your preferred unit of measuring distance? (i - inch, c - cm)"
- read -n 1 -r -s -p $"" unit
- case $unit in
- "") echo "! Some option is needed. Please try again"; echo "";;
- i) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1;echo "INCH";;
- c) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1;echo "CM";;
- *[q*]*) exit;;
- *) echo ""; echo "! Not a valid option, Please choose inches or cm,"; echo "or type q to quit. "; echo "";;
- esac
- done
- validinput=0
- while [ "$validinput" != "1" ]
- do
- echo ""
- read -p "How long is your blade? (min 5, ENTER for default $calc_len) " length
- if [[ $length == "" ]]; then length=$calc_len validinput=1
- elif [[ $length == "q" ]]; then exit
- elif [[ $length -lt 5 ]]; then
- echo "! Minimum length is 5, try again."; echo ""
- elif [[ $length -gt 60 ]]; then
- echo "Are you sure your blade is that long?? (y/n) "
- read -n 1 -r -s -p "" too_long
- if [[ $too_long == "y" ]]; then validinput=1; else echo ""; fi
- elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
- else
- echo "! That is not a valid number or d."
- echo " Please try again or type 'q' to quit."
- echo ""
- fi
- done
- validinput=0
- while [ "$validinput" != "1" ]
- do
- echo "How long is your arm?"
- read -p "(hand to pivot point: shoulder/elbow/wrist) (min 5, ENTER for default $offset_default) " offset
- if [[ $offset == "" ]]; then offset=$offset_default validinput=1
- elif [[ $offset == "q" ]]; then exit
- elif [[ $offset -lt 5 ]]; then
- echo "! Minimum offset is 5, try again."; echo ""
- elif [[ $offset -gt 40 ]]; then
- echo "Are you sure your arm is that long?? (y/n) "
- read -n 1 -r -s -p "" long_arm
- if [[ $long_arm == "y" ]]; then validinput=1; else echo ""; fi
- elif [[ $offset =~ ^[0-9]{1,3}$ ]]; then validinput=1
- else
- echo "! That is not a valid number or d."
- echo " Please try again or type 'q' to quit."
- echo ""
- fi
- done
- else # height_only
- length=36 offset=18
- fi
- make IMAGE=$image OPTIONS="--height=$height --length=$length --offset=$offset" HEIGHT=$height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement