{"id":806,"date":"2016-06-14T15:05:17","date_gmt":"2016-06-14T20:05:17","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=806"},"modified":"2016-06-14T15:29:50","modified_gmt":"2016-06-14T20:29:50","slug":"reproducing-a-clever-animation-product-part-9","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/06\/14\/reproducing-a-clever-animation-product-part-9\/","title":{"rendered":"Reproducing A Clever Animation Product, Part 9"},"content":{"rendered":"<p>Yesterday&#8217;s attempt wasn&#8217;t too bad; I needed to fix the declaration and use of the object that holds the transform information (yesterday&#8217;s form only works if you initialize the internal member values with literals) and I needed to tweak a couple of indexes.  The corrected code is shown below, along with an extra function for displaying the information.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      var bcTransformList = new Array;\r\n\r\n      function tObj(pStart,pEnd,tBegin,tDuration,mMethod) {\r\n        this.pStart = pStart;\r\n        this.pEnd = pEnd;\r\n        this.tBegin = tBegin;\r\n        this.tDuration = tDuration;\r\n        this.mMethod = mMethod;\r\n      }\r\n\r\n      function addTransformToList(sElement,sType,pStart,pEnd,tBegin,tDuration,mMethod) {\r\n        var obj = new tObj(pStart,pEnd,tBegin,tDuration,mMethod);\r\n        if (bcTransformList.length > 0) {\r\n          var i = 0;\r\n          while (i < bcTransformList.length) {\r\n            if (sElement == bcTransformList[i][0]) {\r\n              break;\r\n            }\r\n            i++;\r\n          }\r\n          if (i < bcTransformList.length) {  \/\/element already in list, add to it\r\n            var j = 0;                       \/\/don't have to check for empty type list\r\n            while (j < bcTransformList[i].length) {\r\n              if (sType == bcTransformList[i][j][0]) {\r\n                break;\r\n              }\r\n              j++;\r\n            }\r\n            if (j < bcTransformList[i].length)  {  \/\/type already in list, add object to existing sublist\r\n              bcTransformList[i][j].push(obj);\r\n            } else {  \/\/type not already in list, add it\r\n              bcTransformList[i][j] = new Array;\r\n              bcTransformList[i][j][0] = sType;\r\n              bcTransformList[i][j][1] = obj;\r\n            }\r\n          } else {  \/\/element new to list, add to end\r\n            bcTransformList[i] = new Array;\r\n            bcTransformList[i][0] = sElement;\r\n            bcTransformList[i][1] = new Array;\r\n            bcTransformList[i][1][0] = sType;\r\n            bcTransformList[i][1][1] = obj;\r\n          }  \r\n        } else {  \/\/this is the first element\r\n          bcTransformList[0] = new Array;\r\n          bcTransformList[0][0] = sElement;\r\n          bcTransformList[0][1] = new Array;\r\n          bcTransformList[0][1][0] = sType;\r\n          bcTransformList[0][1][1] = obj;\r\n        }\r\n      }\r\n\r\n      function orderTransformList() {\r\n        if (bcTransformList.length > 0) {\r\n          for (var i=0; i<bcTransformList.length; i++) {  \/\/for each element\r\n            for (var j=1; j<bcTransformList[i].length; j++) {  \/\/for each type\r\n              if (bcTransformList[i][j].length > 2) {  \/\/if there are multiple elements, sort them\r\n                var tempObj = new Array;\r\n                tempObj[0] = bcTransformList[i][j][0];  \/\/type\r\n                tempObj[1] = bcTransformList[i][j][1];  \/\/first element\r\n                for (var k=2; k<bcTransformList[i][j].length; k++) {\r\n                  var n = 1;\r\n                  while ((n < tempObj.length) &#038;&#038; (bcTransformList[i][j][k].tBegin >= tempObj[n].tBegin)) {\r\n                    n++;\r\n                  }\r\n                  tempObj.splice(n,0,bcTransformList[i][j][k]);  \/\/subsequent elements, in order\r\n                }\r\n                bcTransformList[i][j] = tempObj;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n\r\n      function displayTransformList() {\r\n        var s = \"TransformList<br \/>\";\r\n        if (bcTransformList.length > 0) {\r\n          for (var i=0; i<bcTransformList.length; i++) {\r\n            s += \"Element: \" + bcTransformList[i][0] + \"<br \/>\";\r\n            for (var j=1; j<bcTransformList[i].length; j++) {\r\n              s += \"Type: \" + bcTransformList[i][j][0] + \"<br \/>\";\r\n              for (var k=1; k<bcTransformList[i][j].length; k++) {\r\n                s += \"start: \"+bcTransformList[i][j][k].pStart+\r\n                     \" end: \"+bcTransformList[i][j][k].pEnd+\r\n                     \" begin: \"+bcTransformList[i][j][k].tBegin+\r\n                     \" duration: \"+bcTransformList[i][j][k].tDuration+\r\n                     \" method: \" +bcTransformList[i][j][k].mMethod+ \"<br \/>\"; \r\n              }\r\n            }\r\n          }\r\n        }\r\n        tList = document.getElementById(\"transformList\");\r\n        tList.innerHTML = s;\r\n      }\r\n<\/pre>\n<p>Here is how I loaded up the array.  It includes a series of three transformations for the left location of the first object, but out of order.  It then displays the information before sorting, does the sort, and displays the information again after the sort.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      addTransformToList(\"handle001\",\"left\",301,25,0.0,0.75,\"linear\");\r\n      addTransformToList(\"handle001\",\"left\",301,25,4.0,0.5,\"linear\");\r\n      addTransformToList(\"handle001\",\"left\",25,301,2.0,1.0,\"linear\");\r\n      addTransformToList(\"handle001\",\"opacity\",0.0,1.0,0.0,0.75,\"linear\");\r\n      addTransformToList(\"handle002\",\"top\",-25,125,0.5,0.75,\"linear\");\r\n      addTransformToList(\"handle002\",\"opacity\",0.0,1.0,0.5,0.75,\"linear\");\r\n\r\n      displayTransformList();\r\n      alert(\"before sorting\")\r\n      orderTransformList();\r\n      displayTransformList();\r\n      alert(\"after sorting\")\r\n<\/pre>\n<p>Here&#8217;s the output before the sort:<br \/>\n<code><br \/>\nTransformList<br \/>\nElement: handle001<br \/>\nType: left<br \/>\nstart: 301 end: 25 begin: 0 duration: 0.75 method: linear<br \/>\nstart: 301 end: 25 begin: 4 duration: 0.5 method: linear<br \/>\nstart: 25 end: 301 begin: 2 duration: 1 method: linear<br \/>\nType: opacity<br \/>\nstart: 0 end: 1 begin: 0 duration: 0.75 method: linear<br \/>\nElement: handle002<br \/>\nType: top<br \/>\nstart: -25 end: 125 begin: 0.5 duration: 0.75 method: linear<br \/>\nType: opacity<br \/>\nstart: 0 end: 1 begin: 0.5 duration: 0.75 method: linear<br \/>\n<\/code><\/p>\n<p>&#8230;and here it is after the sort:<br \/>\n<code><br \/>\nTransformList<br \/>\nElement: handle001<br \/>\nType: left<br \/>\nstart: 301 end: 25 begin: 0 duration: 0.75 method: linear<br \/>\nstart: 25 end: 301 begin: 2 duration: 1 method: linear<br \/>\nstart: 301 end: 25 begin: 4 duration: 0.5 method: linear<br \/>\nType: opacity<br \/>\nstart: 0 end: 1 begin: 0 duration: 0.75 method: linear<br \/>\nElement: handle002<br \/>\nType: top<br \/>\nstart: -25 end: 125 begin: 0.5 duration: 0.75 method: linear<br \/>\nType: opacity<br \/>\nstart: 0 end: 1 begin: 0.5 duration: 0.75 method: linear<br \/>\n<\/code><\/p>\n<p>Now that this is done I can modify the tween definition functions to write out the full and correct state of every element for every animation step.<\/p>\n<p>Also, it can be argued that it&#8217;s unnecessary to specify the beginning and ending state of each transform.  The properties to be transformed are already initialized, so in theory the transform functions would only have to specify what the new value should be.  That would obviate the need to correctly specify the initial value of a property as being the same as the final value from then end of a previous transformation.  I note that the <a href=\"http:\/\/greensock.com\/sequence-video\">Greensock<\/a> product does this, including not just a &#8220;to&#8221; transform but also a &#8220;from&#8221; transform.  If you initialize all the elements where you want them to end up you can get an idea of the final layout, and then the animation sequence can start from where you specify and end up where they were initialized.  That said, one thing at a time&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s attempt wasn&#8217;t too bad; I needed to fix the declaration and use of the object that holds the transform information (yesterday&#8217;s form only works if you initialize the internal member values with literals) and I needed to tweak a &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/06\/14\/reproducing-a-clever-animation-product-part-9\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[87,101,49],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/806"}],"collection":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/comments?post=806"}],"version-history":[{"count":5,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/806\/revisions"}],"predecessor-version":[{"id":811,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/806\/revisions\/811"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}