min-pxcor

 

min-pxcor reports the pxcor of the leftmost patches in a model. This primitive, and its siblings max-pxcor, max-pycor, min-pycor, are very useful in modeling the agent behavior that involves the boundaries of an environment. For example, if we wanted to build a model where we had a wall at the edges, we would write the following code:

ask patches [
    if pxcor = max-pxcor or
       pxcor = min-pxcor or
       pycor = max-pycor or
       pycor = min-pycor [
            set pcolor gray
       ]
]

Or if we wanted turtles to not walk beyond the world's borders, we would write the following code:

ask turtles [
    if [pxcor] of patch-ahead 1 < min-pxcor [
        forward 1
    ] 
]

Things to keep in mind when using min-pxcor:

In the model example below, we use min-pxcor and its siblings to create walls that represent a container. The balls inside the container bounce off of the green wall but they stick to the red wall.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the min-pxcor primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the min-pxcor primitive:
 
 
Similar primitives:
max-pxcor

Reports the largest x-coordinate of the patches in a model.

Read more
max-pycor

Reports the largest y-coordinate of the patches in a model.

Read more
move-to

Moves a turtle to set its x and y coordinates to be the same as another turtle or patch.

Read more
setxy

Moves a turtle to the exact location defined by the provided x and y coordinates.

Read more
 
Learn another primitive: