Line tracing

Jim Hurley jhurley at infostations.com
Sat Feb 1 07:42:01 EST 2003


>Roger Guay Wrote:
>
>Sarah, Jim
>
>What I'm trying to do is trace a line in time as a ball is moved across
>the screen.  Near as I can tell, I want the screen to update but not
>redraw (if that makes any sense?)  I've done this in ToolBook on the PC
>but I much prefer to stay on my Mac.  Here is a description of my stack:
>
>Create a vertical line and label it "Yaxis" and an horizontal line and
>Label it  "Xaxis" such that they intersect and define the origin 
>somewhere near the lower left corner of your stack.  Create a brightly
>colored circle graphic and name it "Ball."  Create 2 fields, one for
>Theta so labeled which defines the angle from the horizon that the ball
>is being fired, and one for V so labeled which defines the velocity of
>the ball when fired.  Create a "Fire" button and insert the following
>script:
>
>on MouseUp
>    global V, Xo, Yo, Theta, T, X
>    --put item 1 of the rect of graphic "Yaxis" into  Xo.  Yaxis is a
>vertical line and Xo,Yo define the origin of motion
>    --put item 4 of the rect of graphic "Yaxis" into  Yo.
>    put field "V" into V    ---- try a value of about 27 in field "V"
>    Put the value of field "Theta" into Theta  ----try a value of 1.2 in
>field "Theta"
>    set the loc of graphic "mortor" to Xo,Yo   ---- Graphic "mortor" is a
>small red round ball.
>    show graphic "mortor"
>    put 0 into T
>    put xo into x
>    put Yo into y
>    play "Mortor.aiff"
>    repeat while Y <= Yo + 1
>      add 1 to T
>      put the value of (Xo+V*cos(Theta)*T     ) into x
>      put the value of (Yo - V*sin(Theta)*T + .5*T^2  ) into Y
>      set the loc of graphic "mortor" to X,Y
>      wait 1
>    end repeat
>	----------  the rest of the script results in a silly explosion at the
>last location of the mortor -------
>    play  "Boom.aiff"
>    hide graphic "mortor"
>    set the loc of graphic "Burst" to x,Yo
>    repeat 35
>      show graphic "burst"
>      wait 1
>      hide graphic "burst"
>      wait 1
>    end repeat
>end MouseUp
>
>
>
>Jim has actually provided a solution for me that works well if I insert
>"wait .01" in his repeat loops.  I can only assume it has something to
>do with processing speed of the computer (I'm using a high end iMac
>with OS X.)  Without the "wait" command in the repeat loop, Jim's
>scripts are very choppy on my computer.
>
>Finally, as I say, Jim's solution works well but I think it would
>nevertheless be more "elegant" to do this as I have in ToolBook where
>one is able to stop the screen redraw.
>
>Thanks very much for joining in the fun, Roger
>

Roger,

I think I see the problem. It is not a difficulty with refreshing the 
screen but the very large sampling times in the  trajectory 
equations. If you  change "add 1 to T" to "add .05 to T" you  will 
get a much smoother motion.  At least it does on my PowerBook running 
OS 8.6

But I thought you wanted a line drawn in the  wake of the graphic  motion?

I couldn't try your sound effects. They should add a nice touch to 
the visual. I have seen discussions on this list of problems with 
sound effects timing; that could be a conflict for you. I can't help 
you there.

You  will find a number of these problems in dynamics illustrated in 
the demo on the RR web site on the Education page including  the 
projectile motion you are working on as well as planetary motion, 
Kepler's 2nd law (planets sweep out equal areas in equal times), the 
voyager sling shot effect as it moved around Jupiter and others. The 
graphic I use there is the turtle, which I represent with an arrow 
icon, which allows me to show heading as well as position. But it is 
easily modified to move any one or more RR controls (buttons, fields, 
graphics, images, etc.). You have the option of leaving a line in the 
turtle's wake or not.

Good luck with  your project. The sound  effects are  a nice touch.

Jim



More information about the use-livecode mailing list