This models a few different implementations of the TextEffect class.
The following code creates a simple animation that repeats from 0% to 100% every one second (assuming you continually repaint):
TextEffect effect = new PunchTextEffect(font, text, width, height, fillColor, shadowColor); float fraction = ((float)(System.currentTimeMillis()%1000)) / 1000f; effect.paint(g, fraction);
The TextEffect interface is roughly modeled after the Transition interface:
/** This is a common interface for visual text effects. */
public interface TextEffect {
/**
* Paint this effect.
*
* @param g
* the Graphics2D to paint to.
* @param fraction
* a float from [0, 1] indicating how
* far along this effect it.
*/
public void paint(Graphics2D g, float fraction);
/**
* An optional method to retrieve the preferred size.
* May return null.
*/
public Dimension getPreferredSize();
}
These effects started with the CalligraphyStroke. That stroke helped make easy work of the BlockLetter class, which is used to add a simple 3D-ish depth to letters (as seen in the punch and explode effects).
The outline effect uses the Scribbler class to add a little chaos into the mix.
The writing effect is a complete departure from everything else. This uses a WritingFont object, which is a font rendered with a constant java.awt.Stroke where the order of each stroke is preserved. This has to be input by hand (I wrote a special editor app to design these). So far I've implemented one font based on Comic Neue, and another based on some simple calligraphic tutorials.
All of these ‐ especially the writing fonts ‐ can be improved. To date I haven't deployed these in a commercial project, though, so they're low on my priority list. I have, however, implemented a set of text effect animations for a commercial product (flying in text, flipping text, etc.), but that code/project is not open source.