Draw a path with variable width in iOS

后端 未结 2 1839
予麋鹿
予麋鹿 2021-01-22 00:14

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

相关标签:
2条回答
  • 2021-01-22 00:43

    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)

    0 讨论(0)
  • 2021-01-22 00:50

    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.

    0 讨论(0)
提交回复
热议问题