NETLOGO: Drawing Rectangles and Shapes with Patches












0















I am trying to create a code that draws squares and rectangle using patches. The variables used are x and y for coordinates of the upper left corner of the shape, l and w for length and width, and c for color.
I used this, and it creates a rectangle where 1,1 is the upper left corner, and it has a length of 5 and width 4.



to rectanglebase [x y w l c]
ask patches with [pxcor <= w and pxcor >= x and pycor <= y and pycor >= (- l + 2)]
[set pcolor c]
end
to therectangle
rectanglebase 1 1 4 5 red
end


If I want to make x and y be other values, what do i have to fix? every time I put in another value, the output is not what I want. What kind of modifications does my code need so that the drawn rectangle patch will be at the x and y coordinates i put into therectangle?










share|improve this question





























    0















    I am trying to create a code that draws squares and rectangle using patches. The variables used are x and y for coordinates of the upper left corner of the shape, l and w for length and width, and c for color.
    I used this, and it creates a rectangle where 1,1 is the upper left corner, and it has a length of 5 and width 4.



    to rectanglebase [x y w l c]
    ask patches with [pxcor <= w and pxcor >= x and pycor <= y and pycor >= (- l + 2)]
    [set pcolor c]
    end
    to therectangle
    rectanglebase 1 1 4 5 red
    end


    If I want to make x and y be other values, what do i have to fix? every time I put in another value, the output is not what I want. What kind of modifications does my code need so that the drawn rectangle patch will be at the x and y coordinates i put into therectangle?










    share|improve this question



























      0












      0








      0


      0






      I am trying to create a code that draws squares and rectangle using patches. The variables used are x and y for coordinates of the upper left corner of the shape, l and w for length and width, and c for color.
      I used this, and it creates a rectangle where 1,1 is the upper left corner, and it has a length of 5 and width 4.



      to rectanglebase [x y w l c]
      ask patches with [pxcor <= w and pxcor >= x and pycor <= y and pycor >= (- l + 2)]
      [set pcolor c]
      end
      to therectangle
      rectanglebase 1 1 4 5 red
      end


      If I want to make x and y be other values, what do i have to fix? every time I put in another value, the output is not what I want. What kind of modifications does my code need so that the drawn rectangle patch will be at the x and y coordinates i put into therectangle?










      share|improve this question
















      I am trying to create a code that draws squares and rectangle using patches. The variables used are x and y for coordinates of the upper left corner of the shape, l and w for length and width, and c for color.
      I used this, and it creates a rectangle where 1,1 is the upper left corner, and it has a length of 5 and width 4.



      to rectanglebase [x y w l c]
      ask patches with [pxcor <= w and pxcor >= x and pycor <= y and pycor >= (- l + 2)]
      [set pcolor c]
      end
      to therectangle
      rectanglebase 1 1 4 5 red
      end


      If I want to make x and y be other values, what do i have to fix? every time I put in another value, the output is not what I want. What kind of modifications does my code need so that the drawn rectangle patch will be at the x and y coordinates i put into therectangle?







      netlogo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 22:12









      JenB

      8,36911036




      8,36911036










      asked Nov 12 '18 at 19:53









      Neena saskiaNeena saskia

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          3














          Two possible fixes : "pxcor <= w" and "pycor >= (- l + 2)"



          From the conditional, the pxcor "x coordinates" seem to be between your "x" x-coordinate and "w" x-coordinate, meaning pxcor is selecting from your "x" and your width ("w"). This is the same with the pycor. With some rewriting, the bound becomes more clear.



          Rewritten Conditional (where l is length and w is width):



          ask patches with
          [ w >= pxcor and pxcor >= x
          and
          y >= pycor and pycor >= (- l + 2) ] [ set pcolor c ]


          Possible Modification (* : modification):



          ask patches with
          [ * w + x >= pxcor and pxcor >= x
          and
          y >= pycor and pycor >= *(y - l) ] [ set pcolor c ]





          share|improve this answer























            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',
            autoActivateHeartbeat: false,
            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%2f53269179%2fnetlogo-drawing-rectangles-and-shapes-with-patches%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









            3














            Two possible fixes : "pxcor <= w" and "pycor >= (- l + 2)"



            From the conditional, the pxcor "x coordinates" seem to be between your "x" x-coordinate and "w" x-coordinate, meaning pxcor is selecting from your "x" and your width ("w"). This is the same with the pycor. With some rewriting, the bound becomes more clear.



            Rewritten Conditional (where l is length and w is width):



            ask patches with
            [ w >= pxcor and pxcor >= x
            and
            y >= pycor and pycor >= (- l + 2) ] [ set pcolor c ]


            Possible Modification (* : modification):



            ask patches with
            [ * w + x >= pxcor and pxcor >= x
            and
            y >= pycor and pycor >= *(y - l) ] [ set pcolor c ]





            share|improve this answer




























              3














              Two possible fixes : "pxcor <= w" and "pycor >= (- l + 2)"



              From the conditional, the pxcor "x coordinates" seem to be between your "x" x-coordinate and "w" x-coordinate, meaning pxcor is selecting from your "x" and your width ("w"). This is the same with the pycor. With some rewriting, the bound becomes more clear.



              Rewritten Conditional (where l is length and w is width):



              ask patches with
              [ w >= pxcor and pxcor >= x
              and
              y >= pycor and pycor >= (- l + 2) ] [ set pcolor c ]


              Possible Modification (* : modification):



              ask patches with
              [ * w + x >= pxcor and pxcor >= x
              and
              y >= pycor and pycor >= *(y - l) ] [ set pcolor c ]





              share|improve this answer


























                3












                3








                3







                Two possible fixes : "pxcor <= w" and "pycor >= (- l + 2)"



                From the conditional, the pxcor "x coordinates" seem to be between your "x" x-coordinate and "w" x-coordinate, meaning pxcor is selecting from your "x" and your width ("w"). This is the same with the pycor. With some rewriting, the bound becomes more clear.



                Rewritten Conditional (where l is length and w is width):



                ask patches with
                [ w >= pxcor and pxcor >= x
                and
                y >= pycor and pycor >= (- l + 2) ] [ set pcolor c ]


                Possible Modification (* : modification):



                ask patches with
                [ * w + x >= pxcor and pxcor >= x
                and
                y >= pycor and pycor >= *(y - l) ] [ set pcolor c ]





                share|improve this answer













                Two possible fixes : "pxcor <= w" and "pycor >= (- l + 2)"



                From the conditional, the pxcor "x coordinates" seem to be between your "x" x-coordinate and "w" x-coordinate, meaning pxcor is selecting from your "x" and your width ("w"). This is the same with the pycor. With some rewriting, the bound becomes more clear.



                Rewritten Conditional (where l is length and w is width):



                ask patches with
                [ w >= pxcor and pxcor >= x
                and
                y >= pycor and pycor >= (- l + 2) ] [ set pcolor c ]


                Possible Modification (* : modification):



                ask patches with
                [ * w + x >= pxcor and pxcor >= x
                and
                y >= pycor and pycor >= *(y - l) ] [ set pcolor c ]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 '18 at 20:57









                javylowjavylow

                737




                737






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269179%2fnetlogo-drawing-rectangles-and-shapes-with-patches%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

                    Full-time equivalent

                    Bicuculline

                    さくらももこ