{"id":4501,"date":"2016-12-30T14:16:47","date_gmt":"2016-12-30T19:16:47","guid":{"rendered":"https:\/\/www.webomator.com\/?p=4501"},"modified":"2016-12-30T14:16:47","modified_gmt":"2016-12-30T19:16:47","slug":"fun-and-games-with-javascript-animations","status":"publish","type":"post","link":"https:\/\/www.webomator.com\/wordpress\/2016\/12\/30\/fun-and-games-with-javascript-animations\/","title":{"rendered":"Fun and games with Javascript animations"},"content":{"rendered":"<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webomator.com\/grafx3\/blog\/Fun_and_Games_with_Javascript.jpg\" alt=\"Some frames from Javascript animations\" width=\"501\" height=\"464\" class=\"img_wide_open\">\n<p>I&#8217;ve just finished up about twelve days of work on a set of Javascript animations for a web site. The site itself won&#8217;t be reachable until some time next year, so I can&#8217;t show you <em>that<\/em>. But here you can see a few individual frames and elements from the set.<\/p>\n<p>Because they&#8217;re meant for the web, there are very few frames. I have to allow enough time after the page loads, and before the animation plays, for all the frames to get loaded. For that reason there&#8217;s a very simple animation that plays first, and there are only two animations on each page.<\/p>\n<p>There are usually two things going on in each animation. There&#8217;s a primary motion that carries the element around the page, and a secondary action that&#8217;s sometimes a limited animation within the element, and sometimes a special effect.<\/p>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webomator.com\/grafx3\/blog\/Fun_and_Games2.jpg\" alt=\"Actaeon rocket sprite\" width=\"130\" height=\"410\" class=\"img_flush_right\">\n<p>This meant I needed to use Javascript&#8217;s setInterval() function twice. The first time sets the delay before the animation starts, while the second one sets the frame rate for everything that happens, once it does. I never had to set a third interval, though I did schedule some updates to occur on every second or third frame.<\/p>\n<p>The site&#8217;s page layout responds to the browser window&#8217;s width and it changes any time the window&#8217;s resized. That did lead to some conceptual weirdness. I can&#8217;t predict how large the browser window is, or whether its size may change between one frame and the next. In some cases I had to deal with unexpected outcomes when I resized the browser.<\/p>\n<p>Everything seems to work now. There&#8217;s just one case &#8211; an element that travels along an arc &#8211; in which phones may have trouble keeping up with the frame rate. I can&#8217;t test that because I don&#8217;t use a mobile phone. But the math in that one instance is fairly intense; I don&#8217;t think any of the other animations will present a problem.<\/p>\n<p>And I may even do one or two more before you get a chance to see them. But, honestly, this was just a twelve-day obsession. I really ought to be working on something else. It&#8217;s just that it&#8217;s nearly impossible for me to leave something alone when it <em>almost, <\/em><em>almost<\/em> works.<\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just finished up about twelve days of work on a set of Javascript animations for a web site. The site itself won&#8217;t be reachable until some time next year, so I can&#8217;t show you that. But here you can see a few individual frames and elements from the set.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,15],"tags":[],"class_list":["post-4501","post","type-post","status-publish","format-standard","hentry","category-web-development","category-works-in-progress"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/posts\/4501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/comments?post=4501"}],"version-history":[{"count":0,"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/posts\/4501\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/media?parent=4501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/categories?post=4501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webomator.com\/wordpress\/wp-json\/wp\/v2\/tags?post=4501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}