Lesson 1: Lines and Shapes


Open NetLogo and select the Interface tab. Select the textbox at the bottom of the Command Center to input commands. The two sections are highlighted in red.

placeholder

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 ]
      

We can also ask the turtles to change their shape or size.

ask turtles [ set size 5 ]
      ask turtles [ set shape "square" ]
      ask turtles [ set shape "bug" ]
      

To see a list of shapes, you can run show shapes


Let's see what we have so far:

placeholder

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 ]
      

Your turtle should look like this:

placeholder

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 the last instruction 3 more times?

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

Why don't we look at what we have so far?

placeholder

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 even keep telling the turtles to repeat what they're repeating. Something like:

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

You should get something like this.

placeholder

Very pretty, isn't it?

Whoa, what just happened? Why don't we watch that again in slow motion. Move the slider near the top to slow down the speed. Currently it's at normal speed, but if we move it to the left, we can make it slower.

placeholder

Now slower...

placeholder

We can also make it faster. This is useful later when we have very slow animations.

placeholder

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 ]
      

So what's happening? We're giving all the turtles the same set of instructions. So in this case, both turtles are moving, even though they are in different places. Why don't you try the above code for 3 turtles? Or 5 turtles? Or more?

clear-all
      create-turtles 10 [setxy random-xcor random-ycor ]
      ask turtles [ pendown ]
      ask turtles [ forward 5 ]
      ask turtles [ right 60 ]
      ask turtles repeat 5 [ forward 5 right 60 ]
      

Time for some Exercises


Can you make the following shapes?

a triangle whose side is length 4

placeholder

a square whose side is length 4

placeholder

a rhombus whose side is length 4 and with angles of 120 degrees and 60 degrees

placeholder

a rectangle whose sides are 4 and 8

placeholder

Extras!

CHALLENGE: a five tipped star.

placeholder

BONUS ROUND: a six tipped star.

placeholder

CAN'T DO THIS: 4 squares inside a square

placeholder

ONE STEP FURTHER: 16 squares inside a square

placeholder

Check out some of the other interesting designs you can do using Logo.