title: Swift 4: Opacity constantly overlaps in one stroke (Drawing App)
body: <p>The opacity overlaps in one stroke rather than it being one solid opaque stroke.<a href="https://i.stack.imgur.com/bjoz5.png" rel="nofollow noreferrer">Opacity Stroke</a></p>
  
  <p>I have tried modifying some of the contexts and even deleted some, however non of that helped (I have turned it back to its original state). My goal is to try and draw with the marker tool and have the opacity be around .5 comparing to the pencil tool with opacity as 1. When I use the marker, all I get are constant dots as seen in the picture, I believe that they are all separate strokes even with one swipe without lifting up my finger. </p>
  
  <p>If anyone has any knowledge on this I could really use some help (: </p>
  
  <p>Here is my Core Graphics code.</p>
  
  <pre><code>override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
      swiped = true
      if let touch = touches.first {
          let currentPoint = touch.preciseLocation(in: self.view)
          drawLines(fromPoint: lastPoint, toPoint: currentPoint)
          lastPoint = currentPoint
          tool.center = currentPoint
  
      }
  }
  func drawLines(fromPoint: CGPoint, toPoint: CGPoint) {
      UIGraphicsBeginImageContext(self.view.frame.size)
      imageView.image?.draw(in: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
  
      let context = UIGraphicsGetCurrentContext()
      context?.move(to: CGPoint(x: fromPoint.x, y: fromPoint.y))
      context?.addLine(to: CGPoint(x: toPoint.x, y: toPoint.y))
      context?.setStrokeColor(UIColor(red: red, green: green, blue: blue, alpha: opacityValue).cgColor)
      context?.setBlendMode(CGBlendMode.normal)
      context?.setLineJoin(CGLineJoin.bevel)
      context?.setLineCap(CGLineCap.round)
      context?.setLineWidth(brushSize)
      context?.strokePath()
  
      imageView.image = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
  
  }
  
  override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
      if !swiped {
          drawLines(fromPoint: lastPoint, toPoint: currentPoint)
  
      }
  }
  
  override func touchesCancelled(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
      touchesEnded(touches, with: event)
  
  }
  
      override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  
      }
  </code></pre>