clear-patches

 

clear-patches is a primitive that resets all the patches at once. It makes the values of the custom patch variables (defined with the patches-own primitive) to their default initial values and makes all the patches black. You can also use its shorthand version cp in your code.

clear-patches is only used when we do not want to use clear-all. For example, if we wanted to clear the patches but keep some global variables’ values and the existing turtles the same, we would use clear-patches.

In the model example below, we have three buttons. The first one makes the patches' color green and creates some cows on random locations. The second button runs the clear-patches primitive to clear the patches, as a proxy for grass, but leaves the cows the same. The third button runs the clear-turtles primitive to remove the cows from the model but leave the patches/grass as is.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the clear-patches primitive:
 
 
Similar primitives:
clear-all

Clears all the drawings, turtles, plots, etc., leaving a blank slate.

Read more
clear-turtles

Removes all the turtles as well as resets the numbering of turtles.

Read more
die

Removes a turtle or link from the world.

Read more
reset-ticks

Sets the tick counter to 0.

Read more
 
Learn another primitive: