Skip to content

Commit

Permalink
Merge pull request #3 from cruisediary/fix-bundle-issue
Browse files Browse the repository at this point in the history
Fix bundle resource issue
  • Loading branch information
cruisediary authored Oct 21, 2018
2 parents d1bd098 + 026f072 commit 28bc38b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Comets.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,4 +28,4 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '9.0'
s.source_files = 'Comets/Sources/**/*'

end
end
Binary file removed Comets/Assets.xcassets/Comet.imageset/Comet.png
Binary file not shown.
Binary file not shown.
Binary file removed Comets/Assets.xcassets/Comet.imageset/Comet@3x.png
Binary file not shown.
23 changes: 0 additions & 23 deletions Comets/Assets.xcassets/Comet.imageset/Contents.json

This file was deleted.

6 changes: 0 additions & 6 deletions Comets/Assets.xcassets/Contents.json

This file was deleted.

30 changes: 26 additions & 4 deletions Comets/Sources/Comet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 28bc38b

Please sign in to comment.