-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0cfa8b
commit 6d3decf
Showing
8 changed files
with
195 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Easing.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 23/07/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public enum Easing {} | ||
|
||
public extension Easing { | ||
static func linear(_ t: Double) -> Double { | ||
return t | ||
} | ||
|
||
static func easeIn(_ t: Double) -> Double { | ||
return t * t | ||
} | ||
|
||
static func easeOut(_ t: Double) -> Double { | ||
return 1 - easeIn(1 - t) | ||
} | ||
|
||
static func easeInEaseOut(_ t: Double) -> Double { | ||
if t < 0.5 { | ||
return 2 * easeIn(t) | ||
} else { | ||
return 4 * t - 2 * easeIn(t) - 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Effect.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 19/07/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public enum EffectType { | ||
case fadeIn | ||
case fadeOut | ||
case fizzleOut | ||
} | ||
|
||
public struct Effect { | ||
public let type: EffectType | ||
public let color: Color | ||
public let duration: Double | ||
public var time: Double = 0 | ||
|
||
public init(type: EffectType, color: Color, duration: Double) { | ||
self.type = type | ||
self.color = color | ||
self.duration = duration | ||
} | ||
} | ||
|
||
public extension Effect { | ||
var isCompleted: Bool { | ||
return time >= duration | ||
} | ||
|
||
var progress: Double { | ||
let t = min(1, time / duration) | ||
switch type { | ||
case .fadeIn: | ||
return Easing.easeIn(t) | ||
case .fadeOut: | ||
return Easing.easeOut(t) | ||
case .fizzleOut: | ||
return Easing.easeInEaseOut(t) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters