{"id":861,"date":"2016-07-06T21:46:38","date_gmt":"2016-07-07T02:46:38","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=861"},"modified":"2017-02-03T14:39:46","modified_gmt":"2017-02-03T19:39:46","slug":"reproducing-a-clever-animation-product-part-20","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/07\/06\/reproducing-a-clever-animation-product-part-20\/","title":{"rendered":"Reproducing A Clever Animation Product, Part 20"},"content":{"rendered":"<p>Today I added the capability of adding a rotation tween, which I applied to a fourth element at the end of the previous animation.  The tween definition is here:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      function bcDefineRotateTween(sElement,pStart,pEnd,tBegin,tDuration,mMethod) {\r\n        var s = sElement+\".style.transform='rotate(\"+pStart+\"deg)';\";\r\n        var alpha = Math.round(tBegin * 60.0);\r\n        var steps = Math.round(tDuration * 60.0);\r\n        var omega = alpha + steps;\r\n        var increment = (pEnd - pStart) \/ steps;\r\n        var angle = pStart;\r\n        var index = bcActivitiesList[0].length-1;\r\n        if ((alpha > 0) && (!bcChainFlag)) {\r\n          for (var i=0; i<alpha; i++) {    \/\/>\r\n            bcActivitiesList[i][0] = bcActivitiesList[i].push(s);\r\n          }\r\n        }\r\n        if (!bcChainFlag) {\r\n          index++;\r\n        }\r\n        for (var i=alpha; i<=omega; i++) { \/\/>\r\n          s = sElement+\".style.transform='rotate(\"+angle+\"deg)';\";\r\n          bcActivitiesList[i][0] = index+1;\r\n          bcActivitiesList[i][index] = s;\r\n          if (mMethod == \"linear\") {\r\n            angle += increment;\r\n          }\r\n        }\r\n        for (i=omega+1; i<=bcFinalActivity; i++) {\r\n          bcActivitiesList[i][0] = index+1;\r\n          bcActivitiesList[i][index] = s;\r\n        }\r\n        bcClearChainFlag();\r\n      }\r\n<\/pre>\n<p>Here's the code added to handle rotations in the <code>addTransformToList<\/code> function.  The only interesting bit is ensuring the default starting value is properly initialized.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n          if (keyList[ii] == \"left\") {\r\n            pStart = parseFloat(element.style.left);\r\n            pEnd = pStart + parseFloat(trans.left);\r\n          } else if (keyList[ii] == \"top\") {\r\n            pStart = parseFloat(element.style.top);\r\n            pEnd = pStart + parseFloat(trans.top);\r\n          } else if (keyList[ii] == \"opacity\") {\r\n            pStart = parseFloat(element.style.opacity);\r\n            pEnd = pStart + parseFloat(trans.opacity);\r\n          } else if (keyList[ii] == \"display\") {\r\n            pStart = element.style.display;\r\n            pEnd = trans.display;\r\n          } else if (keyList[ii] == \"scale\") {\r\n            var temp = element.style.transform;\r\n            var locStart = temp.search(\"scale\");\r\n            var temp1 = temp.substr(locStart);\r\n            var locEnd = temp1.indexOf(\"\\)\");\r\n            pStart = temp1.substr(5,locEnd-(5-1));\r\n            pEnd = trans.scale;\r\n          } else if (keyList[ii] == \"rotate\") {\r\n            var temp = element.style.transform;\r\n            var locStart = temp.search(\"rotate\");\r\n            var temp1 = temp.substr(locStart);\r\n            var locEnd = temp1.indexOf(\"\\)\");\r\n            pStart = temp1.substr(5,locEnd-(5-1));\r\n            if (pStart == \"\") {\r\n              pStart = 0;\r\n            } else {\r\n              pStart = parseFloat(pStart);\r\n            }\r\n            pEnd = parseFloat(trans.rotate);\r\n          }\r\n<\/pre>\n<p>Here are the initializations for the elements and animations.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      var handle001 = document.getElementById(\"handle001\");\r\n      bcInitElement(handle001,\"301px\",\"50px\",\"red\",\"rgba(0,0,0,0)\",\"260px\",0,\"block\",\"This line slides in, out, in\");\r\n      addTransformToList(\"handle001:1\",0.75,{left:-284, opacity:1.0});\r\n      addTransformToList(\"handle001\",0.50,{left:284});\r\n      addTransformToList(\"handle001:2\",0.75,{left:-284});\r\n      addTransformToList(\"handle001\",0.00,{display:\"none\"});\r\n      \r\n      var handle002 = document.getElementById(\"handle002\");\r\n      bcInitElement(handle002,\"17px\",\"-25px\",\"blue\",\"rgba(0,0,0,0)\",\"280px\",0,\"block\",\"This line drops down from the top\");\r\n      addTransformToList(\"handle002\",0.75,{top:150, opacity:1.0},\"linear\",\"handle001:1-=0.25\");\r\n      addTransformToList(\"handle002\",0.00,{display:\"none\"},\"\",\"handle001:2\");\r\n\r\n      var handle003 = document.getElementById(\"handle003\");\r\n      bcInitElement(handle003,\"120px\",\"60px\",\"yellow\",\"rgba(0,0,0,0)\",\"80px\",0,\"block\",\"This text grows in scale\");\r\n      \/\/handle003.style.transform = \"rotate(45deg) scale(0.5,0.5)\";\r\n      \/\/handle003.style.transform = \"rotate(45deg)\";\r\n      handle003.style.transform = \"scale(0.5,0.5)\";\r\n      addTransformToList(\"handle003\",0.05,{opacity:1.0},\"linear\",\"handle001:2-=0.05\");\r\n      addTransformToList(\"handle003\",1.50,{scale:\"(2.0,2.0)\"},\"linear\",\"+=0.50\");\r\n      addTransformToList(\"handle003\",0.00,{display:\"none\"});\r\n\r\n      var handle004 = document.getElementById(\"handle004\");\r\n      bcInitElement(handle004,\"80px\",\"70px\",\"orange\",\"rgba(0,0,0,0)\",\"140px\",0,\"block\",\"This text rotates into place\");\r\n      addTransformToList(\"handle004\",1.00,{opacity:1.0});\r\n      addTransformToList(\"handle004\",1.00,{rotate:\"-360\"},\"linear\",\"-=1.00\");\r\n<\/pre>\n<p>The animation works as expected.<\/p>\n<p><iframe loading=\"lazy\" width=\"330px\" height=\"480px\" src=\"https:\/\/www.rpchurchill.com\/demo\/animation\/animation_demo_20160706.html\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I added the capability of adding a rotation tween, which I applied to a fourth element at the end of the previous animation. The tween definition is here: function bcDefineRotateTween(sElement,pStart,pEnd,tBegin,tDuration,mMethod) { var s = sElement+&#8221;.style.transform=&#8217;rotate(&#8220;+pStart+&#8221;deg)&#8217;;&#8221;; var alpha = Math.round(tBegin &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/07\/06\/reproducing-a-clever-animation-product-part-20\/\">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\/861"}],"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=861"}],"version-history":[{"count":2,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":1442,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/861\/revisions\/1442"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}