On the previous post, I touched about FORWARD and LEFT. Of course, with just FORWARD and LEFT won't do much. Here is a more complete list of syntax for controlling the turtle:
1. FORWARD
2. BACK
3. LEFT
4. RIGHT
5. PENUP
6. PENDOWN
7. HOME - move turtle back to center
8. CLEAN - clear the drawing space
PENUP and PENDOWN is used when we want to draw a dashed line or move the turtle to somewhere without leaving the trail. For example:
FORWARD 10
PENUP
FORWARD 10
PENDOWN
FORWARD 10
will produce the following result:

And to produce greater things, we have to use the powerful REPEAT.
Try the following code
REPEAT 10 [ FORWARD 100 LEFT 108 ]
and you will see this

With little creativity, we can produce greater result. Try the following code:
REPEAT 10 [
PENUP
LEFT 36
FORWARD 80
PENDOWN
REPEAT 10 [ FORWARD 50 LEFT 108 ]
PENUP
BACK 80]
and we will get

To draw a circle, use the following code:
REPEAT 360 [ FORWARD 1 RIGHT 1]
Have fun trying your own code!
0 comments:
Post a Comment