Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:58:42+00:00 2026-06-18T03:58:42+00:00

I am doing a calligraphy application and would like to modify my code below

  • 0

I am doing a calligraphy application and would like to modify my code below so when a user ends a brush stroke, the line tapers and thins out like it would with a real calligraphy pen (a flick effect). I understand that touchesEnded may be a better way to do this, however I was just wondering what would be the best way to programmatically make this flick at the end of a stroke using CGRect or GraphicsContext in UIKit in Xcode for Objective C.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;

UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];



UIGraphicsBeginImageContext(CGSizeMake(320, 568));
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 0, 0, 1);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());


[drawImage setFrame:CGRectMake(0, 0, 320, 568)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//what code do I put here to get the flick effect - what CGGetContext Parameter
//may be applicable or what programming technique may help with this.     

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:58:43+00:00Added an answer on June 18, 2026 at 3:58 am

    This may be over simplifying, but it should lead you in something of the right direction. I’m going to just make a triangle, but you could eventually add bezier curves to make the effect more realistic.

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //what code do I put here to get the flick effect - what CGGetContext Parameter
    //may be applicable or what programming technique may help with this. 
    
        UIGraphicsBeginImageContext(CGSizeMake(320, 568));
        [drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)];
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 5.0);
        CGContextSetRGBFillColor(context, 0, 0, 0, 1);
        CGContextBeginPath(context);
        CGContextBeginPath(context);
        CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
        CGContextClosePath(context);
        CGContextStrokePath(context);
    
        //Normalized directionality
        float lineLength = sqrt((currentPoint.x - lastPoint.x)*(currentPoint.x - lastPoint.x) + (currentPoint.y - lastPoint.y)*(currentPoint.y - lastPoint.y));
        float dx = (currentPoint.x - lastPoint.x)/lineLength;
        float dy = (currentPoint.y - lastPoint.y)/lineLength;
    
        //Now make a triangle
        CGContextBeginPath(context);
    
        //2.5 is from 1/2 of your line width (5)
        CGContextMoveToPoint(context, currentPoint.x + 2.5*dy, currentPoint.y - 2.5*dx);
    
        //This 10 is completely arbitrary, the length your taper is going to be.
        //Ideally this will be proportional to your last line segment length, longer if their finger is moving faster...
        CGContextAddLineToPoint(context, currentPoint.x + 10*dx, currentPoint.y + 10*dy);
    
        //Now the last tip of the triangle
        CGContextMoveToPoint(context, currentPoint.x - 2.5*dy, currentPoint.y + 2.5*dx);
        CGContextClosePath(context);
        CGContextFillPath(context);
    
        [drawImage setFrame:CGRectMake(0, 0, 320, 568)];
        drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    

    Now to make this cooler you could add in calculation of the curve the person was drawing and create your “triangle” taper with bezier curves in the direction that they were curving. That could actually be really fun to calculate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing some code in JavaScript/jQuery and I need to have it where the user
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
Doing code analysis of the project and get the message Reference-counted object is used
Doing some refactoring in some legacy code I've found in a project. This is
Doing some code reading and stumbled upon this snippet that I haven't seen before:
Doing some code reviews lately I came across a number of classes that have
Doing some OO PHP. I'm getting undefined variables on line 11 and 31 and
Doing a Google search I found several command-line SCEP clients that I can download

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.