Page 1 of 1

Bash Calculator Issue

Posted: 2009-07-21T16:31:57-07:00
by jsells20
I am using the bc command in my script but I cannot figure out how to integrate it into the filter. I have taken out the bc and the filter output is the same as it is with the bc command. I could really use some help here. I appreciate your time.

Code: Select all

count=$START
    SETSTEPS=$(echo "scale=2; 1/2" | bc)
    SETTING=$SETSTEPS
        while [ $count -le $END ]; 
        do
        echo $count

        #set for padding of 4 from 0-999.

        if [ $count -lt 10 ]; then 
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
        fi


        if [ $count -ge 10 ] && [ $count -le 99 ]; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
        fi

        if [ $count -ge 100 ] ; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
        fi

        SETTING=$(echo "scale=2; $SETTING+$SETSTEPS" | bc)
        echo "processing frame: "$count " setting is: " $SETTING "setsteps is " $SETSTEPS""

        let count=count+1
This is from the terminal. I want this math to integrate with the filter output of the image. Basically the image goes lighter to darker over time, I want it to get darker at a slower rate. I know 1/2 wont do that but this is just an example.
processing frame: 0 setting is: 1.00 setsteps is .50
1
processing frame: 1 setting is: 1.50 setsteps is .50
2
processing frame: 2 setting is: 2.00 setsteps is .50
3
processing frame: 3 setting is: 2.50 setsteps is .50
4
processing frame: 4 setting is: 3.00 setsteps is .50
5
processing frame: 5 setting is: 3.50 setsteps is .50
6
processing frame: 6 setting is: 4.00 setsteps is .50
7
processing frame: 7 setting is: 4.50 setsteps is .50
8
processing frame: 8 setting is: 5.00 setsteps is .50
9
processing frame: 9 setting is: 5.50 setsteps is .50
10
processing frame: 10 setting is: 6.00 setsteps is .50

Re: Bash Calculator Issue

Posted: 2009-07-21T16:41:50-07:00
by anthony
Your use of bc is fine! But......
You don't use $SETTING in the script!




As an alternative to bc, you can also use IM. Through its a little slower :-)

SETTING=$( convert null: -format "%[fx:$SETTING+$SETSTEPS]" info: )

See IM Examples, Image Transforms,
FX Expressions as Format and Annotate Escapes
http://www.imagemagick.org/Usage/transform/#fx_escapes

Further down that page goes into using images as arrays of 'fixed point' variables that you can do mathematics on!

Re: Bash Calculator Issue

Posted: 2009-07-21T17:21:03-07:00
by jsells20
Ok, I ran that and no errors, but I still cannot tell a difference in the filter. I replaced...

Code: Select all

SETTING=$(echo "scale=2; $SETTING+$SETSTEPS" | bc)
with

Code: Select all

SETTING=$( convert null: -format "%[fx:$SETTING+$SETSTEPS]" info: )

Related to bc though do you know what im missing why SETTING is not included?

Re: Bash Calculator Issue

Posted: 2009-07-21T17:35:24-07:00
by anthony
You just did not use it in any of the convert commands!!!

You used $count instead!!!!

Re: Bash Calculator Issue

Posted: 2009-07-22T12:37:36-07:00
by jsells20
oops, forgot to change that. Well everything works now. I guess the charcoal filter only changes by integer values, but this will still slow down the speed in which it takes to get dark. Thanks.

Re: Bash Calculator Issue

Posted: 2009-07-22T18:14:57-07:00
by anthony
In an animation change the delay to slow it down. You can remove duplicate frames (whcih also merges animation time delays) using -layers RemoveDups

See Animation Optimization...
http://www.imagemagick.org/Usage/anim_opt/#removedups