ecl
ecl

Reputation: 389

Divide world into equal parts


Edited

Removed duplicated question. See link for the removed question.


2) I want to divide the world into 9 or 16 parts (with the same size). I want the world to be several squares (either 3x3 or 4x4). I found something that is on the right track here at StackOverflow and with @Bryan Head's code, I can generate something like this. But I don't want the size to be random, I want all areas to have the same size.

; Dividing the world randomly into 14 parts.
ca
let region-num 0
ask n-of 14 patches [
  set pcolor item region-num base-colors
  set region-num region-num + 1
  ]
while [ any? patches with [ pcolor = black ] ] [
  ask patches with [ pcolor != black ] [
     ask neighbors with [ pcolor = black ] [ set pcolor [ pcolor ] of myself ]
  ]
]

Thanks!

Upvotes: 1

Views: 414

Answers (1)

Jumboman
Jumboman

Reputation: 541

for point 2: you could use

ask patches with [pxcor < 3 and pycor < 3] 

to get all patches in a corner. You can expand on this to divide the map into parts.

edit to expand on my comment: try the code below.

to test
  resize-world 0 8 0 8
  let x 3
  let y 3
  let col 5
  while [y <= 9][
    while [x <= 9][
      ask patches with [pxcor < x and pxcor >= x - 3 and pycor < y and pycor >= y - 3][
        set pcolor col
      ]
      set x x + 3
      set col col + 10
    ]
    set x 3
    set y y + 3
  ]
end

Upvotes: 3

Related Questions