// Code that generates symbols for logic gates
import UIKit
public enum GateType {
    case and
    case or
    case xor
    case not
}
public func gateImage(type: GateType, negated: Bool) -> UIImage {
    // This code was generated by Trial version of PaintCode, therefore cannot be used for commercial purposes.
    // http://www.paintcodeapp.com

    let renderer = UIGraphicsImageRenderer(size: CGSize(width: 75, height: 60))

    //// OR_TR Drawing
    let oR_TRPath = UIBezierPath()
    oR_TRPath.move(to: CGPoint(x: 11, y: 2))
    oR_TRPath.addLine(to: CGPoint(x: 18, y: 2))
    oR_TRPath.addCurve(to: CGPoint(x: 42, y: 9), controlPoint1: CGPoint(x: 18, y: 2), controlPoint2: CGPoint(x: 32.75, y: 2))
    oR_TRPath.addCurve(to: CGPoint(x: 60, y: 30), controlPoint1: CGPoint(x: 51.25, y: 16), controlPoint2: CGPoint(x: 60, y: 30))
    oR_TRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_TRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_TRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_TRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_TRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_TRPath.lineWidth = 4
    oR_TRPath.lineCapStyle = .round
    oR_TRPath.lineJoinStyle = .round
    let oR_BRPath = UIBezierPath()
    oR_BRPath.move(to: CGPoint(x: 11, y: 58))
    oR_BRPath.addLine(to: CGPoint(x: 18, y: 58))
    oR_BRPath.addCurve(to: CGPoint(x: 42, y: 51), controlPoint1: CGPoint(x: 18, y: 58), controlPoint2: CGPoint(x: 32.75, y: 58))
    oR_BRPath.addCurve(to: CGPoint(x: 60, y: 30), controlPoint1: CGPoint(x: 51.25, y: 44), controlPoint2: CGPoint(x: 60, y: 30))
    oR_BRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_BRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_BRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_BRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_BRPath.addLine(to: CGPoint(x: 60, y: 30))
    oR_BRPath.lineWidth = 4
    oR_BRPath.lineCapStyle = .round
    oR_BRPath.lineJoinStyle = .round
    let nOTPath = UIBezierPath(ovalIn: CGRect(x: 60, y: 24, width: 12, height: 12))
    nOTPath.lineWidth = 4
    let oR_CURVEPath = UIBezierPath()
    oR_CURVEPath.move(to: CGPoint(x: 2, y: 2))
    oR_CURVEPath.addCurve(to: CGPoint(x: 7, y: 31), controlPoint1: CGPoint(x: 2, y: 2), controlPoint2: CGPoint(x: 7, y: 16.75))
    oR_CURVEPath.addCurve(to: CGPoint(x: 2, y: 58), controlPoint1: CGPoint(x: 7, y: 45.25), controlPoint2: CGPoint(x: 2, y: 58))
    oR_CURVEPath.lineWidth = 4
    oR_CURVEPath.lineCapStyle = .round
    oR_CURVEPath.lineJoinStyle = .round
    let oR_TOPPath = UIBezierPath()
    oR_TOPPath.move(to: CGPoint(x: 2, y: 2))
    oR_TOPPath.addLine(to: CGPoint(x: 11, y: 2))
    oR_TOPPath.lineWidth = 4
    let oR_BOTTOMPath = UIBezierPath()
    oR_BOTTOMPath.move(to: CGPoint(x: 11, y: 58))
    oR_BOTTOMPath.addLine(to: CGPoint(x: 2, y: 58))
    oR_BOTTOMPath.lineWidth = 4
    let xORPath = UIBezierPath()
    xORPath.move(to: CGPoint(x: 11, y: 2))
    xORPath.addCurve(to: CGPoint(x: 16, y: 30), controlPoint1: CGPoint(x: 11, y: 2), controlPoint2: CGPoint(x: 16, y: 15.75))
    xORPath.addCurve(to: CGPoint(x: 11, y: 58), controlPoint1: CGPoint(x: 16, y: 44.25), controlPoint2: CGPoint(x: 11, y: 58))
    xORPath.lineWidth = 4
    let not_w = negated ? 10 : 0
    let aNDPath = UIBezierPath(roundedRect: CGRect(x: 4, y: 2, width: 65-not_w, height: 56), byRoundingCorners: [.topRight, .bottomRight], cornerRadii: CGSize(width: 28, height: 28))
    aNDPath.close()
    aNDPath.lineWidth = 4
    aNDPath.lineCapStyle = .round
    aNDPath.lineJoinStyle = .round
    let nOT_TRIANGLEPath = UIBezierPath()
    nOT_TRIANGLEPath.move(to: CGPoint(x: 13, y: 57.5))
    nOT_TRIANGLEPath.addLine(to: CGPoint(x: 13, y: 2.5))
    nOT_TRIANGLEPath.addLine(to: CGPoint(x: 60, y: 30))
    nOT_TRIANGLEPath.addLine(to: CGPoint(x: 13, y: 57.5))
    nOT_TRIANGLEPath.close()
    nOT_TRIANGLEPath.lineWidth = 4
    nOT_TRIANGLEPath.lineCapStyle = .round
    nOT_TRIANGLEPath.lineJoinStyle = .round

    let img = renderer.image { ctx in
        UIColor.white.setStroke()
        switch(type){
        case .or:
            oR_TRPath.stroke()
            oR_BRPath.stroke()
            oR_CURVEPath.stroke()
            oR_TOPPath.stroke()
            oR_BOTTOMPath.stroke()
        case.xor:
            oR_TRPath.stroke()
            oR_BRPath.stroke()
            oR_CURVEPath.stroke()
            xORPath.stroke()
        case .and:
            aNDPath.stroke()
        case .not:
            nOT_TRIANGLEPath.stroke()
        }
        if(negated) {
            nOTPath.stroke()
        }
        // awesome drawing code


    }

    return img

}


