为UML图创建“邋”“纸效果的算法?

时间:2009-09-17 06:26:52

标签: uml

我喜欢http://yuml.me UML图表的邋paper纸张效果,是否有一个算法,最好不要在Ruby中,但在PHP,java或C#中,我想看看是否很容易做同样的事情在REBOL:

http://reboltutorial.com/blog/easy-yuml-dialect-for-mere-mortals2/

1 个答案:

答案 0 :(得分:10)

效果结合

  • 对角渐变填充
  • 投影
  • 线条,而不是直线,在它们中有一些明显随机的偏差,这给人一种“邋'”的感觉。

您可以使用输入的哈希为随机数生成器设定种子,以便每次都获得相同的图像。

这似乎可以解决问题:

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

相关问题