StarLogo Tutorial for Runners and Non-Computer Scientists

home

Overview

This is a tutorial for learning programming in StarLogo. StarLogo is a simple computer language developed by people in MIT. It is considered to be a good language to teach humans how to program.

Our approach is as follows. On this page you the find a pedagogically structured set of programs from very simple game-like to more complex to few that are useful applications.

In the program, a line that starts with ;; is a StarLogo comment. The computer does nothing with comments - their purpose is to give information and hints to the human reader. The programs contain lots of "learning" comments to guide the user studying the programs. Although real life programs do have comments, in this tutorial I have more comments than would be used in real life to help the student to understand the material.

This tutorial is using unique pedagogical approach -- “learn by running”.

How to Use this Tutorial

Each of the programs is an independent lesson. You should start with lesson 1 (sayHelloOnce1) program. After you complete lesson 1, go to the next lesson. The lessons are ordered in by the level of complexity from easy to hard.

(1) Read and try to understand the program. The understanding will not be complete which is why the student need to do the other steps.

(2) Start StarLogo and type in the program exactly as here. Think.

(3) Execute the program. This will add additional degree of understanding what the instructions do. Think.

(4) Based on your understanding, write your own version of the program. This step will need to be repeated few times or many times depending on the student. If you can write the program by yourself without looking at my program, you understand that lesson, and you can continue with the next lesson. Think.

Programming is just like running. First you run around the track once. If you make one lap, and do that many times, eventually you can two laps, four laps, ... and finally you can run the Biggest Race in the US, the Bay to Breakers, or DSE Dipsea.

There are many kinds of programs we can write. Here we will show three different kinds of basic programs.

Some of these programs only draw a geometrical pattern (square, rectangle), some perform some computation (add numbers from 1 to 100), and some print some text (print hello).

Although these programs are very simple, most real programs are some combination of these basic concepts.


Section: Extreme Basic:

These programs are written in the style that I want you to follow.

They contain header, and comments inside the program which are used to explain to the user of this program what do the different parts of the program do.


Note blank lines separating parts of the program for clarity.

sayHelloOnce1 //This prints "hello". (one lap)

multiplier1 //This multiplies two numbers and prints result. (two laps)

simpleSquare2 //This draws a simple square by making turtle walk and leave a trail. (three laps)

Section: Basic:

These programs use the repeat command. The repeat command is very useful, although here it is just simple exercise. Computers are good at repetitive tasks, they don't make mistakes, and don't get tired unlike humans.

sayHelloRepeat1 //This prints multiple hellos using the repeat cmd. Here is an example where we can make computer to say “hello” 1000 times. (1k)

sayHelloWithCount //This prints multiple hellos, but also counts the “hellos”. (2k)

twoSquareTouching1 //This draws Siamese squares connected at their corners. (5k)

Section: Programs that compute something useful:

In this section you will see programs that do something useful. Read them and understand them, and try to program them on your own.

squarePerimeter1 //This makes turtle to walk a square and compute perimeter. (10k)

computePowers1 //This computes the powers of 2 from 1 to n. (12k)

decider2 //This program takes a number from the user and decides if the number is big or small. And prints out its opinion. (half-marathon)

Section: difficult (not really):

This program has a lots of explanations in form of comments. In real life you would not use this many comments.

Look at the other programs for guidance on comments style.

This program will take as input dimensions of a room, and cost of tile per sq meter, and compute the total cost of tiling a room.

This program does real computation you may need in your house.

TileCostComputer (marathon)