Climbing Turtles

Declaring State

The state of a patch is its elevation (as well as the pre-declared state):

patches-own [elevation]
globals [max-elevation min-elevation]

The altitude function will be used to compute the elevation of the patch at location (xc, yc):

to-report altitude [xc yc] 
  report 5000 - (xc * xc + yc * yc) ; = 5000 - xc^2 - yc^2
end

Initialization

to init
   ca
   init-patches
   init-turtles
end

The turtles are initialized with random headings and positions:

to init-turtles
   crt 20
   ask turtles [set heading random 360 fd random screen-edge-x]
end

After initializing the elevation of the center point of each patch, the edges are smoothed by applying the diffuse procedure five times. Finally, the color of each patch is shaded so that lighter shades correspond to higher elevations:

to init-patches
   ask patches [set elevation altitude pxcor pycor]
   repeat 5 [diffuse elevation 1]
   set max-elevation max values-from patches [elevation]
   set min-elevation min values-from patches [elevation]
   ask patches [set pcolor scale-color green elevation
      min-elevation max-elevation]
end

Climbing

to update
  ask turtles [update-turtle] ; patches don't need to be updated
end

On each update cycle a turtle moves one step in the uphill direction:

to update-turtle
   set heading uphill elevation
   if ( elevation-of patch-ahead 1 > elevation ) [ fd 1 ]
end

Running the program

Before

After

Elaborating

Here's a screen shot of a slightly more elaborate version of the program: