Embrace the timeline….

On creating rich, flashy and immersive advertising experiences online by Owen van Dijk

2.5D, world’s smallest cube?

with 9 comments

I remember when Wolfenstein came out, and was suddenly shooting night after night Nazi’s in Castle Wolfenstein. Graphics paling in comparison with today’s pixelpushing standards, but very addictive when it came to Gameplay. iD Software created a whole new market by distributing the game as shareware and it has sold over 250.000 copies of it.

As said, graphics were very pixelated, but the game would run fine on a 286 ( a 486 was top of the line ) and sound was awful ( but then again, what would you expect from 8bit soundcards ). The breakthrough was that this was the first game in the first person shooter genre. The game itself wasn’t really 3D, but it gave you the illusion you were really playing B.J. Blazkowicz, captured and trying to escape from Castle Wolfenstein. It was more 2.5D, since bullets were fired straight ahead with no illusion of depth. In fact there was no up and down at all, so that meant you could not jump or crawl. All items in the game would be displayed ‘en face’ no matter where you stood, so although it looked like 3D, it was not.

Now that’s all nice and all, but what does that have to do with this post? Recently i was challenged by several members of a dutch DHTML community to come up with the smallest version of a spinning 3D cube. Ofcourse, i couldn’t resist this challenge so i started working on a version and posting it to their online forum. For a couple of days it we posted our versions, 1,5k, 1,2k, 1k, 900bytes and so on. Finally they managed it to get it down to 598 bytes. I knew my reputation was at stake, so i had to make a smaller version. Leaving out the Z-axis would chop off some more bytes. So hold and below, my version came down to 555 bytes!

Thanks to Flasm, Peter Hall and Casper Schuirink for their help! Ofcourse, if you manage to find a way to get rid of some more bytes, please let me know, always interested.

Below is the code and the Flash file.

FAIL (the browser should render some flash content, not this).

Actionscript code:
while (i--) {
j[i] = [(i & 1)*100-50, (i >> 1 & 1)*100-50, (i >> 1 >> 1 & 1)*100-50];
attachMovie('d', i, i);
onEnterFrame = function() {
m += k=d ? (_ymouse-h)/2 : k*.99;
n += l=d ? (g-_xmouse)/2 : l*.99;
g = _xmouse;
h = _ymouse;
i = 8;
while (i--) {
C = j[i][2]*Math.cos(n*.017453)-j[i][0]*Math.sin(n*.017453);
D = 200/(j[i][1]*Math.sin(m*.017453)+C*Math.cos(m*.017453)+200);
with(eval(i)) {
_x = 200+D*(j[i][2]*Math.sin(n*.017453)+j[i][0]*Math.cos(n*.017453));
_y = 200+D*(j[i][1]*Math.cos(m*.017453)-C*Math.sin(m*.017453));
_width = _height=D*6.65+1;
onMouseDown = onMouseUp = function() {
d = !d;

Download the Flash source ( *.FLA, 28k )


Written by ohwhen

April 16, 2004 at 4:51 pm

Posted in Web/Tech

9 Responses

Subscribe to comments with RSS.

  1. I still have Wofenstein (and Spear of Destiny) around. It not only ran fine on a 286, it *required* at least a 286! If I remember correctly, I had a 386SX 20MHz machine at the time with a 40MB hardisk, 2MB Ram, 512KB VGA, both 5.25″ and 3.5″ drives but no sound card… Those were the days.

    Burak KALAYCI

    April 16, 2004 at 6:36 pm

  2. I remember playing Doom on my 25 MHz Packard Bell.. and reducing the screen size by 50% so the game would run fast. IDDQD anyone? Ah.. the memories.

    Nice post, by the way.


    April 16, 2004 at 11:06 pm

  3. Great job Owen … that’s a pretty damn small filesize for a 3D cube :p


    April 25, 2004 at 11:10 pm

  4. Wow that’s amazing, only managed to knock off 4bytes by removing the clip from the library and using:

    z = createEmptyMovieClip(i,i);

    Your code is surely too tight to knock off anymore!?!

    Richard Leggett

    May 6, 2004 at 9:10 pm

  5. Well, somehow on my machine the swf becomes bigger than 555 bytes when I publish your fla, so that probably accounts to your FLASM optimizations afterwards.

    But heres an ugly trick that brings me down to 547 bytes. Maybe you can squeeze that even more with some FLASM cosmetics:


    onEnterFrame = function () {
    m += k=d ? (_ymouse-h)/2 : k*.99;
    n += l=d ? (g-_xmouse)/2 : l*.99;
    g = _xmouse;
    h = _ymouse;
    i = 8;
    while (i–){
    with (attachMovie(‘d’, i, i, {j:[(i & 1)*100-50, (i >> 1 & 1)*100-50, (i >> 1 >> 1 & 1)*100-50]})) {
    C = j[2]*Math.cos(n*.017453)-j[0]*Math.sin(n*.017453);
    D = 200/(j[1]*Math.sin(m*.017453)+C*Math.cos(m*.017453)+200);
    _x = 200+D*(j[2]*Math.sin(n*.017453)+j[0]*Math.cos(n*.017453));
    _y = 200+D*(j[1]*Math.cos(m*.017453)-C*Math.sin(m*.017453));
    _width = _height=D*6.65+1;
    onMouseDown = onMouseUp=function () {
    d = !d;

    Mario Klingemann

    May 12, 2004 at 10:07 pm

  6. 413 bytes of AS code:



    November 12, 2005 at 7:36 pm

  7. hmmm, the same with cropped lines:



    November 12, 2005 at 7:37 pm

  8. It’s possible to further reduce the code size by optimizing the bit operations. Do you know how :)?


    November 13, 2005 at 4:49 pm

  9. I don’t know Flash from scratch (I’m a VB programmer) so I couldn’t modify this code if my life depended on it, but can someone post a version of this that doesn’t slow down after you “throw” it (if you know what I mean)?

    Email me at asmqb7 at gmail dot com if you want more info / have no idea what I mean.


    February 1, 2007 at 7:49 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: