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










share|improve this question




























    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










    share|improve this question


























      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










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 12:56









      JenB

      7,8581936




      7,8581936










      asked Nov 11 at 2:50









      Neena saskia

      32




      32
























          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 ]





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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 ]





          share|improve this answer





















          • 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















          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 ]





          share|improve this answer





















          • 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













          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 ]





          share|improve this answer












          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 ]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine