{"id":84,"date":"2011-09-16T21:54:03","date_gmt":"2011-09-16T21:54:03","guid":{"rendered":"http:\/\/courses.haigarmen.com\/isma303\/?p=84"},"modified":"2011-09-16T21:54:03","modified_gmt":"2011-09-16T21:54:03","slug":"structure-logic-animation","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/isma303\/structure-logic-animation\/","title":{"rendered":"Structure, Logic &amp; Animation"},"content":{"rendered":"<p>Until now our scripts have been nothing more than a short list of instructions to perform, after which they stop. But with anything beyond the most basic level of programming, we will need to go further and group instructions and provide some decisions. It&#8217;s time to step it up a notch.<\/p>\n<p><strong>The Frame Loop<\/strong><\/p>\n<p>The frame can mean a variety of things within the computer sciences, but our meaning is the movie industry sense \u2013 a single still image which, if we flash enough of them fast enough, it would give the illusion of movement or animation.<\/p>\n<p>With Processing, a frame loop redraws the screen continuously. If you instruct Processing to do so, you can use this feature to add the dimension of time to your two-dimensional visuals and can create works that grow and move.<\/p>\n<p>To enable this way of drawing to the screen, we need to begin putting our code into <a href=\"glossary\/function\">function<\/a> blocks. Processing sets aside two function blocks for frame-based scripting: setup() and draw().<\/p>\n<p><strong>setup()<br \/>\n<\/strong>The code inside the setup() function block is called once when the program launches, so it should contain all your initialization code \u2013 setting the canvas size, setting the background colour, initializing variables, and so on.<\/p>\n<p><strong>draw()<br \/>\n<\/strong>The code you write inside draw() is then called repeatedly, triggered on every frame. You can set the speed with which <strong>draw() <\/strong>is called by using the <strong>frameRate<\/strong>\u00a0function. The program will work to maintain the rate which you set and will only deviate from this frame rate if the amount of computations exceed the capacity of the processor which is running the program.<\/p>\n<pre>void setup(){\ncode...\/\/ This code block will run only once,\n\u2026\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ at the start of the sketch.\n\u2026\n}\nvoid draw(){\ncode...\/\/ This code block with run repeatedly,\n\u2026\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u00a0 throughout the duration of the sketch.\n\u2026\n}<\/pre>\n<p>Want to see this structure in action? See the simple <a href=\"http:\/\/courses.haigarmen.com\/isma303\/growing-circle\">Growing Circle<\/a> exercise.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Until now our scripts have been nothing more than a short list of instructions to perform, after which they stop. But with anything beyond the most basic level of programming, we will need to go further and group instructions and provide some decisions. It&#8217;s time to step it up a notch. The Frame Loop The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-articles"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/isma303\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}