Paint Algorithm for ActionScript

I bet you can’t fill the canvas with paint using the bad painting algorithm below (keep an eye on the frame rate counter). Now check out your paint skills using the good paint algorithm. What’s the difference? Check out the answer after the examples.

Bad Paint:

Alternate Page.

(pretend your cursor is a paint brush, click and drag around)

Good Paint:

Alternate Page.

(notice the fps counter in the top left)

I would like to start by pointing out that every Flash ‘paint’ example I found online uses lineTo. That’s fine if your just playing around but what if you want to use a more advanced painting algorithm? It looks MUCH better. Drawing a circle using the ‘lineTo’ method has noticeable rigid corners. Using a good painting algorithm allows for much smoother edges and more control: Safe from the Losing Fight – How to implement a basic bitmap brush.

Well my first implementation of a simple painting algorithm turned out really bad (bad paint above). Why? Two reasons. I was creating a new sprite and BitmapAsset for every circle added (thousands of circles eating up memory). In addition to that I was using my own painting algorithm which was just barely a step up from lineTo.

Benchmarks might be nice but in the end this is more of a memory issue than a performance one. The reason for the slowdown is the massive amount of Sprites / BitmapAssets on the canvas. By only using one BitmapAsset and one Sprite memory is no longer an issue for high volumes of paint. Slowdown occurs in the bad paint because of the massive volume of circles; not the power of the users computer.

The line drawing algorithm is just an appearance thing and does not have a significant effect on performance. Try drawing a circle on the bad paint (before the fps goes bad) than on the good paint. You’ll notice that the edges are much better on the good paint.

Interesting Chris. I’ve been searching the web for details of how to make a painting app in flash – this is a good bit of code to help and I’ll add it to my list… I’m not a coder really and struggle with programming. Would you be interested in helping me with a project?