我喜歡的http://yuml.me UML圖的邋遢紙效果,是有其優選不是在Ruby,但在PHP中的算法,Java或C#,我想看看是否可以很容易地做同樣的事情在雷博爾:爲UML圖創建「sc」「紙效果的算法?
http://reboltutorial.com/blog/easy-yuml-dialect-for-mere-mortals2/
我喜歡的http://yuml.me UML圖的邋遢紙效果,是有其優選不是在Ruby,但在PHP中的算法,Java或C#,我想看看是否可以很容易地做同樣的事情在雷博爾:爲UML圖創建「sc」「紙效果的算法?
http://reboltutorial.com/blog/easy-yuml-dialect-for-mere-mortals2/
效果結合
您可以使用輸入的哈希種子的隨機數生成器,所以你每次都得到相同的圖像。
這似乎爲潔膚達線工作確定:
public class ScruffyLines {
static final double WOBBLE_SIZE = 0.5;
static final double WOBBLE_INTERVAL = 16.0;
Random random;
ScruffyLines (long seed) {
random = new Random(seed);
}
public Point2D.Double[] scruffUpPolygon (Point2D.Double[] polygon) {
ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
Point2D.Double prev = polygon[0];
points.add (prev); // no wobble on first point
for (int index = 1; index < polygon.length; ++index) {
final Point2D.Double point = polygon[index];
final double dist = prev.distance (point);
// interpolate between prev and current point if they are more
// than a certain distance apart, adding in extra points to make
// longer lines wobbly
if (dist > WOBBLE_INTERVAL) {
int stepCount = (int) Math.floor (dist/WOBBLE_INTERVAL);
double step = dist/stepCount;
double x = prev.x;
double y = prev.y;
double dx = (point.x - prev.x)/stepCount;
double dy = (point.y - prev.y)/stepCount;
for (int count = 1; count < stepCount; ++count) {
x += dx;
y += dy;
points.add (perturb (x, y));
}
}
points.add (perturb (point.x, point.y));
prev = point;
}
return points.toArray (new Point2D.Double[ points.size() ]);
}
Point2D.Double perturb (double x, double y) {
return new Point2D.Double (
x + random.nextGaussian() * WOBBLE_SIZE,
y + random.nextGaussian() * WOBBLE_SIZE);
}
}
example scruffed up rectangle http://img34.imageshack.us/img34/4743/screenshotgh.png
非常感謝你,你是一個真正的! – 2009-09-17 19:25:12
+1不錯的網站/鏈接,看起來很方便:) – leppie 2009-09-17 06:41:50
訪問您的項目:哇,我很驚訝。你會在你的IDE中包含Rebol;) – 2009-09-17 19:22:56