[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Re: Multi-Turtle programming.



Dear Yehuda,
I'm not sure the following will suit your future Math teachers, but 
I think it'll at least bring some pleasure for you (if you haven't 
found this solution yet by yourself).

Some time ago somebody, I don't remember who, sorry, posted a 
nice code for a mouse chasing the other drunk one. I've posted then 
the MSWLogo version of it. The same idea used for "Ant problem", 
where four ants, initially placed in the corners of the square and 
looking inside it,  begin to chase each it's "left" neighbour, leads 
to a rather amusing picture.

------ Ant Problem ----------
to ant.main
cs
set
move
end

to set
setturtle 0 st 
pu setxy -100 -100 pd label "0
setturtle 1 st 
pu setxy -100 100 pd label "1
setturtle 2 st 
pu setxy 100 100 pd label "2
setturtle 3 st 
pu setxy 100 -100 pd label "3
end

to dx
setturtle 0
localmake "x1 first pos
setturtle 2
localmake "x2 first pos
op :x1-:x2
end

to move
if (abs dx)<2 [stop]
for [i 0 3][setturtle remainder :i+1 4
            make "direction pos
            setturtle :i
            seth towards :direction fd 3]
move
end
--------------------------------------------

-------Chasing Mouse-------------------
to chase
set
drunk.sober
end

to set
cs
setturtle 0 st pu setxy -310 100 seth 90
setturtle 1  st pu setxy -340 0 seth 90
end

to drunk.sober
setturtle 0
fd 6 seth  -30+random 240
make "a pos
; drunk turtle moves off at speed 5 vaguely heading East
setturtle 1
seth towards :a fd 3
; sober turtle moves off at speed 3 with drunk firmly in sights
wait 1
drunk.sober
; recursive line
end
---------------------------------------

Regards,
Olga.





---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home