Moving Turtles

Here are some commands you can do with turtles:

fd numberbk number or forward number,  backward number
Turtles move forward or backward by 'number' of steps at a given time. A negative value can be assigned but this causes the turtle to move in a reverse direction.

lt numberrt number or left number,  right number
Turtles turn left or right by 'number of degrees'. Left and right commands will change the heading of the turtle . Like forward and backward commands, a negative value can be assigned but this causes the turtle to turn in a reverse direction.

pd number or pen-down number
If a turtle's pen is set to down, it will draw lines whenever it moves around. The pen color is similar with the turtle's color, to change the color of the pen, you have to change its color.

repeat number [ commands ]
This control structure will repeatedly execute set of commands enclosed in brackets.

setxy xcor-value ycor-value
To set a turtle's position, coordinates must be specified after setxy command, which can also be done separately by using set xcor xcor-value and set ycor ycor-value.

clear-all
This observer command resets everything in the world.

ask agent [ commands ] or ask agentset [ commands ]
This is an observer command to tell agents or agentset to execute the commands specified within the brackets.


With the commands above, you can create a procedure that move turtles from patch to patch. It can also be used to draw repetitive actions and create patterns.
Drawing shapes using basic turtle commands

Code Sample for Triangle

to start
clear-all
crt 1[
  set size 1
  set heading 0
  setxy -8 3
  set color yellow
   
end

to draw
repeat 3[
  ask turtles[
   pd
   rt 120
   fd 5
 ]
]
end

Trivia: How do you create a circle with the given code above? 

Share on Google Plus

About SSabal

:)
    Blogger Comment
    Facebook Comment

1 comments:

  1. I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work. moving companies in studio city

    ReplyDelete