Charles Petzold

Animated Drawing Brushes

July 23, 2006
Roscoe, NY

A WPF DrawingBrush is usually a tiled composition of GeometryDrawing objects. The geometries that make up these GeometryDrawing objects can be animated, which makes all the tiles of the brush animated, which is a rather frightening thought. Should it be done at all? The nihilist says Yes, the moralist says No, and the programmer can't wait to try it out.

In this first example, the geometry that defines the brush is merely a simple straight line, which is continuously rotated. By default, a geometry that forms the basis of a DrawingBrush is expanded or compressed to fill the whole tile, which is defined by the Viewport property as 25 units square. This means that when the line is exactly horizontal or vertical, the line's width is expanded to 25 units, and it fills the tile. The effect is very odd.


You can prevent this expansion and contracton of geometries in a couple ways. The next program uses a Viewbox to define the total dimensions of a rotating triangle. However, as the triangle rotates, it's often clipped to this Viewbox, which results in the image in each tile merging with its neighbors.


Finally, here's a rotating spiral, but I've also animated the Viewport so the whole brush seems to flow from upper-left to lower-right.


All these files might run more smoothly if you restrict the size of your browser window.