Advertisement
NoSloppy

Untitled

Jan 21st, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 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 4 & 5 down to keep them all together
  110. *[q*]*) exit;;
  111. *) echo ""
  112. echo "! Not a valid option, Please try again,"
  113. echo "or type q to quit. "; echo "";;
  114. esac
  115. done
  116.  
  117. validinput=0
  118.  
  119. while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  120. do
  121. echo ""
  122. echo "How many pixels are in your blade? (Press ENTER for default 144) "
  123. read height
  124. if [[ $height == "" ]]; then height=144 length=36 offset=18 validinput=1; echo "Default 144"
  125. elif [[ $height == "q" ]]; then exit
  126. elif [[ $height -gt 264 ]] && [[ $height -le 576 ]]; then
  127. read -p "Are you sure there's that many pixels?? (y/n)" too_many
  128. if [[ $too_many == "y" ]]; then validinput=1; else echo ""; fi
  129. elif [[ $height -gt 576 ]]; then
  130. echo "! That is likely impossible."
  131. echo " Please try again or type 'q' to quit."; 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 ]] && [[ $preset == 0 ]]
  139. do
  140. echo ""
  141. echo "What is your preferred unit of measuring distance? (i - inches, c - cm) "
  142. read pref
  143. case $pref in
  144. "") echo "! Some option is needed. Please try again"; echo "";;
  145. i) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144 * 100 / 254))e-3"); offset_default=18; validinput=1; units="inches"; echo "";;
  146. c) calc_len=$(printf %.0f "$((10**3 * $height * 100 / 144))e-3"); offset_default=46; validinput=1; units="centimeters"; echo "";;
  147. *[q*]*) exit;;
  148. *) echo ""
  149. echo "! Not a valid option, Please choose inches or cm,"
  150. echo "or type q to quit. "; echo "";;
  151. esac
  152. done
  153.  
  154. validinput=0
  155. while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  156. do
  157. echo "How many "$units" is your blade? (Press ENTER for calculated default $calc_len) "
  158. read length
  159. if [[ $units == "inches" ]]; then max=48; else max=122; fi
  160. if [[ $length == "" ]]; then length=$calc_len validinput=1; echo "Default $calc_len"
  161. elif [[ $length == "q" ]]; then exit
  162. elif [[ $length -gt $max ]]; then
  163. read -p "Are you sure your blade is that long?? (y/n) " too_long
  164. if [[ $too_long == "y" ]]; then validinput=1; else echo ""; fi
  165. elif [[ $length =~ ^[0-9]{1,3}$ ]]; then validinput=1
  166. else
  167. echo "! That is likely impossible."
  168. echo " Please try again or type 'q' to quit."
  169. echo ""
  170. fi
  171. done
  172.  
  173. validinput=0
  174. while [[ "$validinput" != 1 ]] && [[ $preset == 0 ]]
  175. do
  176. echo ""
  177. echo "How many "$units" is the distance from the bottom of the blade to the fulcrum?"
  178. echo "(The fulcrum is usually the swinging joint) (Press ENTER for default $offset_default)"
  179. read offset
  180. if [[ $units == "inches" ]]; then max=30; else max=76; fi
  181. if [[ $offset == "" ]]; then offset=$offset_default validinput=1; echo "Default $offset_default"
  182. elif [[ $offset == "q" ]]; then exit
  183. elif [[ $offset -gt $max ]]; then
  184. read -p "Are you sure this distance is that long?? (y/n) " long_arm
  185. if [[ $long_arm == "y" ]]; then validinput=1; else echo ""; fi
  186. elif [[ $offset =~ ^[0-9]{1,3}$ ]]; then validinput=1
  187. else
  188. echo "! That is likely impossible."
  189. echo " Please try again or type 'q' to quit."
  190. echo ""
  191. fi
  192. done
  193. else # height_only
  194. length=36 offset=18
  195. fi
  196.  
  197. if [ $preset == 0 ]; then make IMAGE=$image OPTIONS="--height=$height --length=$length --offset=$offset"; HEIGHT=$height; fi
  198. mv ./preview.png ./"${sourcebase}"_"${HEIGHT}"_preview.png
  199. mv ./image.h ../styles/"${sourcebase}"_"${HEIGHT}"_FC_POV_data.h
  200. mv ./image_pgm.h ../styles/"${sourcebase}"_"${HEIGHT}"_SC_POV_data.h
  201. mv ./image_8bit.h ../styles/"${sourcebase}"_"${HEIGHT}"_8b_POV_data.h
  202. echo ""
  203. echo ""
  204. echo "Conversion DONE! Find your files as shown below."
  205. echo ""
  206. echo "preview image:"
  207. echo " ProffieOS/pov_tools/"$sourcebase"_"$HEIGHT"_preview.png"
  208. echo "Full color image data file:"
  209. echo " ProffieOS/styles/"$sourcebase"_"$HEIGHT"_FC_POV_data.h"
  210. echo "Single color image data file:"
  211. echo " ProffieOS/styles/"$sourcebase"_"$HEIGHT"_SC_POV_data.h"
  212. echo "256 color image data file:"
  213. echo " ProffieOS/styles/"$sourcebase"_"$HEIGHT"_8b_POV_data.h"
  214. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement