Sunday 7 September 2008

Some Super-Shiny Square-Scaling!

Today, I present to you the result of much mathematical fiddling and error-induced pain. I have been working on the image gallery program I fell short of properly describing in the last post, and have created a system that displays a grid of images (white squares at the moment) which scale up as your mouse approaches. In the final program, the grid of images will also scroll with your mouse cursor, but that will be added later. For now, bask in the awesomeness of the algorithm I like to call "SSSSSS" (Specialised System for Super-Shiny Square Scaling):


If you like, you can take a look at the source code for this at http://pasteall.org/2333/python. However, it must be noted that the code is uncommented and incredibly messy, so I wouldn't advise trying to understand it.

The basic scaling algorithm is as follows:
Mx = Mouse x-position

My = Mouse y-position
Cx = Centre of the tile (x-axis)
Cy = Centre of the tile (y-axis)

Tx = Tile size (x-axis)
Ty = Tile size (y-axis)


Click on the image to view it full-size as always.
As you can see, the scale factor must be in range 1.0 <= x <= 2.0, so it's necessary to also add code that clips the scale factor at these values.
This is probably going to get a lot more complicated when I add scrolling...


Anyway, that's all for this update. Watch this space for more soon!

No comments:

Post a Comment