NETLOGO patches squares and rectangles
up vote
0
down vote
favorite
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
netlogo
add a comment |
up vote
0
down vote
favorite
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
netlogo
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
netlogo
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
netlogo
netlogo
edited Nov 11 at 12:56
JenB
7,8581936
7,8581936
asked Nov 11 at 2:50
Neena saskia
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
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 ]
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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 ]
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
add a comment |
up vote
1
down vote
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 ]
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
add a comment |
up vote
1
down vote
up vote
1
down vote
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 ]
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 ]
answered Nov 11 at 13:06
JenB
7,8581936
7,8581936
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
add a comment |
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Thank you for your help- now I know how to get the upper left corner to e changed. I tried using ask patches with [pxcor <= (w - 1) and pxcor >= x and pycor <= y and pycor >= (- h + 1)] [ set pcolor blue ] but when i replace x and y for the numbers, it does not work. ask patches with [pxcor <= (w - 1) and pxcor >= 0 and pycor <= 0 and pycor >= (- h + 1)] [ set pcolor blue ] work, but using a variable does not. Any advice? This function is a helper by the way, the actual one has the coordinates and w and h as numbers.
– Neena saskia
Nov 12 at 14:12
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
Do a new question with more complete code. The description of your problem should report any error messages, what you want to occur, and what actually occurs. All relevant code must be included if you want us to work out what's wrong.
– JenB
Nov 12 at 14:26
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
I have asked a new question on the site any chance you could offer some more help?
– Neena saskia
Nov 12 at 20:07
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245432%2fnetlogo-patches-squares-and-rectangles%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown