[英]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.