Java - Drawing a dynamic shape outline

↘锁芯ラ 提交于 2019-12-25 12:43:16

问题


I wish to create a dynamic outline to a Shape (AWT) by adding objects (with draw functions) to appropriate positions on screen along the shape's perimeter. I want a roughly even distance between each object. (An alternative approach to the same affect will be fine.)

How might I acquire the locations for these objects? I know shapes have a path iterator, but I have no idea how to use it.


回答1:


You might look at a library such as the one described in A Shape Diagram Editor.

If you want to experiment, GraphPanel is a simple object drawing program that features moveable, resizable, colored nodes connected by edges. If the nodes were a little smaller, they'd be moveable points on a Shape that can be iterated as shown here for Polygon.

Addendum: I want a roughly even distance between each object.

The class Node exposes a number of static methods that operate on a List<Node> such as selected. Existing implementations serve, for example, to translate or resize multiple selections as a unit. Functions for Align and Distribute could be implemented similarly. I'd look at LayoutManger as an example for the latter.




回答2:


Use FlatteningPathIterator to get points for Shape's path.

Also you can use BasicStroke's method

public Shape createStrokedShape(Shape s)

to get Shape's outline with desire width.



来源:https://stackoverflow.com/questions/10678197/java-drawing-a-dynamic-shape-outline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!