change a patch attribute within concentric circles

BehaviourComposer: ignore everything before this.
Begin micro-behaviour:
Begin description:
change a patch attribute within concentric circles
End description

make concentric circles

Begin NetLogo code:
substitute-text-area-for text-area-center-x-coordinate 2
substitute-text-area-for text-area-center-y-coordinate 3
substitute-text-area-for text-area-radius 7
substitute-text-area-for text-area-radius-increment 1
substitute-text-area-for text-area-attribute-name pcolor
substitute-text-area-for text-area-attribute-value 21
substitute-text-area-for text-area-attribute-increment 1
substitute-text-area-for text-area-multiplier 1 

let x                   text-area-center-x-coordinate ; position circle on x-axis
let y                   text-area-center-y-coordinate ; position circle on y-axis
; give circle a radius (this will also be the number of cycles unless you change the  multiplier:
let radius              text-area-radius 
let radius-increment    text-area-radius-increment ; set how much the radius decreases each cycle
let value               text-area-attribute-value ; set the initial value of the patch attribute
let attribute-increment text-area-attribute-increment ; set how much the attribute value changes each cycle
; set number of times radius decreases using the factor: multiplier * radius ( must be more than 0 and less than 1):
let multiplier          text-area-multiplier
let cycles (radius * multiplier) ; number of times radius decreases

set xcor x 
set ycor y
let index 1
repeat cycles [
   ask patches in-radius radius [
     let new-value ( value + ( attribute-increment * index ))
     set text-area-attribute-name new-value ; the patch attribute you want to change e.g. using yyy-of-the-patch
     set plabel new-value
   set radius ( radius - radius-increment )
   set index ( index + 1 )
End NetLogo code

How this works

This image was taken from a model where this micro-behaviour (MB) is added three times to a prototype (which is made invisible to hide the agent). 

This MB uses the NetLogo in-radius primitive to change a patch specific attribute within a circular area with a defined radius. The attribute values are first changed for all the patches in the circular area of the intial radius value, then the code repeats through incrementally decreasing the radius of the circle to change the patch attributes an ever smaller circular area. 

This MB is very flexible, you can set the position of the center of the circle, the initial radius, the rate at which the circle radius decreases and the number of times the circle radius decreases. 

The patch attribute you change can be 'mapped' to an inbuilt patch attribute like pcolor or one that you create e.g. using the BehaviourComposer syntax xxx-of-patch

If you inspect the HTML for this MB you will see how to use the substitute-text-area-for BehaviourComposer syntax to name and use variables entered into a text box. Here we simply use let statements to store the values so that they can be used within the code. 

Regarding specific aspects of the code:
  1. The index (or counter) is implemented for use within the repeat statement. The let index 1 statement initialises index, the set index statement then increments this same variable - see the NetLogo definition of the set primitive regarding how it can be used in conjunction with the let primitive.
  2. That is possible to set an inbuilt patch variable  - see how patch-attribute-name is used to set pcolor

Related micro-behaviours

coming soon


If you put " my-x " and " my-y " in the entry boxes for vertical and horizontal coordinates of the agent that is drawing the concentric circles you can have a turtle moving around and drawing concentric circles from their changing current position. You can also introduce randon values for the colour and radius - here is an example model that shows these ideas.


Implemented by Howard Noble and Ken Kahn
BehaviourComposer: ignore everything after this.