Pages

Showing posts with label Netlogo Primitives. Show all posts
Showing posts with label Netlogo Primitives. Show all posts

Sunday, 10 November 2013

Primitives "show", "print", "write", and "type" in NetLogo

show

show value

Prints value in the Command Center, preceded by this agent, and followed by a carriage return. (This agent is included to help you keep track of what agents are producing which lines of output.) Also, all strings have their quotes included similar to write.

print

print value

Prints value in the Command Center, followed by a carriage return.
This agent is not printed before the value, unlike show.

write

write value

This command will output value, which can be a number, string, list, boolean, or nobody to the Command Center, not followed by a carriage return (unlike print and show).
This agent is not printed before the value, unlike show. Its output also includes quotes around strings and is prepended with a space.
write "hello world"
=>  "hello world"

type

type value

Prints value in the Command Center, not followed by a carriage return (unlike print and show). The lack of a carriage return allows you to print several values on the same line.
This agent is not printed before the value. unlike show.
type 3 type " " print 4
=> 3 4


From NetLogo User Manual

Saturday, 16 June 2012

Four Dealings with the Number in NetLogo: "round","precision", "ceiling", "floor" in NetLogo


  • round

round number
Reports the integer nearest to number.
If the decimal portion of number is exactly .5, the number is rounded in the positive direction.
show round 4.2
=> 4
show round 4.5
=> 5
show round -4.5
=> -4


  • precision

precision number places

Reports number rounded to places decimal places.
If places is negative, the rounding takes place to the left of the decimal point.
show precision 1.23456789 3
=> 1.235
show precision 3834 -3
=> 4000
  
  • ceiling

ceiling number

Reports the smallest integer greater than or equal to number.
show ceiling 4.5
=> 5
show ceiling -4.5
=> -4
  
  • floor

floor number

Reports the largest integer less than or equal to number.
show floor 4.5
=> 4
show floor -4.5
=> -5

Saturday, 24 March 2012

Differences between "forward/fd", "jump" and "move-to" in NetLogo

Their common points:
1.All can only be used on turtles;
2.All are for making turtles move.

Their differences:
1. "forward/fd" is followed by a number, which is the number of steps the turtle move forward. "jump" is followed by a number, which is the number of units (like step width) the turtle move forward. "move-to" is followed by a agent, whose position is the destination of moving. So, they control the number of steps, step width and destination of moving respectively.
2. "forward/fd" and "jump" do not change the direction of moving, so you need to set the direction first if you want the turtle to move toward a specific position. But the direction of "move-to" is determined automatically as you set the agent (destination).
3. "forward/fd" and "jump" are more similar and can be interexchanged easily. For example, "fd 6" = "repeat 6 [ jump 1 ]' and "fd 3.5" = "repeat 3 [ jump 1 ] jump 0.5".