{"id":357,"date":"2009-07-26T11:49:27","date_gmt":"2009-07-26T18:49:27","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1841"},"modified":"2009-07-26T11:49:27","modified_gmt":"2009-07-26T18:49:27","slug":"wave-trick","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=357","title":{"rendered":"Wave Trick"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=800, height=600)]\r\nvar dupes:int = 5\r\nvar pntNum:int = 180;\r\n\r\nvar hh:Number = stage.stageHeight \/ 2;\r\nvar points:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar vel:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar cmds:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();\r\nvar vectors:Vector.&lt;Shape&gt; = new Vector.&lt;Shape&gt;();\r\n\r\nfor (var i:int = 0; i&lt;dupes; i++){\r\n\tvectors&#x5B;i] = Shape(addChildAt(new Shape(),0));\r\n\tvectors&#x5B;i].x = 10 * i;\r\n\tvectors&#x5B;i].y = -10 * i;\r\n}\r\nvar index:int = 0;\r\nfor (i = 0; i&lt;pntNum; i++){\r\n\tpoints&#x5B;index++] = 10 + i * 4;\r\n\tpoints&#x5B;index++] = hh;\r\n\tcmds&#x5B;i] = 2;\r\n\tvel&#x5B;i] = 0;\r\n}\r\ncmds&#x5B;0] = 1;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\t\r\n   index = 1;\r\n   points&#x5B;index] += (mouseY - points&#x5B;index]) \/ 12;\r\n   for (var i:int = 3; i&lt;points.length; i+=2){\r\n         points&#x5B;i] += vel&#x5B;index];\r\n\t\t vel&#x5B;index] += ((points&#x5B;i] - points&#x5B;i - 2]) * -0.16 - vel&#x5B;index]) \/ 4;\r\n\t\t index++;\r\n   }\r\n   for (i = 0; i&lt;dupes; i++){\r\n\t   var c:uint =  255 - 255 \/ i;\r\n\t   with (vectors&#x5B;i].graphics){\r\n\t\t   clear();\r\n\t\t   lineStyle(0,c &lt;&lt; 16 | c &lt;&lt; 8 | c);\r\n\t\t   drawPath(cmds, points);\r\n\t   }\r\n   }\r\n}\r\n<\/pre>\n<p>This snippet uses elasticity to create an interesting wave effect. I first stumbled upon this technique back in my director days&#8230;<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/ewave.html\" target=\"blank\"><br \/>\nHave a look at the swf here&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/wave.jpg\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/ewave.swf&quot;,&quot;title&quot;:&quot;ewave&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: ewave<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=800, height=600)] var dupes:int = 5 var pntNum:int = 180; var hh:Number = stage.stageHeight \/ 2; var points:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var vel:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var cmds:Vector.&lt;int&gt; = new Vector.&lt;int&gt;(); var vectors:Vector.&lt;Shape&gt; = new Vector.&lt;Shape&gt;(); for (var i:int = 0; i&lt;dupes; i++){ vectors&#x5B;i] = Shape(addChildAt(new Shape(),0)); vectors&#x5B;i].x = 10 * i; vectors&#x5B;i].y = -10 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,13,79],"tags":[3,14,4],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-graphics","category-motion","category-vector","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}