tags:

views:

478

answers:

4

I'm capturing data from a tablet using Java (JPen library rocks) and would like to be able to paint a penstroke in a more natural way.

Currently I'm drawing the pen stroke as straight line segments each with a different Stroke thickness.

There has to be something in Java's Graphics Library that lets me to this more efficiently.

Right?

A: 

PostScript RIPs often convert circles to curves and curves to a series of straight line segments. The number of segments depends on the flatness setting which defaults to one suitable for the raster display resolution.

A thick line or thick line segments can be converted to a skinny filled polygon.

+1  A: 

I've never done this, but here are a couple things you could try. First, you could implement a custom Stroke that creates skinny trapezoids. The width of the end caps would be a function of the pressure at the end points. If that works, you could try to make the line segments look more natural by using Bezier curves to form "curvy trapezoids". You might be able to use QuadCurve2D to help.

Will
+1  A: 

I came across this page today. It's pretty much what I want, but I can't help but feel that there might be a "better" way of doing this that uses extends the classes in the Java2D Library. Something like "BendyPath" that extends GeneralPath or something.

http://forums.sun.com/thread.jspa?messageID=9679939

Allain Lalonde
+1  A: 

There's a more general solution available at least. The feature was added to Inkscape based on a recent algorithm. You can see it applied directly to your problem in some screenshots. It can extrude any shape brush along the path to mimic a paintbrush for example, but you'd have to port it to Java from the algorithm in the first link or from the Inkscape sources. Also, it's covered by patents so you'd have to release your code under the GPL (the author gives explicit permission) or buy a patent license.

jjrv