{"id":177,"date":"2009-02-04T00:00:16","date_gmt":"2009-02-04T07:00:16","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=686"},"modified":"2009-02-04T00:00:16","modified_gmt":"2009-02-04T07:00:16","slug":"visualizing-binary-numbers-2","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=177","title":{"rendered":"Visualizing Binary Numbers Part 2"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=900,height=390,backgroundColor=0x000000,frameRate=30)]\r\n\r\nvar canvas:BitmapData=new BitmapData(4,8,false,0xFFFFFFFF);\r\nvar pixNum:int = canvas.width * canvas.height;\r\n\r\nvar frame:Bitmap = Bitmap(addChild(new Bitmap(canvas)));\r\nframe.scaleX = frame.scaleY = canvas.width * 10;\r\nframe.x = stage.stageWidth \/ 2 - frame.width \/ 2;\r\nframe.y =20;\r\n\r\nvar txt:TextField = TextField(addChild(new TextField()));\r\ntxt.autoSize = TextFieldAutoSize.LEFT;\r\ntxt.defaultTextFormat = new TextFormat(&quot;Verdana&quot;, 8, 0xFFFFFF);\r\ntxt.x = frame.x - 3;\r\ntxt.y = frame.y + frame.height + 10;\r\n\r\nvar s:String, a:Number = 0, d:Number = 0;\r\nvar r:Number = 0xFFFFFFFF \/ (stage.stageWidth-20) ;\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\t a  += (d - a) \/ 8;\r\n\t  \r\n\t d = (mouseX-10) * r;\r\n\t \r\n\t s = Math.max(0,Math.min(0xFFFFFFFF, a)).toString(2);\r\n\t\r\n\t if (s.length &lt; pixNum){\r\n\t\twhile(s.length-1 &lt; pixNum){\r\n\t\t\ts = &quot;0&quot; + s;\r\n\t\t}\r\n\t }\r\n\t \r\n\t txt.text = s;\r\n\t\r\n\tcanvas.lock();\r\n\tcanvas.fillRect(canvas.rect, 0xFFFFFF);\r\n\tfor (var i:int = 0; i&lt;pixNum; i++){\r\n\t\tif (s.charAt(i) == &quot;0&quot;){\r\n\t\t\tcanvas.setPixel(i % 4,  i \/ 4, 0x000000);\r\n\t\t}\r\n\t}\r\n\tcanvas.unlock();\r\n}\r\n<\/pre>\n<p>Similar to yesterdays post&#8230; this snippet visualizes binary numbers. Move your mouse left and right to change the value of the number that&#8217;s being displayed. <\/p>\n<p>Here are a few stills:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/binlog1.jpg\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/binlog2.jpg\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/binlog3.jpg\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/binlog4.jpg\" \/><\/p>\n<p>This code uses the mouse position to choose which binary number to display. Going all the way to the left of the screen will set this number to 0 and going all the way to the right will set it to 4294967295&#8230; that number may look arbitrary unless you see it in in binary 11111111111111111111111111111111 or in hexadecimal 0xFFFFFFFF.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=900,height=390,backgroundColor=0x000000,frameRate=30)] var canvas:BitmapData=new BitmapData(4,8,false,0xFFFFFFFF); var pixNum:int = canvas.width * canvas.height; var frame:Bitmap = Bitmap(addChild(new Bitmap(canvas))); frame.scaleX = frame.scaleY = canvas.width * 10; frame.x = stage.stageWidth \/ 2 &#8211; frame.width \/ 2; frame.y =20; var txt:TextField = TextField(addChild(new TextField())); txt.autoSize = TextFieldAutoSize.LEFT; txt.defaultTextFormat = new TextFormat(&quot;Verdana&quot;, 8, 0xFFFFFF); txt.x = frame.x &#8211; 3; txt.y = frame.y [&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,26],"tags":[3,4],"class_list":["post-177","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-setpixel","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/177","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=177"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}