Function Newbie question...

erik hansen erikhans08 at yahoo.com
Sat Dec 7 19:50:01 EST 2002


--- Jim Hurley <jhurley at infostations.com> wrote:

> Eric, there is a function "distance" in Turtle
> Graphics but it 
> relates to the  distance between the current
> location of the turtle 
> (cursor element) and some chosen point.  For
> example, if the turtle 
> were at the origin (center of the screen), the
> function 
> "distance(30,40)" would return 50--the
> hypotenuse of a right triangle 
> whose legs are 30, 40  is 50.
> 
> In some versions of TG there are multiple
> turtles--called sprites. 
> And so in a game with multiple, moving objects,
> one would need a 
> function to determine distance between each of
> the turtles.
> 
> The very basics in TG might be the following
> set of commands and 
> functions, which I hope are self explanatory:
> 
> Commands:
> forward 100
> back 100
> right 30
> left 30
> setHeading 45
> setXY 30,40
> incXY 3,4 --increment the x and y  coordinates
> 
> Functions:
> xCor()
> yCor()
> heading ( )
> distance (xTemp, yTemp)
> 
> This is all quite simple to implement in
> Transcript. But the beauty 
> of TG, like Transcript itself, is that it is
> extensible.
> 
> I know that RunRev is looking eventually to
> expand its market in 
> education. When it does, I think it will be
> helpful to include 
> examples of how Transcript and Turtle Graphics
> might be employed by 
> students as problem solving tools. For example,
> with sufficient 
> background, the students would write their own
> program to simulate 
> planetary motion using only the TG defined
> above:
> 
> constant G = 8000
> 
> on orbitTheSun
>    forward 90 -- Move the plant 90 units from
> the sun
>    put 0 into vx -- Initial horizontal velocity
> of planet
>    put 12 into vy -- Initial vertical velocity
> of planet
> 
>    repeat until mouseClick() -- My apologies
> for polling the mouse.
>      incXY vx, vy -- Move the turtle (planet) a
> distance v 
> (distance/second) in each second
>      add accx() to vx
>      add accy() to vy
>    end repeat
> 
> end orbitTheSun
> 
> function accx
>    -- Newton's inverse square law of gravity
>    return -G * xcor()/ distance(0,0)^3 -- The
> sun is at 0,0
> end accx
> 
> function accy
>    return -G * ycor()/ distance(0,0)^3
> end accy
> 
> The result is an ellipse.
> 
> The emphasis would not necessarily be
> programing for its own sake, 
> but for programing (Transcript + TG) as a
> problem solving tool in a 
> variety of disciplines--in fact, getting back
> to the original 
> function of programming.
> 
> Sorry Eric: That's probably a lot more than
> your wanted to know about 
> the distance function.

just right in fact. wasn't there something about
a bouncing ball? anyway, as soon as i get
converted to RunRev, there are some dancers
("sprites") that i am now moving around linearly,
but want to eventually move parabolicly. the
funny thing is that the danceSprites <appear> to
move in a curvaceous fashion.

=====
erik at erikhansen.org    http://www.erikhansen.org

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the Use-livecode mailing list