Skip to content

Commit

Permalink
Merge pull request #13 from cruisediary/feature-comet-color
Browse files Browse the repository at this point in the history
Customize comet color
  • Loading branch information
cruisediary authored Aug 3, 2019
2 parents 02cb8ce + 6370fce commit 4ae2df6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion 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.3.0'
s.version = '0.3.1'
s.summary = '☄️Comets: Animating Particles in Swift'

# This description is used to generate tags and improve search results.
Expand Down
2 changes: 1 addition & 1 deletion Comets/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.3.0</string>
<string>0.3.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
19 changes: 13 additions & 6 deletions Comets/Sources/Comet.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
public struct Comet {
public var startPoint: CGPoint
public var endPoint: CGPoint
public var lineColor: UIColor
let startPoint: CGPoint
let endPoint: CGPoint
let lineColor: UIColor
let cometColor: UIColor

public init(startPoint: CGPoint, endPoint: CGPoint, lineColor: UIColor) {
public init(
startPoint: CGPoint,
endPoint: CGPoint,
lineColor: UIColor = UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor = UIColor.white
) {
self.startPoint = startPoint
self.endPoint = endPoint
self.lineColor = lineColor
self.cometColor = cometColor
}

public var linePath: UIBezierPath {
Expand Down Expand Up @@ -45,9 +52,9 @@ public struct Comet {
return emitter
}

public var contents: Any? {
private var contents: Any? {
let cometLayer = CAGradientLayer()
cometLayer.colors = [UIColor.white.withAlphaComponent(0.0).cgColor, UIColor.white.cgColor]
cometLayer.colors = [cometColor.withAlphaComponent(0.0).cgColor, cometColor.cgColor]
cometLayer.cornerRadius = 0.25
cometLayer.frame = CGRect(x: 0, y: 0, width: 80, height: 0.5)
cometLayer.locations = [0.0, 1.0]
Expand Down
2 changes: 1 addition & 1 deletion CometsTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.0</string>
<string>0.3.1</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
21 changes: 14 additions & 7 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,32 @@ class ViewController: UIViewController {
let height = view.bounds.height
let comets = [Comet(startPoint: CGPoint(x: 100, y: 0),
endPoint: CGPoint(x: 0, y: 100),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: 0.4 * width, y: 0),
endPoint: CGPoint(x: width, y: 0.8 * width),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: 0.8 * width, y: 0),
endPoint: CGPoint(x: width, y: 0.2 * width),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: width, y: 0.2 * height),
endPoint: CGPoint(x: 0, y: 0.25 * height),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: 0, y: height - 0.8 * width),
endPoint: CGPoint(x: 0.6 * width, y: height),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: width - 100, y: height),
endPoint: CGPoint(x: width, y: height - 100),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red),
Comet(startPoint: CGPoint(x: 0, y: 0.8 * height),
endPoint: CGPoint(x: width, y: 0.75 * height),
lineColor: UIColor.white.withAlphaComponent(0.2))]
lineColor: UIColor.red.withAlphaComponent(0.2),
cometColor: UIColor.red)]

// draw track and animate
for comet in comets {
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Comets (0.3.0)
- Comets (0.3.1)
- Gradients (0.3.0)
- SnapKit (5.0.0)

Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Comets: 80ad7341f67f2743b5f8bdcfaf299956b9840d57
Comets: ff75eb4658d612af66073bf9fcf6e8bef274817b
Gradients: d7e1be639692b86577616ee55ea96f54fb5f1de1
SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf

Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@ let width = view.bounds.width
let height = view.bounds.height
let comets = [Comet(startPoint: CGPoint(x: 100, y: 0),
endPoint: CGPoint(x: 0, y: 100),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: 0.4 * width, y: 0),
endPoint: CGPoint(x: width, y: 0.8 * width),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: 0.8 * width, y: 0),
endPoint: CGPoint(x: width, y: 0.2 * width),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: width, y: 0.2 * height),
endPoint: CGPoint(x: 0, y: 0.25 * height),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: 0, y: height - 0.8 * width),
endPoint: CGPoint(x: 0.6 * width, y: height),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: width - 100, y: height),
endPoint: CGPoint(x: width, y: height - 100),
lineColor: UIColor.white.withAlphaComponent(0.2)),
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white),
Comet(startPoint: CGPoint(x: 0, y: 0.8 * height),
endPoint: CGPoint(x: width, y: 0.75 * height),
lineColor: UIColor.white.withAlphaComponent(0.2))]
lineColor: UIColor.white.withAlphaComponent(0.2),
cometColor: UIColor.white)]

// draw line track and animate
for comet in comets {
Expand All @@ -62,7 +69,7 @@ pod "Comets"

### Carthage
```
github "cruisediary/Comets" ~> 0.3.0
github "cruisediary/Comets" ~> 0.3.1
```

## ❤️ Contribution
Expand Down

0 comments on commit 4ae2df6

Please sign in to comment.