我的問題涉及到的各種技術繪製,似乎是寫意線:如何繪製手繪的橢圓或圓形?
How do you draw like a Crayon?
具體史蒂夫Hanov張貼了這個優秀的blog entry。
由此我能夠使用貝塞爾曲線爲徒手線實現漂亮的算法。但是,我堅持如何實現手繪橢圓。理想情況下,我想給它一個矩形作爲邊界,類似於其他橢圓繪圖調用。但是,我希望它看起來很自由。
到目前爲止,最好的我想出了這一點:
- (UIBezierPath*) freehandEllipseFromRect:(CGRect) rect {
// freehand ellipses need a lil more height
rect = CGRectMake(rect.origin.x, rect.origin.y-5, rect.size.width, rect.size.height+10);
UIBezierPath* path = [UIBezierPath bezierPath];
CGPoint topMidPoint = CGPointMake(rect.origin.x + (rect.size.width/2), rect.origin.y);
CGPoint bottomMidPoint = CGPointMake(rect.origin.x + (rect.size.width/2), rect.origin.y+rect.size.height);
// random point along bottom quarter of height, cause makes it look better
CGFloat randomY = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * (rect.size.height/4);
CGPoint leftControlPoint = CGPointMake(rect.origin.x-(rect.size.width), rect.origin.y+(rect.size.height-randomY));
// another random y;
randomY = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * (rect.size.height/4);
CGPoint rightControlPoint = CGPointMake(rect.origin.x+(rect.size.width*2), rect.origin.y+(rect.size.height-randomY));
CGFloat overshootValueX = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * 4;
CGFloat overshootValueY = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * 6;
[path moveToPoint:CGPointMake(topMidPoint.x+overshootValueX, topMidPoint.y)];
[path addQuadCurveToPoint:bottomMidPoint controlPoint:leftControlPoint];
// random value to overshoot
overshootValueX = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * 20;
overshootValueY = (((CGFloat) (arc4random() % RAND_MAX)/RAND_MAX)) * 4;
[path addQuadCurveToPoint:CGPointMake(topMidPoint.x-overshootValueX, topMidPoint.y-overshootValueY) controlPoint:rightControlPoint];
return path;
}
結果看起來是這樣的:
我不喜歡怎麼指出這是在上面,儘管我嘗試了所有的嘗試,但我無法讓它變得更好。另外,我喜歡曲線看起來不那麼完美,並且不依賴懸垂物作爲唯一的「徒手畫」看的部分。我認爲2條四線曲線只是錯誤的路線.....
也許4弧?
任何人有我的另一個解決方案或一些示例代碼? (任何語言都可以)