开发者

Java AWT - Draw a Polygon connected by smooth curved lines

Here I am asking more silly graphics questions. Hopefully soon I will leave the world of graphics behind and plant myself firmly in the color-less middle-tier again. I have a newfound respect for people who are able to fiddle with images in pleasing ways through code.

That said, I am drawing a Polygon on a canvas. It can have an arbitrary number of points, but let's assume 12 for now. The polygon, as implemented, is connected via straight lines from point to point. I would like to apply some type of transformation so that the shape is drawn more 'naturally', as if someone had开发者_运维知识库 connected the points with a pen/pencil.

I'm not sure if this is too vague of a description. I think what I'm looking for is a bezier curve, but I'm a graphics (and geometry) slack-jaw. I'm interested in novel solutions in general, just something that makes a straight-sided polygon look more like a blob of ink. Maybe with controls to achieve a more or less 'natural' shape.

If you need any additional info, please don't hesitate to ask.

Kind thanks, Matt


To get started:
* create a GeneralPath
* add curves to the path using GeneralPath.curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
* get a Graphics2D object
* use Graphics2D.draw(Shape s) to draw the GeneralPath (which is a shape)

Optionally you can set the line cap and join style:
* Create a BasicStroke (width=1, cap=CAP_ROUND , join=JOIN_ROUND )
* use Graphics2D.setStroke to set the stroke

The only hard part is that you have to figure out the x3,y3 of the method curveTo


With a J2SE JVM you can cast any Graphics object to a Graphics2D object and then use this to draw Bezier lines.

See here for an example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