0

Some paint programs like Manga Studio include brushes that taper down to a point at the ends of the stroke. I have a few ideas about how this could be implemented, but the ideas I have seem problematic / inefficient to me... I haven't been able to find any information about this task via Google, so thought I'd ask here.

Does anyone know of any algorithms for creating a tapered stroke in AWT?

What I need to figure out is how to convert the mouse coordinates I already have from mouse events for example (x50,y50)-(x37,y20)-(x47,y10) into arguments for Path2D.curveTo() or something of that nature. How do you do the math for tapering the stroke? (I don't imagine there's any way to do this without a fair amount of math... though I suppose I could be wrong.)

Thanks!

Edit: Note that a user is allowed to draw freehand onto an image using this stroke, which means the sides of the stroke must curve to match the user's pen.

Sam Dealey
  • 371
  • 4
  • 10

1 Answers1

1

Polygon is a good choice. As is implements the Shape interface, createStrokedShape() is available, as shown here. An AffineTransform may be applied to rotate, translate or scale the object, as shown here and here. The examples may help you judge performance.

Addendum: Although I haven't tried it, Arc2D may be an reasonable alternative to rotating a Polygon. A related QuickDraw primitive once gave the venerable MacDraw a distinctive shape for arrowheads.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks. Unfortunately this doesn't really help in my situation. This is an interface where a user is allowed to draw freehand onto an image, so the sides of the stroke have to curve, which makes any direct use of Polygon a non-option. I suppose I could use a polygon with extra points as a base and then copy each point and rotate it according to the location of the next freehand drawing point before adding it to a Path2D, but that puts me back at the beginning with what seem like very complicated, possibly inefficient solutions. – Sam Dealey Sep 15 '11 at 13:40
  • You can use any [`Shape`](http://download.oracle.com/javase/7/docs/api/java/awt/Shape.html), perhaps one of the paths or curves. – trashgod Sep 15 '11 at 15:38
  • It's not really "which objects" that's the problem... I'm using all kinds of shape objects already and have implemented brushes using Path2D. But that doesn't answer the question of how to efficiently calculate / plot the curves involved in tapering the stroke. What I need is in Path2D.curveTo(x1, y1, x2, y2) -- how do I convert the mouse coordinates I have to arguments in the curveTo method? That may not be the right method -- it may be cubeTo or quadTo, but it's the math that's my challenge. Thanks for the suggestions, tho! :D – Sam Dealey Sep 16 '11 at 04:01
  • Anything [here](http://stackoverflow.com/questions/7443212/drawing-curve-bit-by-bit/7443911#7443911) you can use? – trashgod Sep 16 '11 at 14:48
  • Thanks man! That's headed in the right direction... but I'm kinda tired right now & can't tell if any of that will be useful at first glance... I'll have to have a better look at it when I've had some sleep. – Sam Dealey Sep 17 '11 at 04:32
  • Kudos to @mKorbel for archiving examples such as these; I would welcome his perspective. – trashgod Sep 17 '11 at 11:55