gpt4 book ai didi

uml - 为 UML 图表创建 "scruffy"纸效果的算法?

转载 作者:行者123 更新时间:2023-12-04 17:28:53 24 4
gpt4 key购买 nike

我喜欢 http://yuml.me 的脏纸效果UML图,有没有一种算法最好不是在Ruby中,而是在PHP、java或C#中,我想看看在Rebol中做同样的事情是否容易:

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

    关于uml - 为 UML 图表创建 "scruffy"纸效果的算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1437019/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com