<file_sep>//
//  ViewController.swift
//  Gestures
//
//  Created by Stacy on 24.04.21.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var gestureIndicator: UILabel!
    
    @IBAction func tap(sender: AnyObject) {
        gestureIndicator.text = "Gesture: tap\n Background color: green"
        
        gestureIndicator.backgroundColor = .green
        
    }
    
    @IBAction func pinch(sender: AnyObject) {
        gestureIndicator.text = "Gesture: pinch\n Background color: red"
        
        gestureIndicator.backgroundColor = .red

    }
    
    @IBAction func rotation(sender: AnyObject) {
        gestureIndicator.text = "Gesture: rotation\n Background color: blue"
        
        gestureIndicator.backgroundColor = .blue
    }
    
    @IBAction func longPress(sender: AnyObject) {
        gestureIndicator.text = "Gesture: long press\n Background color: orange"
        
        gestureIndicator.backgroundColor = .orange

        
    }
    
    @IBAction func swipe(sender: AnyObject) {
        gestureIndicator.text = "Gesture: swipe\n Background color: gray"
        
        gestureIndicator.backgroundColor = .gray
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        gestureIndicator.isUserInteractionEnabled = true
        gestureIndicator.textAlignment = .center
        gestureIndicator.numberOfLines = 2
        gestureIndicator.text = "Use gestures in this area"
        gestureIndicator.backgroundColor = .yellow
    }


}

<file_sep>//
//  BrushWidth.swift
//  Example
//
//  Created by Stacy on 24.04.21.
//

import UIKit

enum BrushWidth {
  case superSmall
  case small
  case medium
  case large
  case superLarge

    init?(tag: Int) {
        switch tag {
        case 0:
            self = .superSmall
        case 1:
            self = .small
        case 2:
            self = .medium
        case 3:
            self = .large
        case 4:
            self = .superLarge
        default:
            return nil
        }
    }
    
    var size: CGFloat {
      switch self {
      case .superSmall:
        return 15.0
      case .small:
        return 20.0
      case .medium:
        return 30.0
      case .large:
        return 40.0
      case .superLarge:
        return 50.0
      }
    }
}
<file_sep>//
//  ViewController.swift
//  Graphics
//
//  Created by <NAME> on 8.05.21.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var NewView: UIView!
    
    @IBOutlet weak var InfoLable: UILabel!
    
    @IBOutlet weak var Circle: CircleView!
    
    @IBOutlet weak var Triangle: TriangleView!
    var isTogether: Bool = false
    var TagID: Int = 100

    override func viewDidLoad() {
        super.viewDidLoad()
        NewView.addSubview(Circle)
        NewView.addSubview(Triangle)
    }

    @IBAction func tapAddTo2nd(_ sender: Any) {
        if(!isTogether) {
            isTogether = true
            InfoLable.text = ""
            Triangle.center = NewView.center
            Circle.center = Triangle.center
        }
        else {
            NewView.bringSubviewToFront(Triangle)
        }
    }
    
    @IBAction func tapAddTo1st(_ sender: Any) {
        
        if(!isTogether) {
            isTogether = true
            InfoLable.text = ""
            Triangle.center = NewView.center
            NewView.bringSubviewToFront(Circle)
            Circle.center = Triangle.center
        }
        else {
            NewView.bringSubviewToFront(Circle)
        }
    }
    
    @IBAction func tapRotateButton(_ sender: Any) {
        if(isTogether){
            UIView.animate(withDuration: 0.5, animations: {
                self.NewView.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
            })
            UIView.animate(withDuration: 1, delay: 0.45, animations: { self.NewView.transform = CGAffineTransform(rotationAngle: CGFloat.pi * 2)
            })
        }
        else {
            InfoLable.text = "Please add figures to each other."
        }
    }
    
    @IBAction func tapAlphaButton(_ sender: Any) {
        if(isTogether){
            UIView.animate(withDuration: 1.5, animations: {
                self.NewView.alpha = 1.0
                self.NewView.alpha = 0
                self.NewView.alpha = 1.0
            })
        }
        else {
            InfoLable.text = "Please add figures to each other."
        }
    }
    
    @IBAction func tapMoveButton(_ sender: Any) {
        if(isTogether){
            UIView.animate(withDuration: 0.5, animations: {
                self.NewView.transform = CGAffineTransform(translationX: 0, y: -200)
                UIView.animate(withDuration: 1, delay: 0.45, animations: { self.NewView.transform = CGAffineTransform(translationX: 0, y: 0)
                })
            })
            
        }
        else {
            InfoLable.text = "Please add figures to each other."
        }
    }
    
    @IBAction func tapBothButton(_ sender: Any) {
        if(isTogether){
            tapAlphaButton((Any).self)
            if ((Int.random(in: 0..<2)) == 0) {
                tapMoveButton((Any).self)
            }
            else {
                tapRotateButton((Any).self)
            }
        }
        else {
            InfoLable.text = "Please add figures to each other."
        }
    }
    
    func removeTr(triangle: TriangleView) {
        triangle.removeFromSuperview()
    }
    
    @IBAction func tap(sender: AnyObject) {
        if(Triangle.center != NewView.center) {
            let tr = TriangleView.init(frame: Triangle.frame)
            tr.backgroundColor = UIColor.clear
            tr.InsideColor = UIColor.blue
            tr.OutsideColor = UIColor.green
            NewView.addSubview(tr)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.removeTr(triangle: tr)
            }
        }
    }
    
    @IBAction func pinch(sender: AnyObject) {
        if(Triangle.center != NewView.center) {
            let tr = TriangleView.init(frame: Triangle.frame)
            tr.backgroundColor = UIColor.clear
            tr.InsideColor = UIColor.black
            tr.OutsideColor = UIColor.red
            NewView.addSubview(tr)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.removeTr(triangle: tr)
            }
        }
    }
    
    @IBAction func rotation(sender: AnyObject) {
        if(Triangle.center != NewView.center) {
            let tr = TriangleView.init(frame: Triangle.frame)
            tr.backgroundColor = UIColor.clear
            tr.InsideColor = UIColor.systemYellow
            tr.OutsideColor = UIColor.orange
            NewView.addSubview(tr)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.removeTr(triangle: tr)
            }
        }
    }
    
    @IBAction func longPress(sender: AnyObject) {
        if(Triangle.center != NewView.center) {
            let tr = TriangleView.init(frame: Triangle.frame)
            tr.backgroundColor = UIColor.clear
            tr.InsideColor = UIColor.black
            tr.OutsideColor = UIColor.cyan
            NewView.addSubview(tr)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.removeTr(triangle: tr)
            }
        }
    }
    
    @IBAction func swipe(sender: AnyObject) {
        if(Triangle.center != NewView.center) {
            let tr = TriangleView.init(frame: Triangle.frame)
            tr.backgroundColor = UIColor.clear
            tr.InsideColor = UIColor.magenta
            tr.OutsideColor = UIColor.white
            NewView.addSubview(tr)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.removeTr(triangle: tr)
            }
        }
    }
    
}

