[英]smooth drawing in iphone
我想在繪圖應用程序中畫線。
我想畫線如下圖所示。
在這里,您可以看到在頂部和底部,線寬大於中間線。 根據應用程序,當用戶緩慢繪制時,線寬需要增加,而當用戶快速繪制時,線寬會減小。
我嘗試了http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/
但這與我的需要相反。
對這種光滑的繪圖,奧尼爾有什么想法嗎?
我在您提供的示例鏈接中看到了一段代碼
- (float)extractSize:(UIPanGestureRecognizer *)panGestureRecognizer
{
// 1
float vel = ccpLength([panGestureRecognizer velocityInView:panGestureRecognizer.view]);
float size = vel / 166.0f;
size = clampf(size, 1, 40);
// 2
if ([velocities count] > 1) {
size = size * 0.2f + [[velocities objectAtIndex:[velocities count] - 1] floatValue] * 0.8f;
}
[velocities addObject:[NSNumber numberWithFloat:size]];
return size;
}
你能試一下嗎 ? 用...替換它
- (float)extractSize:(UIPanGestureRecognizer *)panGestureRecognizer
{
// 1
float vel = ccpLength([panGestureRecognizer velocityInView:panGestureRecognizer.view]);
float size = vel / 166.0f;
size = clampf(size, 1, 40);
// 2
if ([velocities count] > 1) {
size = size * 1.2f + [[velocities objectAtIndex:[velocities count] - 1] floatValue] * 0.8f;
}
[velocities addObject:[NSNumber numberWithFloat:size]];
return size;
}
編輯 :無論如何,使用此方法應該可以為您提供所需的東西。
添加代碼
size = 40 - size;
如下代碼使完全相反。
- (float)extractSize:(UIPanGestureRecognizer *)panGestureRecognizer
{
//! result of trial & error
float vel = ccpLength([panGestureRecognizer velocityInView:panGestureRecognizer.view]);
float size = vel / 166.0f;
size = clampf(size/2, 1, 20);
if ([velocities count] > 1) {
size = size * 0.2f + [[velocities objectAtIndex:[velocities count] - 1] floatValue] * 0.8f;
}
[velocities addObject:[NSNumber numberWithFloat:size]];
return size;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.