0

I created a grid containing several rectangles. These rectangles are represented by several orange patches and each rectangle is delimitated by white corridors.

How can I color patches within a given orange rectangle ?

Thanks in advance.

This is a beginning of code :

to create-yellow-patches

ask one-of patches with [pcolor = orange] [ 
 set pcolor yellow
 foreach list pxcor to max-pxcor [ ;; I don't know how to define a list from pxcor to max-pxcor
  let x ?
  foreach list min-pycor to max-pycor [ ;; I don't know how to define a list from min-pycor to max-pycor
   let y ?
    ifelse [pcolor] of patches with [pxcor = x and pycor = y ] = orange 
    [ set pcolor yellow ] 
    [ break ] ] ] ;; I don't know what is the equivalent of break in netlogo

  foreach pxcor - 1 to min-pxcor [ ;; I don't know how to define a list from pxcor - 1 to min-pxcor
   let x ?
   foreach min-pycor to max-pycor [ ;; I don't know how to define a list from min-pycor to max-pycor
    let y ?
    ifelse [pcolor] of patches with [pxcor = x and pycor = y ] = orange 
    [ set pcolor yellow ]     
    [ break ] ] ] ;; I don't know what is the equivalent of break in netlogo
end
4

1 回答 1

1

Here's some example code for making an orange rectangle of patches:

ask patches with [pxcor >= -3 and pxcor <= 6 and pycor >= -5 and pycor <= 7] [
  set pcolor orange
]

I'm guessing that doesn't fully answer your question though. You have already have some orange patches and some white patches and those should somehow control the location of the rectangle you want to draw... something like that?

UPDATE

OK, the question is lot clearer now.

There's a ton of different ways you can solve this. Here's the most elegant one I can think of:

to setup
  clear-all
  ask patches [
    ifelse pxcor mod 5 = 0 or pycor mod 5 = 0
      [ set pcolor white ]
      [ set pcolor orange ]
  ]
end

to create-yellow-patches
  let seed one-of patches with [pcolor = orange] 
  ask seed [ turn-yellow ]
end

to turn-yellow  ;; patch procedure
  set pcolor yellow
  ask neighbors4 with [pcolor = orange] [
    turn-yellow
  ]
end

This is a completely different approach than the one you were trying. If you want to stick with your original solution approach, I would suggest writing your loops using while instead of foreach plus break.

于 2013-10-16T16:39:31.580 回答