Notes for IntroCS

Creating/Using Backgrounds:

You have 2 options to create useful or colorful backgrounds for your projects:

A) importing a picture into the "drawing layer" from a JPEG or GIF or PNG type file
or
B) importing a picture into the patches from a JPEG, GIF or PNG file.
Here are the advantages/drawbacks of each:

A) Assume you have a nice picture in the file: "fred.jpg" which is located in the same directory as your .nlogo file.  At any time, you can execute the command:
  import-drawing "fred.jpg"
and this will write the image into the "drawing-layer" of the netlogo canvas.  That's the layer that lives above the patches and below the turtles, and which the turtle's pen draws into and stamps into.
Advantage of A): Fast display, so you can import one image after another quickly (if you need to do that).  Each image overwrites the previous image.
Disadvantage of A): When there's an image in the drawing-layer, the patches cannot be seen because they are below the drawing layer.  Also, a turtle on the screen cannot "see" the colors below it in the drawing-layer the way that a turtle can "see" the pcolor of a patch below it.

If you want to play with importing images to the drawing-layer, create a button that exectures the following procedure:

  to show-image
    cd
    let f user-file
    if f != false [
      import-drawing f
    ]
  end


B) Once more, assume you have "fred.jpg" around.  To import into the patches, you execute:
  import-pcolors "fred.jpg"
Advantage of B): Importing into the patches will allow turtles to "see" and modify the pcolors of the patches that have just been colored.  This is useful in a variety of situations -- for instance, in a maze game, if the picture of the maze is imported into the patches, and the walls are red, then a turtle can detect that it's on top of a wall by checking the pcolor of the patch it's on.
You can also create images to import into your patches by using Mr. Brooks's PatchPainter (right-click to download) program.
Disadvantage of B): If you want to import a photo, the image will be pixellated.  The larger your patches are, the more pixellated.  To reduce the pixellation, you might want to create a very large number of tiny patches -- but if so, the import-patches command may take a much longer time than import-drawing (you should try this).

If you want to play with importing images into the patches, change "import-drawing" to "import-pcolors" in the show-image code above.
Fri, 1/14:
We talked about turtle-turtle interaction using "turtles-here" and its variants:
- ask turtle 0 [ if count turtles-here > 0 [do something]]
- if any? other turtles-here ...
- turtles-here with [color = red] ...
Thurs, 1/13:
We talked about the final project:  3 Choices
- A) an animation -- smooth and at least 1 minute and interesting)
- B) a game -- must be playable, with adequate instructions and a decent possibility of winning and losing.
- C) a simuation -- must be a simulation of something real and must teach the average user something that they did not know.

We also talked about how to deal with the tail in Snake.  The finished version is lined to on the homepage.
Wed, 1/12:
- We talked about creating a PLAY button that moves the head (turtle) forward 1 step.
- We created the direction buttons to change the direction that the turtle moves.
- But we also prevented the player for mistakenly asking the snake to go in the direction opposite to the one it's currently going.  And added code to each turn procedure to prevent that.
- We then figured out that painted the patch under the turtle right after the turtle moves is a BAD idea.
- I then showed how to ask the observer to "unpress" a forever button using the STOP command.
Here's the current version (right-click to download.
Tues, 1/11:  

- We talked about turtles affecting patches.

- A turtle can change or examine any property of the patch it's on, simply by referring to that property.  For instance, a turtle can turn the pcolor of the patch it's on red by:
ask turtle 12 [set pcolor red]

- We started designing a Snake game.  Today's task (to be finished by tomorrow), was to code the Start button, which will clear everything, draw the borders, create a snake with a body of 4 patches and a head of a turtle, and place a food unit in a random place except on the border or the body of the snake.  Each class chose different colors for the border, snake and food.  The world should look like this.