{"id":267,"date":"2009-04-27T18:28:32","date_gmt":"2009-04-28T01:28:32","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1236"},"modified":"2009-04-27T18:28:32","modified_gmt":"2009-04-28T01:28:32","slug":"random-walk-texture","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=267","title":{"rendered":"Random Walk Texture"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\npackage {\r\n\r\n\t&#x5B;SWF(width=1000,height=1000)]\r\n\timport flash.display.*;\r\n\timport flash.events.*;\r\n\tpublic class RandomWalkTexture extends Sprite {\r\n\r\n\t\tprivate var _canvas:BitmapData;\r\n\t\tprivate var _populationNum:int=100;\r\n\t\tprivate var _movers:Vector.&lt;Mover&gt;;\r\n\t\tpublic function RandomWalkTexture() {\r\n\t\t\tvar sw:Number=stage.stageWidth;\r\n\t\t\tvar sh:Number=stage.stageHeight;\r\n\t\t\tscaleX=scaleY=.25;\r\n\t\t\t_canvas=new BitmapData(sw*4,sh*4,false,0x000000);\r\n\t\t\taddChild(new Bitmap(_canvas));\r\n\t\t\t\r\n\t\t\t_movers = new Vector.&lt;Mover&gt;();\r\n\t\t\tfor (var i:int = 0; i&lt;_populationNum; i++) {\r\n\t\t\t\t_movers&#x5B;i]=new Mover(_canvas,sw*1.5+Math.random()*sw,sh*1.5+Math.random()*sh);\r\n\t\t\t}\r\n\t\t\taddEventListener(Event.ENTER_FRAME, onRun);\r\n\t\t}\r\n\t\tprivate function onRun(evt:Event):void {\r\n\t\t\tfor (var i:int = 0; i&lt; 200; i++) {\r\n\t\t\t\tfor (var j:int = 0; j&lt;_populationNum; j++) {\r\n\t\t\t\t\t_movers&#x5B;j].run();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\nimport flash.display.BitmapData;\r\nclass Mover {\r\n\tpublic var x:Number;\r\n\tpublic var y:Number;\r\n\tpublic var velX:Number;\r\n\tpublic var velY:Number;\r\n\tpublic var speed:Number;\r\n\tprivate var _canvas:BitmapData;\r\n\r\n\tpublic function Mover(canvas:BitmapData, xp:Number, yp:Number) {\r\n\t\t_canvas=canvas;\r\n\t\tx=xp;\r\n\t\ty=yp;\r\n\t\tvelX=0;\r\n\t\tvelY=0;\r\n\t\tspeed=Math.random()*5-2.5;\r\n\t}\r\n\tpublic function run():void {\r\n\t\tx+=velX;\r\n\t\ty+=velY;\r\n\t\t_canvas.setPixel(x, y, 0xFFFFFF);\r\n\t\tvar dir:Number=int(Math.random()*4);\r\n\t\tif (dir==0) {\r\n\t\t\tvelX=0;\r\n\t\t\tvelY=- speed;\r\n\t\t} else if (dir == 1) {\r\n\t\t\tvelX=0;\r\n\t\t\tvelY=speed;\r\n\t\t} else if (dir == 2) {\r\n\t\t\tvelX=- speed;\r\n\t\t\tvelY=0;\r\n\t\t} else if (dir == 3) {\r\n\t\t\tvelX=speed;\r\n\t\t\tvelY=0;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>This snippet is meant to be run as a document class. Nothing special here&#8230; this is just something I found laying around &#8211; the actual bitmap being drawn is rather big, so I recommending right clicking (control clicking on mac) on the swf and to zoom in and out.<\/p>\n<p>Here are a few images:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/rwalk_1.gif\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/rwalk_2.gif\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/rwalk_3.gif\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/rwalk_4.gif\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>package { &#x5B;SWF(width=1000,height=1000)] import flash.display.*; import flash.events.*; public class RandomWalkTexture extends Sprite { private var _canvas:BitmapData; private var _populationNum:int=100; private var _movers:Vector.&lt;Mover&gt;; public function RandomWalkTexture() { var sw:Number=stage.stageWidth; var sh:Number=stage.stageHeight; scaleX=scaleY=.25; _canvas=new BitmapData(sw*4,sh*4,false,0x000000); addChild(new Bitmap(_canvas)); _movers = new Vector.&lt;Mover&gt;(); for (var i:int = 0; i&lt;_populationNum; i++) { _movers&#x5B;i]=new Mover(_canvas,sw*1.5+Math.random()*sw,sh*1.5+Math.random()*sh); } addEventListener(Event.ENTER_FRAME, onRun); } private function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94],"tags":[3,4],"class_list":["post-267","post","type-post","status-publish","format-standard","hentry","category-misc","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/267","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=267"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}