문제
나는 멍청한 종이 효과를 좋아합니다 http://yuml.me UML 다이어그램, Ruby가 아니라 PHP, Java 또는 C#에 대한 알고리즘이 있습니까? REBOL에서 같은 일을하기가 쉬운 지 확인하고 싶습니다.
http://reboltutorial.com/blog/easy-yuml-dialect-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 );
}
}
예제는 사각형을 긁어 냈다 http://img34.imageshack.us/img34/4743/screenshotgh.png
제휴하지 않습니다 StackOverflow