And we know the new default spits out 432x144?
looks different, but still works ok? I haven’t done on blade comparison.
800x144:
432x144:
And we know the new default spits out 432x144?
looks different, but still works ok? I haven’t done on blade comparison.
800x144:
432x144:
Saving memory is probably the most important one. On my darksaber i currently was at 99% (ProffieOS 5.9) so I had to comment out a good blade styles.
It’s 4 questions, not a wall of text.
I know. I ment if we were to enhance this by explaining more. Then it would exceed those 4 questions and maybe we have the scrolling text for Episode X - The POV Menace returns and strikes back.
“providing” as in print them? like
"What blade length in pixels? (d for default 144) "
?
Yes, something like that.
What I don’t understand is that why we need to get a
length
value if it’s meant to be the same as height, yet 144 and 36 are !=
What if a user enters height 133 but length 50?
To put the offset in perspective.
You are basically telling the code that 144 pixels are placed inside a 36" blade so that it knows how to implement the offset accordingly.
Trust me, It took my a long time figuring that out
If the user inputs the length wrongly, than he will hopefully see the mistake in his ways by watching the preview image.
Looks different, but might be okay. Fredrik wanted to decrease the angles it checks. to further reduce size and memory usage.
Script is coming along, but I can’t pin down the syntax for the digits.
case needs to be checked against:
"if not [digits(up to 3 places), or ‘d’]
I’ve tried:
case $height in
*[![0-9]{1,2,3} d]) nope
[\d{1,2,3}]) nope
[!0-9]|???|[!d]) nope
if [ $height != [0-9]|?|??|???|[d] ] ugh nope
I googled and found
(\d{3})|(\d{2})|(\d{1})
this is for 0 - 999 but the d is missing for me as well. 000 and 00 are also included here
There:
(^\d{3})|(\d{2})|(\d{1})|(^d$)
Edit even shorter:
(^\d{1,3})|(^d$)
Edit2: now without leading zeros 000:
^(0|[1-9][0-9]{0,2})$|(^d$)
I think I got it. Going with a while do and reordering conditions
standby
Okay, but the last one should do what you want.
What was needed is start ^ and end $ character of string.
Seems you need a =~ compare operator.
Learn Bash - Regex matching
Trying to use it in a case, so there’s regular expression expansion stuff etc…
getting annoying. So close.
That line is not working as is.
Don’t need the ‘d’ anymore, already checking for that ahead of time.
I tried running it on the following site for testing purposes:
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java. Features a regex quiz & library.
For Bash I used this:
JDoodle is a free Online Compiler, Editor, IDE for Java, C, C++, PHP, Perl, Python, Ruby and many more. you can run your programs on the fly online and you can save and share them with others. Quick and Easy way to compile and run programs online.
With the Tutorial from here:
Learn Bash - Regex matching
And found a stackoverflow topic, that stated BASH_REMATCH, is platform-dependent.
Not sure how this can be included in an if statement.
Found something:
Learn Bash - Check if a string matches a regular expression
This seems to work:
pat='^(0|[1-9][0-9]{0,2})$'
string='999'
if [[ $string =~ $pat ]]; then echo "success"; else echo "fail"; fi
Dear Lord, I got it done. Jeez man lol. Thanks for hangin in there with me on this…
Could you test this?
aside from the first case where it downloads the image, i suggest a short filename, or have it in your clipboard.
Then just try all scenarios. Wrong answers, just hitting enter, quitting, etc…
I found everyhing to work well on my end.
One change to the default pov_tools folder is Makefile.
I set it to save the data files direcct into /styles. So, when more than one .png exist (because of preview.png is assumed), typing ‘del’ will run ‘make clean’. The point is, that is set to look in /styles to wipe out image*.h files.
The first 3 recipes end similarly:
anytopnm $(IMAGE) | ./pnmwindshieldwiper $(OPTIONS) | pnmscale -reduce 10 | ./pnmtorle >../styles/image.h
preview.png still writes to /pov_tools.
Alll working, just test it out please.
Now I should nap LOL
The fruits of my laborious overnight:
#!/bin/bash
# create_POV_data_files
cd "$(dirname "$0")"
clear
echo ""
find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done
have_logo=0
height_only=0
files=$(ls 2>/dev/null -Ubad1 -- *.png | wc -l)
if [ "$files" -ge 2 ]; then
echo "OOPS, too many .png image files found!"
echo ""
echo "There needs to be only ONE source .png image in the pov_tools folder."
echo ""
echo "Type 'del' - to just delete the last preview.png "
echo "Press ENTER - to start again."
read -p "Type q to quit for now. " fix
case $fix in
del) make clean;;
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
read -p "Hit ENTER to process the image, or type q to exit. " delay
if [ "$delay" = "q" ]; then exit
fi
fi
echo ""
case $have_logo in
1) echo "image name: $logo"
echo ""
image="$logo";;
0) echo "What is the source file name? (including.png) "
read image
if [ "$image" == "" ]; then
echo "Some option is needed. Press ENTER to try again"
read
exec "./create_POV_data_files"
fi
check=$(find . -type f -name "$image" | wc -l)
if [ "$check" -lt 1 ]; then
echo "OOPS. That file does not exist in the pov_tools folder."
read -p "Press ENTER to try again, or type q to quit: " redo
case $redo in
q) exit;;
*) exec "./create_POV_data_files";;
esac
fi;;
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"
read option
case $option in
"") echo "Some option is needed. Please try again"; echo "";;
1) make IMAGE=$image OPTIONS="--height=144 --length=36 --offset=18"; exit;;
2) make IMAGE=$image OPTIONS="--height=97 --length=63 --offset=50"; exit;;
3) make IMAGE=$image OPTIONS="--height=72 --length=50 --offset=15"; exit;;
4) height_only=1; valid_option=1;;
5) valid_option=1;;
*[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
read -p "What blade length in pixels? (d for default 144) " height
case $height in
"") echo "Some option is needed. Please try again"; echo "";;
*[d*]*) height=144 length=36 offset=18 validinput=1;;
*[q*]*) exit;;
*) if [[ $height =~ ^[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;;
esac
done
if [ $height_only != 1 ]; then
validinput=0
while [ "$validinput" != "1" ]
do
read -p "Hilt length in inches? (d for default 36) " length
case $length in
*[d*]*) length=36 validinput=1;;
*[q*]*) exit;;
*) if [[ $length =~ ^[0-9]{1,2}$ ]]; then validinput=1
else
echo "That is not a valid number or d."
echo "Please try again or type 'q' to quit."
echo ""
fi;;
esac
done
validinput=0
while [ "$validinput" != "1" ]
do
echo "Distance in inches to pivot point from hilt when swinging?"
read -p "(shoulder/elbow/wrist -> hilt) (d for default 18) " offset
case $offset in
*[d*]*) offset=18 validinput=1;;
*[q*]*) exit;;
*) if [[ $offset =~ ^[0-9]{1,2}$ ]]; then validinput=1
else
echo "That is not a valid number or d."
echo "Please try again or type 'q' to quit."
echo ""
fi;;
esac
done
else # height_only
length=36 offset=18
fi
make IMAGE=$image OPTIONS="--height=$height --length=$length --offset=$offset"
intitial process
make: *** [Makefile:35: clean] Error 1
Selecting the options
General
I understand why you positioned them the way you did (1-3 for Presets 1-3), but in case someone has more presets, manipulating this so height-only and custom remain at the bottom might get more complex instead of just adding one more line to it.
I had plans to rename my personal presets to more speaking names e.g. “TheChild” and “DarkSaber” anyway, which is why the corralation between pressed key and preset number might not be there. But that might just be me.
Preset 1
Preset 2
Preset 3
custom options
height-only
inputs
general
So overall it works really smoothly.
There are some issues of different severity, but it is cool and intuitiv to use.
Discovery: It appears that a longer offset results in smaller images, probably because the actual image has to be placed inside a smaller friction of the circle.
I will address:
make clean
. The files should just be overwritten if they exist, and I would think that others that exist for different sizes/names from previous conversions should stay in /styles.I was asked to enter the name
I don’t understand the benefit in this. I move to go back to finding the 1 file, just print it out with something like "Found the following source image file: " $source
, then process it.
A lengthy name is a pain to type and/or need to copy/paste in, it’s already checking for zero or more than one file existing, and the instructions are pretty simple: Have only one file in the folder.
I understand why you positioned them the way you did (1-3 for Presets 1-3), but in case someone has more presets, manipulating this so height-only and custom remain at the bottom might get more complex instead of just adding one more line to it.
If you’re going to be manually editing the script to add more presets, the way it’s written, there’s nothing preventing you from just adding more single line preset options starting at 6, or even moving current 4&5 down the list and insert your new presets above them.
I would therefore recommend not naming the unit and place somewhere "units for blade LENGTH and offset need to be in identical unit10
I can’t input 100 (cm) for either question 2 nor 3
That’s because I was in inches world and a hilt longer than 99 inches seemed unlikely, hence the 2 digit limit. Easily changed.
using 999, 99, 99 took really long
might be a good idea to limit the input?
a limit is ok, but what number? Some people have 264 KR Pixel Strips or zig-zag quad blades. Would 400 be reasonable?
prevent zero entries/ too small value: setting minimums should work, but what values are reasonable? HEIGHT min 10? The others?
i’d like the resulting image*.h files to inform me of what I did, namely having the name of my source image and the height inside the name. for sorting reasons that could look like [name] pov [height]_[colors].png
I also think the resulting names should be more descriptive, taking the basename of the source, appending the chosen HEIGHT value and also FC, SC, or 8b.
I’ll edit Makefile and propose changes via PR once it’s tested. (already tested )
it would also be nice, if in the readme there would be further information, like recommendations for inputs
That’s fine too, but what ARE the recommendations?
See, even as I’m do this, I’m still confused why we need to ever enter custom width and offset.
I feel as an end user, it just makes things unnecessarily complicated.
If setting only HEIGHT generates an good image in proper ratio…remind me again why the need for the other inputs?
I think my confusion is coming from the 144 value. That’s based on pixel count in my mind, and early on when asking about this, I came to understand the purpose for resizing at all was to accommodate shorter blades for less scaling and better image quality.
So…it’s NOT the blade length in pixels?
I would think a user just want to say “ok, I have a 123 pixel blade, my height is 123, GO.”
offset needs to be identical unit… I think we need to make some assumptions that anyone using this would likely use the same units of measurements for all 3 entries.
using 30, 10, 99 worked, but distorted the image
This one is kind of weird… wonder what caused that?
Editing this script as per notes from initial test above.
What should the questions be for height length and offset if they’re not blade, hilt, armature?
I was going off of this, to which @profezzorn replied “That is correct”
So
height
would be the Pixel amount and blade length,length
the hilt length andoffset
anything else from shoulder/ellbow/wrist what the user wants to be his center point when swinging?
If requesting input using just the variables themselves such as “Height?” there’s no reference to what it is.
Again, partially why I don’t understand this is the why it’s needed to customize length and offset in the first place.
Your script could just assume that people are using 144 LED/m strips, since they are by far the most common and then calculate he length of the blade from that. Then the only remaining question is the distance from the fulcrum to the bottom of the blade (offset). Not sure how to phrase that in a concise way though…
Maybe the script should be like:
How many pixels are in your blade? (144)
How long is your blade? (XX inches)
How long is your arm? (18 inches)
Where (XX) is calculated from the number of pixels, and if you press enter, you just get the value in the parenthesis.
Where (XX) is calculated from the number of pixels
Could I have an assist on that math please? In code form, not blackboard
Like, I get 1 meter = about 39". Thats 3.69 leds per inch. at 36" that should be around 133 leds.
but… in non-unit not sure how to universalize.
Ok, I had this all typed out then lost it grrr.
Script has been edited as per notes from initial test above.
Makefile edited as well to work along with it.
make clean
and delete any file containing preview. However, data files are not deleted, as they will either get overwritten with subsequent conversions, or remain for future useMake POV images for ProffieOS. Contribute to NoSloppy/EZ-POV development by creating an account on GitHub.
Makefile
ALL: image.h image_pgm.h image_8bit.h preview.png
IMAGE=1024px-Star_Wars_Logo.svg.png
OPTIONS=
image.h: pnmtorle pnmwindshieldwiper $(IMAGE)
anytopnm $(IMAGE) | ./pnmwindshieldwiper $(OPTIONS) | pnmscale -reduce 10 | ./pnmtorle >../styles/$(basename $(IMAGE))_$(HEIGHT)_FC_POV_data.h $(info Full color image is named: $(basename $(IMAGE))_$(HEIGHT)_FC_POV_data.h)
image_pgm.h: pgmtorle pnmwindshieldwiper $(IMAGE)
anytopnm $(IMAGE) | ./pnmwindshieldwiper $(OPTIONS) | pnmscale -reduce 10 | ./pgmtorle >../styles/$(basename $(IMAGE))_$(HEIGHT)_SC_POV_data.h
image_8bit.h: pnmquantizedtorle pnmwindshieldwiper $(IMAGE)
anytopnm $(IMAGE) | ./pnmwindshieldwiper $(OPTIONS) | pnmscale -reduce 10 | pnmquant 256 | ./pnmquantizedtorle > ../styles/$(basename $(IMAGE))_$(HEIGHT)_8b_POV_data.h
preview.png: pnmwindshieldwiper $(IMAGE)
anytopnm $(IMAGE) | ./pnmwindshieldwiper $(OPTIONS) | pnmscale -reduce 10 | pnmquant 256 | pnmtopng >$(basename $(IMAGE))_$(HEIGHT)_preview.png
pnmtorle: pnmtorle.cc common.h rle.h
g++ -O2 pnmtorle.cc -o pnmtorle -g -lm
pgmtorle: pgmtorle.cc common.h rle.h
g++ -O2 pgmtorle.cc -o pgmtorle -g -lm
pnmquantizedtorle: pnmquantizedtorle.cc common.h rle.h
g++ -O2 pnmquantizedtorle.cc -o pnmquantizedtorle -g -lm
pnmwindshieldwiper: pnmwindshieldwiper.cc common.h
g++ -O2 pnmwindshieldwiper.cc -o pnmwindshieldwiper -g -lm
1024px-Star_Wars_Logo.svg.png:
wget https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1024px-Star_Wars_Logo.svg.png
clean:
rm *preview*.png
create_POV_data_files script (LINE 130 is where math needs to happen)
#!/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;;
5) valid_option=1;;
# 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 5, ENTER for default 144) " height
if [[ $height == "" ]]; then height=144 length=36 offset=18 validinput=1
elif [[ $height == "q" ]]; then exit
elif [[ $height -lt 5 ]]; then
echo "! Minimum length is 5, 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
# do some math here with $height to calculate length and give it to calc_len
fi
done
if [ $height_only != 1 ]; then
validinput=0
while [ "$validinput" != "1" ]
do
read -p "How long is your blade? (min 5, ENTER for default ($ calc_len goes here) " 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 18) " offset
if [[ $offset == "" ]]; then offset=18 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