Skip to content

Instantly share code, notes, and snippets.

@shurane
Last active December 15, 2015 20:58
Show Gist options
  • Save shurane/5322127 to your computer and use it in GitHub Desktop.
Save shurane/5322127 to your computer and use it in GitHub Desktop.
First in a series of NetLogo/Logo lessons. This should take approximately 1 hour. After going through the experiments, the students should be allowed to experiment making whatever shapes that they feel like. Perhaps challenging each other to make more bizarre shapes.

lesson1: Turtling.

With NetLogo open and the Interface tab selected, try out the following in the Command Center:

This is how you make a turtle:

create-turtles 1

We are going to ask our turtles to draw underneath them as they move.

ask turtles [ pendown ]

Now let's ask the turtle to move forward 5 steps and then turn right 60 degrees. I hope you guys remember your shapes. It's especially useful if you remember how big the angles of the shape are.

ask turtles [ forward 5 ]
ask turtles [ right 60 ]

We can combine the 2 instructions to one line as follows.

ask turtles [ forward 5 right 60 ]

Alright, why don't we tell this turtle to repeat this 3 more times?

ask turtles [repeat 3 [forward 5 right 60 ]]

It looks like we almost have a shape. What shape does this look like? Why don't we complete the shape? What instructions do we need to give to complete the shape?

Note: if you make a mistake by giving the wrong instruction to the turtle, you can reset and start again by running: clear-all

We can also tell the turtle to move backwards and to the left. ask turtles [ left 60 ] ask turtles [ back 4 ]

Okay, now let's clean up that mess we drew. This time we will create 2 turtles. clear-all create-turtles 2

Do you notice where the 2 turtles are? They are right on top of each other. Why don't we ask them to move?

ask turtles [ pendown ]
ask turtles [ forward 5 ]
ask turtles [ right 180 ]

But what if we don't want them on top of each other? Okay, let's try this again:

clear-all
create-turtles 2 [setxy random-xcor random-ycor ]

Where are the turtles? Try running that command again.

clear-all
create-turtles 2 [setxy random-xcor random-ycor ]

Okay, now we made our turtles, let's tell them to move exactly like before.

ask turtles [ pendown ]
ask turtles [ forward 5 ]
ask turtles [ right 60 ]
ask turtles repeat 5 [ forward 5 right 60 ]

We can even keep telling the turtles to repeat. Something like:

clear-all
create-turtles 1 
ask turtles [ pendown ]
ask turtles [ repeat 6 [repeat 6 [ forward 5 right 60] right 60 ] ]

Exercises

  1. What kind of shape did you make?
  2. Now on to some exercises. Can you make:
    • triangle whose side is length 4
    • square whose side is length 4
    • rhombus whose side is length 4
    • a rectangle whose sides are 4 and 8
    • CHALLENGE: a five tipped star, like this picture
    • BONUS ROUND: a six tipped star, like this picture
    • CAN'T DO THIS: 4 squares inside a square, like this picture

Some neat pictures in NetLogo/Logo:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment