{"id":58,"date":"2021-05-02T08:26:13","date_gmt":"2021-05-02T08:26:13","guid":{"rendered":"https:\/\/msc-ai.knipmeyer.co.uk\/?p=58"},"modified":"2021-05-02T08:26:13","modified_gmt":"2021-05-02T08:26:13","slug":"tutorial-3-procedures-walk-thru","status":"publish","type":"post","link":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/05\/02\/tutorial-3-procedures-walk-thru\/","title":{"rendered":"Tutorial #3: Procedures walk-thru"},"content":{"rendered":"\n<p>In this post I describe following the Tutorial 3 form the NetLogo User Manual.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"1024\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1014x1024.png\" alt=\"\" class=\"wp-image-59\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1014x1024.png 1014w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-297x300.png 297w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-150x150.png 150w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-768x776.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image.png 1384w\" sizes=\"auto, (max-width: 1014px) 100vw, 1014px\" \/><figcaption>it all starts here !<\/figcaption><\/figure>\n\n\n\n<p>Having followed the previous 2 tutorials, which walk thru existing code to gain familiarity with the NetLogo User Interface (UI) this tutorial starts with a completely blank interface. The tutorial takes us thru adding various buttons, sliders and graphs with the accompanying code, as well as the turtle behaviour.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"460\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1.png\" alt=\"\" class=\"wp-image-60\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1.png 940w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1-300x147.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1-768x376.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-1-500x245.png 500w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><figcaption>start here.. setup<\/figcaption><\/figure>\n\n\n\n<p>Adding elements to the UI is really simple &#8211; the &#8216;Add&#8217; menu option has various components that can be added tothe UI, in this case the &#8216;setup&#8217; button. The UI helpfully tells us that this button wont work\/do anything by being in red, this is due to the absence of code to support the action.<\/p>\n\n\n\n<p>By selecting code, I can easily assign actions to a button with the &#8216;to &#8230; end&#8217; method used within Netlogo<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>to setup\n  clear-all\n  create-turtles 100 &#91; setxy random-xcor random-ycor ]\n  reset-ticks\nend\n\n\n<\/code><\/pre>\n\n\n\n<p>This iterates for all the controls that will be added.<\/p>\n\n\n\n<p>The iteratve loop for the sheep program is the &#8216;go&#8217; button code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>to go\n  if ticks >= 500 &#91; stop ]\n  move-turtles\n  eat-grass\n  reproduce\n  check-death\n  regrow-grass\n  tick\nend<\/code><\/pre>\n\n\n\n<p>In this way our world takes shape with the sheep expending energy to move and reproduce, and eventually dieing when energy is expended. The sheep interact with the &#8216;world&#8217; by the way of the netlogo &#8217;tiles&#8217; when they random move and encounter a green tile, energy increases. Grass only regrows after a number of turns, so the balance between sheep, movement, birth, deaths and grass growing is exhibited.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>to eat-grass\n  ask turtles &#91;\n    if pcolor = green &#91;\n      set pcolor black\n      set energy (energy + energy-from-grass)\n    ]\n    ifelse show-energy?\n    &#91; set label energy ]\n    &#91; set label \"\" ]\n  ]\nend\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"906\" src=\"https:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2-1024x906.png\" alt=\"\" class=\"wp-image-61\" srcset=\"http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2-1024x906.png 1024w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2-300x266.png 300w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2-768x680.png 768w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2-339x300.png 339w, http:\/\/msc-ai.knipmeyer.co.uk\/wp-content\/uploads\/2021\/05\/image-2.png 1376w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>The tutorial takes you from blank canvas to sheep environment quickly<\/figcaption><\/figure>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Conclusion<\/span><\/strong><\/p>\n\n\n\n<p>I found the three tutorials all very well written and easy to follow, I was quickly able to grasp how to add buttons, counters, toggles and sliders, and the association between these and the code.<\/p>\n\n\n\n<p>It is still early in the development practices, but I think a section on comments and why &#8216;globals&#8217; are declared at the start of the program would of been useful. I think too many devleopers\/programming overlook the importance of commenting code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I describe following the Tutorial 3 form the NetLogo User Manual. Having followed the previous 2 tutorials, which walk thru existing code to gain familiarity with the NetLogo User Interface (UI) this tutorial starts with a completely &hellip; <a href=\"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/2021\/05\/02\/tutorial-3-procedures-walk-thru\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":1,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":62,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/58\/revisions\/62"}],"wp:attachment":[{"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/msc-ai.knipmeyer.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}