在iOS中绘制宽度可变的路径 [英] Draw a path with variable width in iOS

查看:105
本文介绍了在iOS中绘制宽度可变的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个写作应用程序,我的写作工作正常,但我想要实现的是可变笔画宽度,因此写作非常逼真和直观,如 BAMBOO PENULTIMATE 申请。

I am working on a writing application, My writing is working fine, but what I want to implement is variable stroke width, so that the writing is very realistic and intuitive, as done by "BAMBOO" and "PENULTIMATE" application.

首先,我想告诉你我的尝试。

Firstly I want to tell you what I have tried.

1)在iOS中,根据我的研究,它们没有压力检测或速度检测。对于速度检测,我必须使用OPENGL。

1) In iOS, their is no pressure detection, or velocity detection according to my research. For velocity detection, I have to use OPENGL.

2)由于这些限制,我尝试使用本教程中给出的方法非常简单。这是链接 http://mobile.tutsplus.com/教程/ iphone / ios-sdk-advanced-freehand-drawing-techniques /

2) Due to these limitations, I tried using the method given in this tutorial which is pretty straight forward.Here is the link http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-advanced-freehand-drawing-techniques/

3)这很好用但是这里发生的是宽度当我移动速度越来越快时,我越来越慢。但我想要的是相反的效果,即当我移动得更慢时宽度应该增加,当我快速移动时,厚度应该只在边缘和整条线上看到。

3) This works fine, But here what happens is that, the width increases as I move faster and decreases, as I move slower. But I want is the opposite effect, that is the width should increase as I move slower and when I move fast, the thickness should only be seen only at the edges and for the whole line.

以下是BAMBOO应用程序和我的应用程序的屏幕截图。

Here are the screenshot of the BAMBOO app and my app.

1)BAMBOO app

1)BAMBOO app

在上图中,线条以速度绘制,你会看到厚度仅在边缘。

In the above image, the line is drawn with speed and you will see that the thickness is only at edges.

2)我的APP

在这里你会看到边缘处的线条较薄,而其他地方的线条较厚。

Here you will see that the line is thinner at edges and thick every where else.

所以,这是我的怀疑

1)除了我的尝试之外,他们是否有更好的方法来满足我的要求。

1) Is their any better approach to fulfil my requirement, other than what I have tried.

2)如果我尝试了,是正确的方法来解决问题那么我需要做些什么改变为了达到预期的效果。

2) If what I have tried, is correct approach to tackle the problem, then what changes I need to make to achieve the desired effect.

问候
Ranjit

Regards Ranjit

推荐答案

如何扭转宽度行为和(甚至与您的问题相同的问题)的答案就在您发布的链接中。我所做的只是搜索宽度这个词

The answer to how to reverse the width behaviour and (and even the same question as yours) is right there in the link that you posted. All I did was to search for the word "width"

问题(我的突出显示不是报价的一部分):

The question (my highlighting is not part of the quote):


这个版本的最终版本似乎与第一个版本相反。我希望线条更粗,因为用户移动得更慢而不是更薄。 我在哪里更改代码以反转最终变化的厚度以执行或像笔一样?意味着用户移动较慢或更多墨水的速度越慢...谢谢!很棒的教程,顺便说一句......

The final version of this seems to work opposite of the first version. I would like to have the line thicker as the user moves slower and not thinner. Where do I change the code to inverse the final varying thickness to perform or like a pen? Meaning the slower the user moves the thicker or more ink the pen puts down... Thanks! Great tutorials, btw...

答案是:


感谢您的精彩教程!

thanks for the great tutorial!

通过这些更改我获得了相反的线宽cahnge效果:

with these changes i got the opposite line width cahnge effect:

#define CAPACITY 100
#define FF 20.0
#define LOWER 0.01
#define UPPER 1.5

float frac1 = clamp(FF/len_sq(pointsBuffer[i], pointsBuffer[i+1]), LOWER, UPPER); // ................. (4)
float frac2 = clamp(FF/len_sq(pointsBuffer[i+1], pointsBuffer[i+2]), LOWER, UPPER);
float frac3 = clamp(FF/len_sq(pointsBuffer[i+2], pointsBuffer[i+3]), LOWER, UPPER);


在同一链接中搜索文本float frac1 = 显示此更改应该应用于第76-78行(在文章的代码中,touchesMoved:withEvent:中的某处)

Another search in the same link for the text "float frac1 =" shows that this change should be applied to lines 76-78 (somewhere inside touchesMoved:withEvent: in the code from the article)

这篇关于在iOS中绘制宽度可变的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