I create several turtles with the same shape. One of them I need to rotate 90 degrees.I tried rt and also heading. Nothing works. When I created the shape I cancelled the rotation - does it influence. How ca n I set may shape rotated. All these shapes doesn`t move.
crt 0 [
setxy 0 / 4) 0
set shape "tunnel"
set heading 200
set size 10]
crt 1 [
setxy 10 0
set shape "tunnel"
set heading 200
set size 10]
Some NetLogo turtle shapes are by default not rotatable.
When you open the "Turtle Shapes Editor" (Tools Menu) you will see that some shapes are framed within a circle (rotatable), whereas others are framed within a box (not rotatable). However, you can easily change this setting for the default shapes and also for your own shapes. Just edit a non-rotatable shape and check the rotatable checkbox in the lower left.
Related
I have to make a button that colors in the patches in the bottom half of the grid randomly with darker shades of a given color based off of a slider, and the top of half of the grid randomly with lighter shades of a given color based off of the slider. When I wrote my code it says that I can't use my command because it is in patch-context because by command is in turtle-only context. I am confused because I am not using turtles, I am only using patches. Inside of my button I wrote "colorRandomShade2" which is the name of my command. The button is also in patch context and its display name is "colorRandomShade2".
Code:
to colorRandomShade2
if ycor > 0 [ set pcolor ( main_color + random 5 ) ]
if ycor < 0 [ set pcolor ( main_color + random 9 ) ]
end
Patch coordinates are pxcor and pycor, but you have used xcor and ycor, which are the variable names for coordinates of a turtle. So you are pressing the button to call the code and the first thing that NetLogo sees is a request to look at the ycor or y-coordinate of a turtle.
I wanted to initialise my world with turtles that would theoretically occupy x% of the total surface area or the size of the world. How do I know what is the exact size of each turtle? I know the world size can be calculated by:
world-width
world-height
My turtles are triangular in size and currently a size 4 and as per patch size 5 and dimensions of the world set to -80 80 -80 80, this size is perfect and I would like to keep it at size 4.
How do I calculate what number of turtles would occupy 1%, 5%, 10%, 20% and 40% of the entire surface area?
You are on the right track with world-width and world-size. Those give you the size of the world, based on the number of patches.
If you want to make a turtle to have half the surface area, you just need to update it's size variable, which is also measured in patches. So a turtle with size of 1 is exactly as tall and wide as a single patch.
to make-half-size-square
clear-all
; assumes we want a square shape, just use `sqrt` on the total world surface area
let half-surface-size sqrt (world-width * world-height / 2)
show half-surface-size
crt 1 [
set shape "square"
set size half-surface-size
]
end
to make-half-size-circle
clear-all
; assumes we want a circle shape
let half-surface-size 2 * sqrt ((world-width * world-height / 2) / pi)
show half-surface-size
crt 1 [
set shape "circle"
set size half-surface-size
]
end
A couple extra bits of info, though:
The size only controls the visual size of the turtle in the world view. It still only lives on a single patch. If you want to get all turtles/patches "under" the turtle shape you'll need to use in-radius (for a circle) or do a bounding-box check using the turtle's size (for a square).
The turtle might not quite appear to take up half the surface area. This is because the shape the turtle uses might not go all the way to the edge of its possible size. Even the square shape that comes with NetLogo doesn't quite have its edges all the way at the end, but the circle does.
I am trying to create a square of brown patches centered at the origin of my grid. Previously, I had a slider on the interface called "sink-patch-radius" that goes from 0 to 20. Then in my code, I created a circular set of patches centered at the origin that were colored brown + 2 and had a radius of "sink-patch-radius", and the surrounding patches were green. Here is the code that worked for that (thank you to JenB for this!):
;;create the 'sink'
let sink-centre patch 0 0
set sink-patches [patches in-radius sink-patch-radius] of sink-centre
ask sink-patches [ set pcolor brown + 2 ]
;; create the 'source'
set source-patches patches with [pcolor != brown + 2]
ask source-patches [ set pcolor green ]
So now, I want that idea to stay the same, but instead of a circular "sink area", I want it to be a square. I know the above code will have to change, maybe even quite a bit, because you cannot use "in-radius" to make a square. I'm thinking of maybe changing the slider to be "sink-patch-length" so that it adjusts the length of the sides of the square. My question would then be: how do I incorporate that into my code, so that I get a square of brown patches centered at the origin? For example, if "sink-patch-length" is set to 20, then I would want a 20x20 square (400 cells) centered at the origin to have a pcolor of brown + 2.
Any help is greatly appreciated! Thank you.
Use the inbuilt coordinate system. So you want (something like) patches with [abs(pxcor) <= sink-patch-length and abs(pycor) <= sink-patch-length]. If you want it centred somewhere other than the middle, you will need to do some fiddling to make the boundaries correct.
I'm attempting to make squares and rectangles with patches on netlogo, with the variables x (pxcor) y (pycor) w (width) l (length). I wrote
ask patch random w random h [set pcolor blue]
and was able to create regular rectangles and squares with lengths and widths I enter, but they always appear with the lower left corner at 0, 0. How can I create these shapes and have them appear with the upper left corner the x and y coordinates that I enter. Please, any help would be appreciated
In fact, your code instructs NetLogo to turn ONE patch blue, not a rectangle of patches. This is because random w selects a random number from 0 to (w-1) and random h selects a random number from 0 to (h-1). If the two random numbers chosen happen to be 3 and 2, you are telling NetLogo to change the color of patch 3 2 to blue.
If you are actually getting rectangles, you must be repeatedly selecting one random patch, but that's not in the code you provided.
In NetLogo, patch 0 0 is the centre of the world (though that can be changed with settings). Think about what you are trying to do. If you want (0,0) to be the upper left corner, then you want the rectangle to cover the space from pxcor of 0 to w and pycor of -h to 0 (possibly different, depending on whether you want 0,0 in the rectangle).
So you want something more like:
ask patches with [pxcor <= 3 and pxcor > 0 and pycor < 0 and pycor >= -2]
[ set pcolor blue ]
Is there a way to make in Netlogo an object similar to this?
I would like a dynamic object, formed by 3 circumferences and if possible, I wish I could dynamically resize them, making them larger or thinner.
Maybe something like this? They will have to be different agents, so you will have 3 times as many agents as you actually want.
to makecell
create-turtles 1
[ set shape "circle"
set color green
set size 20
]
create-turtles 1
[ set shape "circle"
set color red
set size 15
]
create-turtles 1
[ set shape "circle"
set color gray
set size 10
]
end