{"id":176,"date":"2009-02-03T00:00:47","date_gmt":"2009-02-03T07:00:47","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=683"},"modified":"2009-02-03T00:00:47","modified_gmt":"2009-02-03T07:00:47","slug":"visualizing-numbers","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=176","title":{"rendered":"Visualizing Binary Numbers"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=320,height=512,backgroundColor=0x000000,frameRate=30)]\r\n\r\nvar canvas:BitmapData=new BitmapData(32,512,false,0xFFFFFF);\r\naddChild(new Bitmap(canvas)).scaleX = 10;\r\n \r\nvar a:uint ;\r\nvar s:String;\r\nvar m:Number = 0;\r\nvar d:Number = 0;\r\nvar mi:int ;\r\nvar r:Number = 0xFFFFFF \/ stage.stageWidth;\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\n\r\nfunction onLoop(evt:Event):void {\r\n\t\r\n\td = mouseX * r;\r\n\tm += (d - m) \/ 30;\r\n\t\r\n\tmi = int(m);\r\n\r\n    canvas.lock();\r\n\tcanvas.fillRect(canvas.rect, 0xFFFFFF);\r\n\r\n    a = 0xFFFFFFFF;\r\n\tfor (var i:int = 0; i&lt;512; i++) {\r\n\t\ts = (a -= mi).toString(2);\r\n\t\tfor (var j:int = 0; j&lt;s.length; j++) {\r\n\t\t\tif (s.charAt(j)==&quot;0&quot;) {\r\n\t\t\t\tcanvas.setPixel(j, i, 0x000000);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tcanvas.unlock();\r\n}\r\n<\/pre>\n<p>The above uses setPixel() to visualize numbers in binary format. You can move your mouse left and right to change an incremental counting value&#8230;.<\/p>\n<p>Here&#8217;s a still generated by this snippet:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/binv2.jpg\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=320,height=512,backgroundColor=0x000000,frameRate=30)] var canvas:BitmapData=new BitmapData(32,512,false,0xFFFFFF); addChild(new Bitmap(canvas)).scaleX = 10; var a:uint ; var s:String; var m:Number = 0; var d:Number = 0; var mi:int ; var r:Number = 0xFFFFFF \/ stage.stageWidth; addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { d = mouseX * r; m += (d &#8211; m) \/ 30; mi = int(m); canvas.lock(); canvas.fillRect(canvas.rect, 0xFFFFFF); a = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,94,25],"tags":[3,4],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-misc","category-pixel-manipulation","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/176","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=176"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}