<file_sep>//
//  Pensil.swift
//  Example
//
//  Created by Stacy on 24.04.21.
//

import UIKit

enum Pencil {
  case black
  case grey
  case red
  case blue
  case darkGreen
  case darkOrange
  
  init?(tag: Int) {
    switch tag {
    case 0:
      self = .black
    case 1:
      self = .blue
    case 2:
      self = .darkGreen
    case 3:
        self = .darkOrange
    case 4:
      self = .grey
    case 5:
      self = .red
    default:
      return nil
    }
  }
  
  var color: UIColor {
    switch self {
    case .black:
      return .black
    case .grey:
      return UIColor(white: 105/255.0, alpha: 1.0)
    case .red:
      return UIColor(red: 1, green: 0, blue: 0, alpha: 1.0)
    case .blue:
      return UIColor(red: 0, green: 0, blue: 1, alpha: 1.0)
    case .darkGreen:
      return UIColor(red: 102/255.0, green: 204/255.0, blue: 0, alpha: 1.0)
    case .darkOrange:
      return UIColor(red: 1, green: 102/255.0, blue: 0, alpha: 1.0)
    }
  }
}

<file_sep>//
//  GraphicsCircle.swift
//  Graphics
//
//  Created by <NAME> on 23.04.21.
//

import UIKit

@IBDesignable
class CircleView: UIView {
    @IBInspectable var InsideColor: UIColor = .clear
    @IBInspectable var OutsideColor: UIColor = .clear

    override func draw(_ rect: CGRect) {
        let endRadius = min(frame.height, frame.width) / 2
        let colors = [InsideColor.cgColor, OutsideColor.cgColor] as CFArray
        let shadowColors = [UIColor.black.cgColor, UIColor.clear.cgColor] as CFArray
        let center = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2)
        let shadowCenter = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2 + 50)
        
        guard let gradient = CGGradient(colorsSpace: nil, colors: colors, locations: nil) else { return }
        
        guard let shadow = CGGradient(colorsSpace: nil, colors: shadowColors, locations: nil) else { return }
        
        UIGraphicsGetCurrentContext()!.drawRadialGradient(shadow, startCenter: shadowCenter, startRadius: 10, endCenter: shadowCenter, endRadius: endRadius, options: CGGradientDrawingOptions.drawsBeforeStartLocation)
        
        UIGraphicsGetCurrentContext()!.drawRadialGradient(gradient, startCenter: center, startRadius: 10, endCenter: center, endRadius: endRadius, options: CGGradientDrawingOptions.drawsBeforeStartLocation)
        self.backgroundColor = UIColor.clear
        
    }
}
<file_sep>//
//  GraphicsTriangle.swift
//  Graphics
//
//  Created by <NAME> on 24.04.21.
//

import UIKit

@IBDesignable
final class TriangleView: UIView {
    
    @IBInspectable var InsideColor: UIColor = .clear
    @IBInspectable var OutsideColor: UIColor = .clear
    
