It’s done! Finally! My entry for the Mix09 10k Challenge is submitted. Drag your mouse on the area surrounding the cube to rotate the entire cube. Click the cube itself to turn the sides of the cube.

From the moment I got notice of this challenge I thought of doing something in 3D. I decided to build a Rubik’s Cube. I started out with the classes to make the 3D possible. To do this, I made a Vector3D class for position all vertices in the 3D world and a Matrix3D class for doing the rotations. Next stop is the Poly3D class. This class is for creating the colored faces of the cube. Before the optimizations it took care of the rotation and the drawing of the faces. Each Poly3D has 4 corners, that are positioned in 3D space. Than each 3D position of those corners is calculated to a 2D screen position and added as a Point of a standard Silverlight Poly. This Poly is drawn onto a Canvas. The Z-Index of the Canvas is moved to the average Z-position of the face and it’s ready to be drawn on the main canvas. After the contest is over, I probably go in much greater detail on how this works.
After going all crazy on the functions to calculate the cube and handling the mouse events, I removed everything the compiler didn’t need and ended up with a small application of 7.5k. Awesome. But if I could do that in so little space, what can be done with the 2.5k that’s left? At that point the application was black and showed only a rotating cube.
I added the background, the title and better animations for the turning sides. Great. But after a few hours optimizing the code again, I got an app of 8.5k.
I needed to do something better. I thought I may look cool to show the amount of moves and the time the user was playing, but not in a regular font. Digital 7-Led look was the way I wanted this to work. So I added a class that converts an integer to a “7-Led-integer”.
At this point my unoptimized code was about 21k. Before, every optimization shrunk the application about 45% in size. And that wasn’t enough enymore. After a bit of puzzling and examining the code I came up with a few more ways to optimize and was able to shrink it down to 10,130 bytes. Which is 110 bytes under 10k.
So, now go check it out and vote. Thanks!