Table of Contents | Previous Page | Next PageCopyright Don Sleeth, 1998 ©
![]()
Page 11 - Cool Animation
Load in your work
- From the file menu, open your project named Page10. Then from the file menu select "Save Project As..." and save your project as Page11
In the procedures page, your program should look like this:
to DoJump Height local "OriginalY make "OriginalY ycor sety sum ycor thing "Height wait 1 sety thing "OriginalY end to Jump DoJump 30 end ========================== to Main cc talkto "t1 setshape [dog1 dog2] seth 270 repeat 200 [Walk 10 10] end ========================= to Start Main end to Walk StepSize QSteps repeat thing "QSteps [forward thing "StepSize wait 1] endBecome a master of illusions
- Programming often involves creating an illusion. Often you will want to make a creature appear to walk or jump. Actually all you do is move the turtle, change the shape, move the turtle, change the shape but to the user it looks like, it creates the illusion that the creature is walking.
If you are using Windows 95, take a close look at your screen, especially the edges of the windows. It really looks 3-dimensional doesn't it. It looks like the edge has some depth to it. But it is just an illusion. The screen is flat, 2 dimensional, it is just the careful use of light and dark colors to create the illusion of shadowing that makes the screen look three dimensional.
I want to make a program that makes it look like a creature is jumping over an obstacle. To do this we need to trigger the DoJump procedure. I am going to program a color to call DoJump and then plant that color in front of the obstacle. This will create the illusion that when the creature gets near the obstacle, it sees it and jumps over it!
Program a color
- MicroWorlds has a really cool and useful feature that allows you to program colors. You can program a procedure to be called if a turtle touches that color or a different procedure if the mouse clicks on that color. We will be using the turtle rule here.
Please go to your program page and switch to the drawing center. Click on the gray color. Your screen will look similar to the one below.
![]()
Here you see that you can put an instruction inside the dialog box that will be run when a turtle touches the gray color. There is a 'better' way to program a color where you don't have to use the dialog box at all, but we will learn that way at another time. The color Gray is an object, as is a turtle, and an object has properties. One of the properties of a color object is what procedure to call if a turtle hits that color. We haven't written the procedure yet, but we will fill in the property in the dialog box anyway. In the white area next to Turtle: type ColorGrayHit and click on OK. We will write this procedure in a second.
While you are in the Drawing Center and the Gray color is selected, click on the spray can and spray a grey splotch of color. Then switch back to the Command Center.
ColorGrayHit
- Ctrl-F to the Procedures page and we will program the color Gray to call DoJump. Write the procedure ColorGrayHit as follows
to ColorGrayHit DoJump 50 endNow Ctrl-F back to the program page and click on the Start button. Make sure your dog hits the gray splotch. Isn't that neat? My little Dog jumps up and down a few times in the gray and then continues on its way.
Jump a pond
- Let's put a pond for the dog to jump over. You do this by hatching another turtle and placing him where you want the pond. Then you go to the Shape Center and click on the Pond, then the Turtle. Here is my screen.
![]()
Try the program. Pretty good, but we have two problems to fix. One is that it would be much better if the dog jumped forward, and with one jump cleared the pond. The other problem, which wouldn't be as noticable if we fixed problem one, is that the dog disappears behind the pond, it would look better if the dog were in front of the pond. Let's fix the second problem first. Oh, and one more thing, you can delete the Jump button as it was only a temporary thing, used to help us test our procedure.
Who's on first?
- In MicroWorlds, the most recently hatched turtle goes in front of any other turtles. Also the turtles are automatically named t1, t2 and so on. In our case, this is not the order we want. The only way I know of changing this is to just accept it and change turtles. In other words, we will make our dog t2 and our pond t1.
On the program page, drag the t2/pond out of the way and drag the t1/dog into the middle of the gray splotch. Then go to the shapes center and be sure the pond is still selected then click on the t1/dog. This should now make the first turtle, t1, look like the pond. Now go to the procedures page. We need to change our talkto line so that we are now talking to t2. Change Main as shown:
to Main cc talkto "t2 setshape [dog1 dog2] seth 270 repeat 200 [Walk 10 10] endGive the program a try. There, that solves problem two, what do you think would be the way to solve problem one?Go the distance
- I think we need to either change our procedure DoJump or to make a different procedure that both jumps up and forward. I like the first option of revising our existing procedure DoJump and making it more flexible. We will try to make it so that it can be used both to jump up and down or to jump over something.
To jump over an object, the turtle needs to move up and also move forward a certain amount. We need a second input to DoJump so we can control how far forward the turtle should move while it is jumping. You should try revising your DoJump before looking at mine:
to DoJump Height Distance local "OriginalY make "OriginalY ycor sety sum ycor thing "Height wait 1 forward thing "Distance wait 1 sety thing "OriginalY end to ColorGrayHit DoJump 50 100 endIt works! Finally we have a great little procedure that can be used to make turtles jump over things. You should copy your DoJump procedure into your Library file.Fun with DoJump
- Before I end this page, let's have a little fun. Hatch another turtle and put it in line with your gray splotch. This turtle is automatically named 't3', you can check this by right-clicking on it.
I would like to use the skater shape, skater1, skater2 and skater3 at the same time as the Dog. You definitely should try to program this on your own before looking at mine, but don't spend too much time on it because there is a bit of information that we have not talked about yet. Which way did your skater go the first time you tried your soloution? Mine too! :-)
Here is my 'first try' which does not work right:
========================== to Main cc talkto "t2 setshape [dog1 dog2] seth 270 repeat 200 [Walk 10 10] talkto "t3 setshape [skater1 skater2 skater3] seth 90 repeat 200 [Walk 10 10] end ==========================When you try this program, you will see that the dog continues to do its thing properly, but the other turtle never moves. Change your Main as follows:
========================== to Main cc talkto "t2 setshape [dog1 dog2] seth 270 repeat 5 [Walk 10 10] talkto "t3 setshape [skater1 skater2 skater3] seth 90 repeat 200 [Walk 10 10] end ==========================Try it and let it run for a few minutes. First the dog correctly does its thing and then the skater does her thing. (Note: if your skater doesn't jump, change her back into a turtle and comment out the line in Main that sets her shape. You have to make sure that the turtle itself touches the gray splotch) If you follow the lines in Main, this makes sense. The repeat procedure causes the program to run the following list of instructions [Walk 10 10] over and over and then proceeds to the next line.What we really want is for a process to be launched making the dog walk and then for the program to continue to the next line and launch another process to make the skater walk, at the same time. This can be done using the built-in procedure launch. Launch has as an input a list of instructions to run as a separate process. Change your Main as follows
========================== to Main cc talkto "t2 setshape [dog1 dog2] seth 270 launch [ repeat 200 [Walk 10 10] ] talkto "t3 setshape [skater1 skater2 skater3] seth 90 launch [ repeat 200 [Walk 10 10] ] end ==========================There! Pretty cool, eh! Be sure to save your work. This program launches two processes that operate independently.
Who are you talking to?
- One more thing to notice about this program is that ColorGrayHit automatically seems to run the line talkto "WhatEverTurtleTouchedMe before it calls the procedure DoJump. This functionality is built-in to the MicroWorlds Logo language.
Exercise your skills
- Learning how to program is a bit like learning how to ride a bike. Your teacher can tell you how to do it, they can show you how to do it and you can read about it. But there is only one way to learn how and that is to do it. You have learned quite a few built-in procedures now and some programming techniques. Now you should consolidate your knowledge by actually putting these things to use.
I suggest you take the time to write several of your own procedures now. Even rewrite the same ones we have done. Do them over and over until you can do them totally without looking at the code here.
Make up your own little projects but don't let them get too complex and if you are banging in to a wall, ditch the project and do a different one. There are still lots of things you don't know about Logo and, in time, that wall will be dissolved.