Re: [netlogo-users] i need help
- baishakinaha <baishakinaha@...> wrote:
> can someone help me. I need to make a procedure in netlogo so thatBaishakinaha,
> everytime the turtle makes a square i want it to fill in with color
> in that area. Please email me back if you can help me.
That's a tricky one!
There's lots of different ways to solve that problem, and one
important question that may help choose the best way is: "How is the
turtle drawing the square?"
And the next is: Why are we filling in the square?
See, if the answer is, "because we want to QUICKLY paint filled-in
squares, well, here's the way I would do it:
;; this code is run by a turtle on the patch.
;; makes a filled in square with the current patch or turtle as the
;; fills the patches with the color of the patch calling this procedure.
;; ROUNDS the turtle heading to the nearest 90 degrees
;; takes as input the length of one side of the square:
to draw-filled-square [ side ]
ask patches with
[ pxcor >= pxcor-of myself
and pxcor <= pxcor-of myself + side - 1
and pycor >= pycor-of myself
and pycor <= pycor-of myself + side - 1
[ set pcolor pcolor-of myself ]
However, this could be considered "cheating'" if the goal of the
procedure was to do something clever with turtles.
Here's another way, that's more "turtle-centric" (and recursive, to boot!)
to draw [ side ]
; marks this spot
; drop the pen, and prepare to draw
; draw a square this size
; subtract one, because just staying put is a 1 unit square...
[ fd side - 1
; stop drawing
; if side is big enough that there is still interior to be filled in,
if side >= 3
[ ; move into interior
; draw a smaller square
draw (side - 2)
; move back to starting point.
Hope this helps!