#tweetcoding

About 3 weeks ago, Grant Skinner started an AS3 programming contest on Twitter. The idea is that you take 140 characters of “gimme” code, essentially a few function shortcuts with an enterFrame function to hold your code, and see what you can program in a single tweet.
Initially, most of the entries were automated line and shape visualizations, since most of the function shortcuts are for the Graphics class. I wanted to add a little more visual interest, as well as some user interaction. Here is what I ended up submitting as my first entry:
entry #1: leaky sunset
a=new BitmapData(2,400);a.perlinNoise(2,400,9,51,0,0);
g.beginBitmapFill(a);lt(1,0);lt(0,1);q=mouseX;w=mouseY;g.drawCircle(q,w,m.min(q,w)/9);
Next, I tried do something similar but using a bit less code:
entry #2: wheelix
q=mouseX;w=mouseY;ls(0,0,.1);mt(q,w);lt(0,0);
g.beginFill(r()*1e7,.1);g.drawCircle(q,w,r()*20);rotationZ+=4;
After taking a break from what had become an addicting little challenge, Shelby suggested making something that would print, so I threw one last entry together. It’s a simple drawing application that will automatically print once a bunch of circles are drawn. Just let your mouse do the talking:
entry #3: dotprint
if(i++<99){g.beginFill(r()*1e7);g.drawCircle(mouseX,mouseY,99-i)
}else if(i==99){var p=new PrintJob();p.start();p.addPage(this);p.send()};
It’s fun to see just how much you can get out of 140 characters. There are a handful of tricks to save every last character: using 9 instead of 10, 99 instead of 100, almost completely ignoring memory management, shortening color values to exponents (1e7 instead of 0xFFFFFF), boolean shorthand if(!i++), modulus, ternary conditionals, etc. The cooler something is, the less likely it is to be readable, for instance:
for(g.clear();j=i++%300;ls(0))with(o[j]=o[j]?o[j]:new Matrix)mt(b,c),
u=b-mouseX,v=c-mouseY,t=-m.pow(u*u+v*v,-.7)*r(),lt(b+=a+=u*t,c+=d+=v*t)
renders a flock of pixels that follow your mouse around… pretty rad if you ask me.
If you’re interested in learning more, here are the official tweetcoding rules, complete list of entries, and a bit more about the story behind tweetcoding.
Comments(1)
You are awesome. That is all.