2

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) In iOS, their is no pressure detection, or velocity detection according to my research. For velocity detection, I have to use OPENGL.

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) 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.

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

1)BAMBOO app

enter image description here

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

2) MY APP

enter image description here

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

So, here are my doubts

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

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.

Regards Ranjit

Ranjit
  • 4,576
  • 11
  • 62
  • 121
  • It seems like you are almost there, just modify the code that changes the width to the opposite dependency on speed – David Rönnqvist Jan 22 '14 at 11:21
  • Hey David, I am not getting it, can you point out in the code, what needs to be changed. – Ranjit Jan 22 '14 at 11:33
  • 2
    The answer to that question is there in the same post that you linked to. I just searched for the word "width" (see my answer). This really is something that you should have been able to do by yourself. – David Rönnqvist Jan 22 '14 at 11:47
  • Hey @DavidRönnqvist, its not that, I had not seen this, but here the problem is when we write closely writing becomes weird.Can you throw some light on why it might be happening. – Ranjit Jan 22 '14 at 13:31

2 Answers2

2

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...

And the answer:

thanks for the great tutorial!

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);

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)

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • Checking it out, I will get back to you – Ranjit Jan 22 '14 at 11:52
  • I tried it and it works but writing is very bad. I think I need to play with FF, LOWER and UPPER values. What say?. If I write slow, it is getting very thick and weird. – Ranjit Jan 22 '14 at 11:58
  • Hello @David, can you help me out with this – Ranjit Jan 23 '14 at 09:33
  • @Ranjit I would assume that it's mostly tweaking the values specific to this code that you are using to find something that you like – David Rönnqvist Jan 23 '14 at 09:39
  • Helo @David, I didnt get you, what are you conveying. – Ranjit Jan 23 '14 at 09:41
  • Hello @David, can we discuss this issue and sort it out. – Ranjit Jan 23 '14 at 10:54
  • Hello @David, I tried out with different possibilities, the writing is good, but I think can be better. I need your help in understanding it better – Ranjit Jan 23 '14 at 13:20
  • Hello @David, please have a look at this http://stackoverflow.com/questions/21438586/undo-redo-for-drawing-in-ios, I got stuck with this, please help – Ranjit Jan 31 '14 at 07:53
  • Hello @David, please help me out http://stackoverflow.com/questions/21545923/multitouch-tracking-issue – Ranjit Feb 09 '14 at 14:40
  • Hello @David, please look at this http://stackoverflow.com/questions/21935064/undo-with-multitouch-drawing-in-ios – Ranjit Feb 21 '14 at 12:58
  • Hello @David, please look at this http://stackoverflow.com/questions/21952274/writing-getting-jagged-with-multiotuch, please give me some direction – Ranjit Feb 22 '14 at 09:26
0

In your touchesBegan: method, UItouch is supplied.
UITouch has below instance functions,

– locationInView:
– previousLocationInView:

And below property

@property(nonatomic, readonly) NSTimeInterval timestamp

From the above, i think you can easily calculate velocity.I didn't go through any of mentioned links.I just want to give you an idea of how to calculate velocty based on touch object.

santhu
  • 4,796
  • 1
  • 21
  • 29
  • Given the the OP posted a screen shot of his results I assume that he already got the velocity calculations done. – David Rönnqvist Jan 22 '14 at 11:22
  • yes, its an 'assumption' as you said.For his knowledge, iam mentioning above so that he dont need to depend on some other code. – santhu Jan 22 '14 at 11:25
  • So do you feel that this answers to OP's question or is it more of a good piece of information – David Rönnqvist Jan 22 '14 at 11:28
  • Hey thanks santhu, for your information, but the link which I have posted, has a nice algorithm which I am following now.And thinking of modifying it. So what you have to say about it. – Ranjit Jan 22 '14 at 11:35
  • Hello @santhu, what you have to say? – Ranjit Jan 23 '14 at 07:36
  • Hello @Santhu, can you elaborate more on your logic, I am thinking of going your way – Ranjit Jan 23 '14 at 16:13
  • Hello @santhu, please look at this http://stackoverflow.com/questions/21438586/undo-redo-for-drawing-in-ios, I got stuck with it, please help – Ranjit Jan 31 '14 at 07:54
  • Hello @santhu, please help me out with this http://stackoverflow.com/questions/21952274/writing-getting-jagged-with-multiotuch – Ranjit Feb 22 '14 at 09:26