Next post: Game For OLPC

MS Paint Animation

I gave MS Paint the ability to make animations and save them as .avi files.

I wanted to write a "flipbook" program, where you could draw a series of frames and create a simple animation. I think this type of program could be fun for kids.

See the video:

I was about to write the program in Pygame, but found myself re-implementing many of the standard bitmap editing tools. It's easy to make a rectangle and oval tool, but I didn't really feel like making the fill tool or selection tool. So, instead, I used MSPaint as part of the interface to the program. (This is completely a hack, and the resulting program isn't robust, but it was kind of interesting to do).

I'm trying to make this look like just one program, but a lot is going on behind the scenes. The program is a c# app that, first, launches Paint. It has a window style that causes it to be on top of other windows. The program uses many Windows API SendKey calls to send key events to Paint. When you move from one frame to the next, it does the following:
  • Tell paint to select all (Ctrl A), and cut (Ctrl X)
  • Take that image from the clipboard and save it to a .png file
  • Open the next .png file in memory and put it in clipboard
  • Tell paint to paste (Ctrl V) and deselect (Esc)
The other operations are done with a similar series of events. I had to tune the timing; the c# program sleeps while waiting for Paint. The play preview actually opens up a borderless c# window that is positioned so that it appears above the image, and cycles through the images.

It ended up working. Sometimes it's like the Windows API gives you almost too much to play with.