Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Animating Multiple Turtles

Animating Multiple Turtles

Ratings: (0)|Views: 321|Likes:
Published by scribdmuthu

More info:

Published by: scribdmuthu on Jan 27, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Animating Multiple Turtles
Chapter 11. Animating Multiple Turtles
“Wow, working with one turtle was bad enough. Butworking with hundreds?“That’s worse than working with rabbits!”________________________________________________
Simulating Multiple Turtles
Yes, there are lots of turtles in MSW Logo, 1024 of them.You can animate them, change their shapes, add sound effects,and all sorts of things.But before you start getting busy with animating all thoseturtles, let’s take a look at how you can use just one turtle tosimulate multiple turtles that do lots of different things. It’s agreat review of things you’ve been doing up until now. And itwill give you some ideas for working with UCB Logo, whichonly has one turtle.The KALEIDOSCOPE procedure (KALEID.LGO)shows a good use of coordinate, color, and other commands.
Animating Multiple Turtles
The resulting picture looks as if it were drawn by multipleturtles.TO KALEID :ANG :CNTIF :CNT < 1 [STOP]SETPC (LIST (RANDOM 128)+128 (RANDOM 128) ~+128 (RANDOM 128)+128);Try SETPC RANDOM 16 with other LogosMOVEKALEID :ANG + 5 :CNT - 1ENDThe pen colors for red, green, and blue are set from 128 to255 (0 to 127 plus 128). You may recall that the higher thenumber, the lighter the color. The lighter pen colors go withthe darker screen colors set in the START procedure below.In that procedure, the colors are set randomly from 0 to 100to produce a darker screen color. TO STARTCS HTSETSC (LIST RANDOM 100 RANDOM 100 ~RANDOM 100);Try SETBG RANDOM 16 with other LogosKALEID 0 50WHATNOWENDIn the MOVE procedure, the turtle remembers it’scoordinates and then moves. The four simulated turtles eachmove in the four quadrants (the four quarters) of the screenbased on the (+) positive and (-) negative values assigned tothe X and Y variables.TO MOVE(LOCAL "X1 "Y1 "Y1 "Y2)MAKE "X1 XCOR
Animating Multiple Turtles
MAKE "Y1 YCORFD RANDOM 100 RT :ANG + 15MAKE "X2 XCORMAKE "Y2 YCORPU SETPOS (LIST (- :X1) :Y1) PDSETPOS (LIST (- :X2) :Y2)PU SETPOS (LIST (- :X1) (- :Y1)) PDSETPOS (LIST (- :X2) (- :Y2))PU SETPOS (LIST :X1 (- :Y1)) PDSETPOS (LIST :X2 (- :Y2))PU SETPOS (LIST :X2 :Y2) PDENDBelow is the MSW Logo procedure for running theprocedure again. It creates a typical Windows dialog boxwhere you can click on your response to run the kaleidoscopeagain or quit.TO WHATNOWCT MAKE "ANS YESNOBOX [AGAIN?] ~[RUN THE KALEIDOSCOPE AGAIN?]IFELSE :ANS = "TRUE [START][CT STOP]ENDTry this procedure with non-windows versions of thelanguage.TO WHATNOWCTPR [ANY KEY TO RUN IT AGAIN, ESC TOTERMINATE]IF RC = CHAR 27 [CT STOP] [START]ENDIf you press the Esc key — CHAR 27 — the text is clearedand the procedure stops. Any other key and the STARTprocedure is called.

Activity (3)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Farheen Khalid liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->