    override func draw(_ rect: CGRect) {
        let startPoint = CGPoint(x: bounds.size.width/2, y: 0)
        let endPoint = CGPoint(x: bounds.size.width/2, y: bounds.size.height)
        let radius = 30.0
        let colors = [InsideColor, OutsideColor]
        let triangle = UIBezierPath.init(cgPath: createRoundedTriangle(width: bounds.size.width, height: bounds.size.height - 50, radius: CGFloat(radius)))
        let shadowColors = [UIColor.black.withAlphaComponent(0.6), UIColor.clear]
        let shadow = UIBezierPath.init(cgPath: createRoundedTriangle(width: bounds.size.width, height: bounds.size.height - 50, radius: CGFloat(radius)))
        shadow.apply(CGAffineTransform.init(translationX: 0, y: 50))
        drawLinearGradient(inside: shadow, start: startPoint, end: endPoint, colors: shadowColors)
        drawLinearGradient(inside: triangle, start: startPoint, end: endPoint, colors: colors)
        self.backgroundColor = UIColor.clear
    }
    
    func drawLinearGradient(inside path:UIBezierPath, start:CGPoint, end:CGPoint, colors:[UIColor])
    {
        guard let ctx = UIGraphicsGetCurrentContext() else { return }

        ctx.saveGState()
        defer { ctx.restoreGState() }

        path.addClip()

        let cgColors = colors.map({ $0.cgColor })
        guard let gradient = CGGradient(colorsSpace: nil, colors: cgColors as CFArray, locations: nil)
            else { return }

        ctx.drawLinearGradient(gradient, start: start, end: end, options: [])
    }

    private func setUpGradient() -> CAGradientLayer {
        let gradient = CAGradientLayer()
        gradient.colors = [UIColor.orange.cgColor, UIColor.yellow.cgColor]
        return gradient
    }
    
    func createRoundedTriangle(width: CGFloat, height: CGFloat, radius: CGFloat) -> CGMutablePath {

        let point1 = CGPoint(x: width / 2, y: 0)//-width/2
        let point2 = CGPoint(x: width, y: height)
        let point3 = CGPoint(x: 0, y: height)

        let path = CGMutablePath()
        path.move(to: CGPoint(x: 0, y: height))
        path.addArc(tangent1End: point1, tangent2End: point2, radius: radius)
        path.addArc(tangent1End: point2, tangent2End: point3, radius: radius)
        path.addArc(tangent1End: point3, tangent2End: point1, radius: radius)
        path.closeSubpath()
        
        return path
    }
}
<file_sep>//
//  ViewController.swift
//  Example
//
//  Created by Stacy on 24.04.21.
//

import UIKit
import CoreGraphics

class ViewController: UIViewController {
    
    @IBOutlet var mainImageView: UIImageView!
    @IBOutlet weak var tempImageView: UIImageView!
    
    var lastPoint = CGPoint.zero
    var color = UIColor.black
    var brushWidth: CGFloat = 15.0
    var swiped = false
    
    var tapGestureRecognizerNumberPadView : UITapGestureRecognizer?
    
    @IBAction func resetPressed(_ sender: Any) {
        mainImageView.image = nil
        tempImageView.image = nil
    }
    @IBAction func saveTapped(_ sender: Any) {
        if let image = tempImageView.image {
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
           }

    }
    
    @IBAction func widthPressed(_ sender: UIButton) {
        guard let width = BrushWidth(tag: sender.tag) else {
          return
        }
        brushWidth = width.size
    }
    
    @IBAction func pencilPressed(_ sender: UIButton) {
        guard let pencil = Pencil(tag: sender.tag) else {
          return
        }
        color = pencil.color
    }
    
    func drawLine(from fromPoint: CGPoint, to toPoint: CGPoint) {
      UIGraphicsBeginImageContext(view.frame.size)
      guard let context = UIGraphicsGetCurrentContext() else {
        return
      }
      tempImageView.image?.draw(in: view.bounds)
      
      context.move(to: fromPoint)
      context.addLine(to: toPoint)
      
      context.setLineCap(.round)
      context.setBlendMode(.normal)
      context.setLineWidth(brushWidth)
      context.setStrokeColor(color.cgColor)
      
      context.strokePath()
      
      tempImageView.image = UIGraphicsGetImageFromCurrentImageContext()
      
      UIGraphicsEndImageContext()
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
      guard let touch = touches.first else {
        return
      }
      swiped = false
      lastPoint = touch.location(in: view)
    }
    
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
      guard let touch = touches.first else {
        return
      }
      swiped = true
      let currentPoint = touch.location(in: view)
      drawLine(from: lastPoint, to: currentPoint)
      
      lastPoint = currentPoint
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
      if !swiped {
        drawLine(from: lastPoint, to: lastPoint)
      }

      UIGraphicsBeginImageContext(mainImageView.frame.size)
      mainImageView.image?.draw(in: view.bounds, blendMode: .normal, alpha: 1.0)
      mainImageView.image = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
    }
    
}


