Algorithmus einen „vergammelt“ Papier-Effekt für UML-Diagramme zu erstellen?

StackOverflow https://stackoverflow.com/questions/1437019

  •  08-07-2019
  •  | 
  •  

Frage

Ich mag den maroden Papiereffekt von http://yuml.me UML-Diagramme, gibt es einen Algorithmus für diese vorzugsweise in Ruby nicht aber in PHP, Java oder C #, würde ich gerne sehen, wenn es einfach ist, die gleiche Sache in Rebol zu tun:

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

War es hilfreich?

Lösung

Die Wirkung kombiniert

  • eine diagonale Verlaufsfüllung
  • ein Schlagschatten
  • Linien, die, anstatt gerade, in ihnen ein paar kleine scheinbar zufällige Abweichungen aufweisen, die eine ‚vergammelt‘ gibt das Gefühl.

Sie können Ihren Zufallszahlengenerator mit einem Hash-Wert der Eingabe-Samen, so dass Sie das gleichen Bild jedes Mal bekommen.

Dies scheint für scruffing up-Linien OK zu arbeiten:

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 );
    }
}

Beispiel scruffed up Rechteck http://img34.imageshack.us/img34/4743/screenshotgh.png

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top