diff --git a/Comets.podspec b/Comets.podspec index f42d4a1..147ea60 100644 --- a/Comets.podspec +++ b/Comets.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Comets' - s.version = '0.1.0' + s.version = '0.1.1' s.summary = '☄️Comets: Animating Particles in Swift' # This description is used to generate tags and improve search results. @@ -28,4 +28,4 @@ Pod::Spec.new do |s| s.ios.deployment_target = '9.0' s.source_files = 'Comets/Sources/**/*' -end \ No newline at end of file +end diff --git a/Comets/Assets.xcassets/Comet.imageset/Comet.png b/Comets/Assets.xcassets/Comet.imageset/Comet.png deleted file mode 100644 index 2e00238..0000000 Binary files a/Comets/Assets.xcassets/Comet.imageset/Comet.png and /dev/null differ diff --git a/Comets/Assets.xcassets/Comet.imageset/Comet@2x.png b/Comets/Assets.xcassets/Comet.imageset/Comet@2x.png deleted file mode 100644 index 7211e88..0000000 Binary files a/Comets/Assets.xcassets/Comet.imageset/Comet@2x.png and /dev/null differ diff --git a/Comets/Assets.xcassets/Comet.imageset/Comet@3x.png b/Comets/Assets.xcassets/Comet.imageset/Comet@3x.png deleted file mode 100644 index d49fd23..0000000 Binary files a/Comets/Assets.xcassets/Comet.imageset/Comet@3x.png and /dev/null differ diff --git a/Comets/Assets.xcassets/Comet.imageset/Contents.json b/Comets/Assets.xcassets/Comet.imageset/Contents.json deleted file mode 100644 index 8317950..0000000 --- a/Comets/Assets.xcassets/Comet.imageset/Contents.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "filename" : "Comet.png", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "Comet@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "Comet@3x.png", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Comets/Assets.xcassets/Contents.json b/Comets/Assets.xcassets/Contents.json deleted file mode 100644 index da4a164..0000000 --- a/Comets/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Comets/Sources/Comet.swift b/Comets/Sources/Comet.swift index 212344d..4ef0262 100644 --- a/Comets/Sources/Comet.swift +++ b/Comets/Sources/Comet.swift @@ -3,6 +3,12 @@ public struct Comet { public var endPoint: CGPoint public var lineColor: UIColor + public init(startPoint: CGPoint, endPoint: CGPoint, lineColor: UIColor) { + self.startPoint = startPoint + self.endPoint = endPoint + self.lineColor = lineColor + } + public var linePath: UIBezierPath { let path = UIBezierPath() path.move(to: startPoint) @@ -14,7 +20,7 @@ public struct Comet { // create the line as a CAShapeLayer let lineLayer = CAShapeLayer() lineLayer.path = linePath.cgPath - lineLayer.lineWidth = 4 + lineLayer.lineWidth = 0.5 lineLayer.strokeColor = lineColor.cgColor return lineLayer } @@ -27,9 +33,7 @@ public struct Comet { // create comet cell let cell = CAEmitterCell() - cell.contents = UIImage(named: "Comet")? - .rotate(radians: calculateAngle())? - .cgImage + cell.contents = contents cell.birthRate = 0.2 * Float(Int.random(in: 500 ... 2000 )) / 1000 cell.lifetime = 10.0 cell.velocity = 600 @@ -41,6 +45,24 @@ public struct Comet { return emitter } + public var contents: Any? { + let cometLayer = CAGradientLayer() + cometLayer.colors = [UIColor.white.withAlphaComponent(0.0).cgColor, UIColor.white.cgColor] + cometLayer.cornerRadius = 0.25 + cometLayer.frame = CGRect(x: 0, y: 0, width: 80, height: 0.5) + cometLayer.locations = [0.0, 1.0] + cometLayer.startPoint = CGPoint(x: 0, y: 0.5) + cometLayer.endPoint = CGPoint(x: 1.0, y: 0.5) + + UIGraphicsBeginImageContextWithOptions(cometLayer.bounds.size, cometLayer.isOpaque, 0.0) + defer { UIGraphicsEndImageContext() } + guard let context = UIGraphicsGetCurrentContext() else { return nil } + cometLayer.render(in: context) + return UIGraphicsGetImageFromCurrentImageContext()? + .rotate(radians: calculateAngle())? + .cgImage + } + public func calculateAngle() -> CGFloat { let deltaX = endPoint.x - startPoint.x let deltaY = endPoint.y - startPoint.y