{"id":213,"date":"2011-03-07T19:46:19","date_gmt":"2011-03-07T18:46:19","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=213"},"modified":"2011-03-07T21:12:19","modified_gmt":"2011-03-07T20:12:19","slug":"playing-with-blend-mode","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/playing-with-blend-mode\/","title":{"rendered":"Playing with Blend Mode"},"content":{"rendered":"<p>Recently, I tried some BlendMode in AS3. Thanks to them we can reproduce some cool effects of Photshop.<br \/>\nThis is a simple script to do <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2011\/03\/MouseFollower.swf\" rel=\"lightbox[flash 600 500]\"><strong>that<\/strong><\/a>. I thought it&#8217;s a nice effect !<\/p>\n<pre lang=\"actionscript3\" line=\"1\">package {\r\n\r\n\timport flash.display.Bitmap;\r\n\timport flash.display.BitmapData;\r\n\timport flash.display.BlendMode;\r\n\timport flash.display.Shape;\r\n\timport flash.display.Sprite;\r\n\timport flash.events.Event;\r\n\timport flash.filters.BlurFilter;\r\n\timport flash.geom.Point;\r\n\t\r\n\t[SWF(backgroundColor=\"#000000\", frameRate=\"31\", width=\"600\", height=\"500\")]\r\n\t\r\n\t\/**\r\n\t * @author Aymeric\r\n\t *\/\r\n\t\r\n\tpublic class MouseFollower extends Sprite {\r\n\t\t\r\n\t\tprivate var _container:Sprite;\r\n\t\t\r\n\t\tprivate var _bData:BitmapData;\r\n\t\tprivate var _img:Bitmap;\r\n\t\tprivate var _circle:Shape;\r\n\t\t\r\n\t\tpublic function MouseFollower() {\r\n\t\t\t\r\n\t\t\t_container = new Sprite();\r\n                        _container.visible = false;\r\n\t\t\tthis.addChild(_container);\r\n\t\t\t\r\n\t\t\t_bData = new BitmapData(600, 500, true, 0x00FF00);\r\n\t\t\t\r\n\t\t\t_img = new Bitmap(_bData);\r\n\t\t\t\r\n\t\t\t_circle = new Shape();\r\n\t\t\t\r\n\t\t\tthis.addChild(_img);\r\n\t\t\t\r\n\t\t\t_container.addChild(_circle);\r\n\t\t\r\n\t\t\tthis.addEventListener(Event.ENTER_FRAME, _ef);\r\n\t\t}\r\n\t\t\r\n\t\tprivate function _ef(evt:Event):void {\r\n\t\t\t\r\n\t\t\t_circle.graphics.clear();\r\n\t\t\t_circle.graphics.beginFill(Math.random()*0xFFFFFF);\r\n\t\t\t_circle.graphics.drawCircle(0, 0, 10);\r\n\t\t\t_circle.graphics.endFill();\r\n\t\t\t\r\n\t\t\tvar diffx:int =\tmouseX - _circle.x;\r\n\t\t\tvar diffy:int = mouseY - _circle.y;\r\n\t\t\t\r\n\t\t\t_circle.x +=diffx * 0.05;\r\n\t\t\t_circle.y +=diffy * 0.05;\r\n\t\t\t\r\n\t\t\t_bData.draw(_container, null, null, BlendMode.ADD);\r\n\t\t\t_bData.applyFilter(_bData, _bData.rect, new Point(), new BlurFilter(5, 5, 2));\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>This two lines are important if you want to keep an eye on your CPU usage :<br \/>\n_circle.graphics.clear();<br \/>\n_circle.graphics.endFill();<br \/>\nBlendMode are more than ever CPU&#8217;s eater ! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I tried some BlendMode in AS3. Thanks to them we can reproduce some cool effects of Photshop. This is a simple script to do that. I thought it&#8217;s a nice effect ! package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; import flash.filters.BlurFilter; import flash.geom.Point; [SWF(backgroundColor=&#8221;#000000&#8243;, frameRate=&#8221;31&#8243;, width=&#8221;600&#8243;, height=&#8221;500&#8243;)] &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/playing-with-blend-mode\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Playing with Blend Mode<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4,33],"tags":[20,15,38,34],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/213"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":8,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":221,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions\/221"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}