{"id":366,"date":"2009-08-04T09:42:32","date_gmt":"2009-08-04T16:42:32","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1906"},"modified":"2009-08-04T09:42:32","modified_gmt":"2009-08-04T16:42:32","slug":"twitter-texture-alphabet","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=366","title":{"rendered":"Twitter Texture Alphabet"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 1000, height=800, frameRate=60)]\r\n\r\n\/\/ if you don&#039;t have flex you&#039;ll need to embed this font in your library\r\n&#x5B;Embed(source=&quot;\/Library\/Fonts\/Verdana.ttf&quot;, fontFamily=&quot;Verdana&quot;)]\r\nvar Verdana:Class;\r\n\r\nvar canvas:BitmapData = new BitmapData(1000,800,false, 0xFFFFFF);\r\naddChild(new Bitmap(canvas));\r\nvar overlay:BitmapData = new BitmapData(1000,800,true, 0x01FFFFFF);\r\n \r\n\r\nvar txt:TextField = TextField(addChild(new TextField()));\r\nwith (txt){\r\n\tdefaultTextFormat = new TextFormat(&quot;Verdana&quot;, 10);\r\n\tembedFonts = true;\r\n\twidth = stage.stageWidth-20;\r\n\theight = stage.stageHeight-20;\r\n\tmultiline = true;\r\n\twordWrap = true;\r\n\ttext =&quot;&quot;;\r\n\ttextColor = 0x444444;\r\n\tselectable = false;\r\n\tx = y = 10;\r\n\ttext = &quot;loading...&quot;;\r\n}\r\n\r\n\r\nvar selectWords:Array = &#x5B;];\r\nvar currFirstLetter:String=&quot;&quot;;\r\nvar prevFirstLetter:String=&quot;&quot;;\r\nvar index:int = 0;\r\nvar anchorX:Number = 0, anchorY:Number = 0, theta:Number, radius:Number;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\t canvas.copyPixels(overlay, overlay.rect, new Point(0,0), null, null, true);\r\n\t var leng:int = selectWords.length;\r\n     if (leng &gt; 0){\r\n\t\t var word:String = selectWords&#x5B;index % leng];\r\n\t\t trace(word);\r\n\t\t currFirstLetter = word.charAt(0);\r\n\t\t if (currFirstLetter != prevFirstLetter){\r\n\t\t\t anchorX = Math.random() * (stage.stageWidth - 200) + 100\r\n\t\t\t anchorY = Math.random() * (stage.stageHeight - 200) + 100;\r\n\t\t\t theta = Math.random() * Math.PI * 2;\r\n\t\t\t radius = 50 + Math.random() * 100;\r\n\t\t\t txt.textColor = &#x5B;0,0xFFFFFF,0xCCCCCC,0x666666]&#x5B;int(Math.random()*4)];\r\n\t\t }else{\r\n\t\t\t txt.x = anchorX + radius * Math.cos(theta);\r\n\t\t\t txt.y = anchorY + radius * Math.sin(theta);\r\n\t\t\t theta += Math.random() * .1;\r\n\t\t\t radius += 3;\r\n\t\t\t txt.scaleX = txt.scaleY = 1 + Math.random();\r\n\t\t\t if (int(Math.random()*30) == 1) txt.scaleX = txt.scaleY = 1 + Math.random()*10;\r\n\t\t\t txt.rotation = theta \/ Math.PI * 180;\r\n\t\t\t txt.text = word;\r\n\t\t\t canvas.draw(txt, txt.transform.matrix);\r\n\t\t }\r\n\t\t prevFirstLetter = currFirstLetter;\r\n\t\t index++;\r\n\t }\r\n}\r\n\r\nvar loader:URLLoader = new URLLoader();\r\nvar req:URLRequest = new URLRequest(&quot;http:\/\/search.twitter.com\/search.atom&quot;);\r\nvar vars:URLVariables = new URLVariables();\r\nvars.q = &quot;alphabet&quot;;\r\n\/\/ results per page\r\nvars.rpp = &quot;100&quot;;\r\nvars.page = 1;\r\nvars.lang = &quot;en&quot;;\r\n\r\nreq.data = vars;\r\nreq.method = URLRequestMethod.POST;\r\nloader.load(req);\r\nloader.addEventListener(Event.COMPLETE, onLoaded);\t\t\t\t\t\t\t\t\t\r\nfunction onLoaded(evt:Event):void{\r\n\tvar searchData:XML = new XML(loader.data);\r\n\tvar atom:Namespace = searchData.namespace(&quot;&quot;);\r\n\tdefault xml namespace = atom;\r\n\tvar titles:String = &quot;&quot;;\r\n\tfor each(var entry:XML in searchData.entry){\r\n\t\ttitles += entry.title.toString();\r\n\t}\r\n\tvar index:int = 0;\r\n\tvar words:Array = titles.split(&quot; &quot;);\r\n\tfor (var i:int = 0; i&lt;words.length; i++){\r\n\t\t\/\/ exclude a few things\r\n\t\tif (words&#x5B;i].match(\/RT|@|#|http\/g).length == 0){\r\n\t\t\tselectWords&#x5B;index++] = words&#x5B;i].replace(\/s|r|n|&quot;\/g, &quot;&quot;);\r\n\t\t}\r\n\t}\r\n\tselectWords.sort();\r\n\ttxt.text =&quot;&quot;\r\n        removeChild(txt);\r\n}\r\n<\/pre>\n<p>This snippet draws a texture using a twitter search for the word &#8220;alphabet&#8221;. The results are arranged alphabetically and used to draw a texture.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/alphatwit.html\" target=\"blank\"><br \/>\nHave a look at the swf:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/alphatwit.jpg\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/alphatwit.swf&quot;,&quot;title&quot;:&quot;alphatwit&quot;,&quot;width&quot;:1000,&quot;height&quot;:800,&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\">: alphatwit<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 1000, height=800, frameRate=60)] \/\/ if you don&#039;t have flex you&#039;ll need to embed this font in your library &#x5B;Embed(source=&quot;\/Library\/Fonts\/Verdana.ttf&quot;, fontFamily=&quot;Verdana&quot;)] var Verdana:Class; var canvas:BitmapData = new BitmapData(1000,800,false, 0xFFFFFF); addChild(new Bitmap(canvas)); var overlay:BitmapData = new BitmapData(1000,800,true, 0x01FFFFFF); var txt:TextField = TextField(addChild(new TextField())); with (txt){ defaultTextFormat = new TextFormat(&quot;Verdana&quot;, 10); embedFonts = true; width = [&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,88,20,21],"tags":[3,14,4,128],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-external-data","category-string-manipulation","category-strings","tag-actionscript","tag-as3","tag-flash","tag-twitter"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/366","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=366"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}