title: Smooth writing on iPad
body: <p>I'm currently working on a iPad project where I need the functionality to let the user write on a piece of paper with a stylus.</p>
  
  <p>I've tested a couple of styluses and found out that the bamboo was the best. They also have a free application which you can use to write.</p>
  
  <p>The problem I'm facing is that the method I use does not delivers smooth curves. The bamboo paper app provides perfect looking lines. This is the code I have so far:</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
      CGContextRef context = UIGraphicsGetCurrentContext();
      UIGraphicsBeginImageContext(self.frame.size);
  
      // draw accumulated lines
      if ([self.lines count] &gt; 0) {
          for (Line *tempLine in self.lines){
              CGContextSetAlpha(context, tempLine.opacity);
              CGContextSetStrokeColorWithColor(context, tempLine.lineColor.CGColor);
              CGContextSetLineWidth(context, tempLine.lineWidth);
              CGContextSetLineCap(context, kCGLineCapRound);
              CGContextSetLineJoin(context, kCGLineJoinRound);
              CGContextAddPath(context, tempLine.linePath);
              CGContextStrokePath(context);
  
              }
      }
  
      //draw current line
      CGContextSetAlpha(context, self.currentLine.opacity);
  
  
      CGContextSetStrokeColorWithColor(context, self.currentLine.lineColor.CGColor);
      CGContextSetLineWidth(context, self.currentLine.lineWidth);
      CGContextSetLineCap(context, kCGLineCapRound);
      CGContextSetLineJoin(context, kCGLineJoinRound);
      CGContextBeginPath(context);
      CGContextAddPath(context, self.currentLine.linePath);
      CGContextStrokePath(context);
  
  
      UIGraphicsEndImageContext();
  
  
  }
  
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch *touch = [touches anyObject];
      CGPoint cPoint = [touch locationInView:self];
  
      CGPathMoveToPoint(self.currentLine.linePath, NULL, cPoint.x, cPoint.y);
  
      [self setNeedsDisplay];
  }
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch *touch = [touches anyObject];   
      CGPoint currentPoint = [touch locationInView:self];
  
      CGPathAddLineToPoint(self.currentLine.linePath, NULL, currentPoint.x, currentPoint.y);
  
      [self setNeedsDisplay];
  }
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {  
      UITouch *touch = [touches anyObject];
      CGPoint cPoint = [touch locationInView:self];
      CGPathAddLineToPoint(self.currentLine.linePath, NULL, cPoint.x, cPoint.y);
  
      [self setNeedsDisplay];
      [self.lines addObject:self.currentLine];
      Line *nextLine = [[Line alloc] initWithOptions:self.currentLine.lineWidth color:self.currentLine.lineColor opacity:self.currentLine.opacity];
      self.currentLine = nextLine;
      [nextLine release];
  }
  </code></pre>
  
  <p>Here are the images that makes it clear what problem I'm facing. This is the image what gets generated when writing with the code provided above:</p>
  
  <p><img src="https://i.stack.imgur.com/zcPaQ.png" alt="enter image description here"></p>
  
  <p>This is the image if I write the same thing on the Mamboo paper app:</p>
  
  <p><img src="https://i.stack.imgur.com/DDy8v.png" alt="enter image description here"></p>
  
  <p>Does anyone have an idea how to get the nice writing like in the mamboo app?</p>