base32 Twitter Coordinates

Actionscript:
  1. [SWF(width = 800, height=700, frameRate=30, backgroundColor=0x000000)]
  2. var canvas:BitmapData = new BitmapData(1000,800,false, 0x000000);
  3. addChild(new Bitmap(canvas));
  4.  
  5. var coords:String ="";
  6. var index:int = 0;
  7. addEventListener(Event.ENTER_FRAME, onLoop);
  8.  
  9. var s:Shape = new Shape();
  10. with (s.graphics) beginFill(0xFFFFFF, 0.3), drawCircle(4,4,4)
  11. var brush:BitmapData = new BitmapData(10,10, true, 0x00000000);
  12. brush.draw(s);
  13.  
  14. var pnt:Point = new Point();
  15. function onLoop(evt:Event):void {
  16.      if (coords.length> 0){
  17.          for (var i:int = 0; i<100;i++){
  18.              if (index <coords.length){
  19.                  pnt.x+= 0.2;
  20.                  pnt.y = parseInt(coords.substr(index,3), 32) / 2;
  21.                  index+=3;
  22.                  canvas.copyPixels(brush, brush.rect, pnt, null, null, true);
  23.              }else{
  24.                 break;
  25.                 removeEventListener(Event.ENTER_FRAME, onLoop);
  26.              }
  27.          }
  28.      }
  29. }
  30.  
  31. var loader:URLLoader = new URLLoader();
  32. var req:URLRequest = new URLRequest("http://search.twitter.com/search.atom");
  33. var vars:URLVariables = new URLVariables();
  34. vars.q = "as3, flash";
  35. vars.rpp = "100";
  36. vars.page = 1;
  37. vars.lang = "en";
  38. req.data = vars;
  39. req.method = URLRequestMethod.POST;
  40. loader.load(req);
  41. loader.addEventListener(Event.COMPLETE, onLoaded);
  42. function onLoaded(evt:Event):void{
  43.     var searchData:XML = new XML(loader.data);
  44.     var atom:Namespace = searchData.namespace("");
  45.     default xml namespace = atom;
  46.     var titles:String = "";
  47.     for each(var entry:XML in searchData.entry){
  48.         titles += entry.title.toString();
  49.     }
  50.     var index:int = 0;
  51.     var words:Array = titles.split(" ");
  52.     words.sort();
  53.     for (var i:int = 0; i<words.length; i++){
  54.         if (words[i].match(/RT|\@|\#|http/g).length == 0){
  55.             var word:String = words[i].replace(/[\W]/g, "");
  56.             if (word.length> 1){
  57.                 coords += word + " ";
  58.             }
  59.         }
  60.     }
  61. }

This snippet does a twitter search and sorts the results alphabetically. It then reads through the results 3 characters at a time - each set of 3 characters is converted to base32 and then used a y coordinate on a plot.

In order for the swf to be worth looking at, I think I'd need to add an input field. I may do that later... but for now here are a few stills:

This entry was posted in BitmapData, external data, string manipulation, strings and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted August 5, 2009 at 11:09 am | Permalink

    this is not really random, is it :)

  2. Posted August 5, 2009 at 12:30 pm | Permalink

    not very random… also I’m sorting the results - really has to do more with the frequency of certain combinations of letters occurring…

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*