Stroking paths using a pattern color to simulate brush texture

后端 未结 1 635
旧时难觅i
旧时难觅i 2021-01-31 23:45

I am making a finger painting app and I am having a hard time giving my brush a nice brush-like feel and texture.

I have this code:

    UIColor * brushTe         


        
1条回答
  •  孤街浪徒
    2021-02-01 00:27

    Here i found a solution!

        UIImage *texture = [UIImage imageNamed:"brush.png"]    
        CGPoint vector = CGPointMake(currentPoint.x - endPoint.x, currentTPoint.y - endPoint.y);
        CGFloat distance = hypotf(vector.x, vector.y);
        vector.x /= distance;
        vector.y /= distance;
        for (CGFloat i = 0; i < distance; i += 1.0f) {
            CGPoint p = CGPointMake(endPoint.x + i * vector.x, endPoint.y + i * vector.y);
            [texture drawAtPoint:p blendMode:blendMode alpha:0.5f];
        }
    

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