diff --git a/Example/ContentView.swift b/Example/ContentView.swift index 8f7c70d..e04cf7b 100644 --- a/Example/ContentView.swift +++ b/Example/ContentView.swift @@ -24,15 +24,15 @@ struct ContentView: View { CubeTransition() } HStack(spacing: 20) { - BallZigZag() - BallZigZagDeflect() - BallTrianglePath() + BallZigZag(color: .blue, type: .filled) + BallZigZagDeflect(color: .blue, type: .filled) + BallTrianglePath(color: .blue, type: .filled) BallScale() } HStack(spacing: 20) { LineScale() LineScaleParty() - BallPulseSync() + BallPulseSync(color: .blue, type: .filled) BallBeat() } HStack(spacing: 20) { diff --git a/Sources/BallPulseSync.swift b/Sources/BallPulseSync.swift index 9e917ee..f297186 100644 --- a/Sources/BallPulseSync.swift +++ b/Sources/BallPulseSync.swift @@ -15,12 +15,17 @@ public struct BallPulseSync: View { private let timingFunction = TimingFunction.easeInOut private let keyTimes = [0, 0.33, 0.66, 1] private let directionValues: [CGFloat] = [0, 1, -1, 0] - + private let color: Color + private let type: BallType + public var body: some View { GeometryReader(content: render) } - public init() { } + public init(color: Color = .black, type: BallType = .outlined) { + self.color = color + self.type = type + } func render(geometry: GeometryProxy) -> some View { let dimension = min(geometry.size.width, geometry.size.height) @@ -38,7 +43,8 @@ public struct BallPulseSync: View { timingFunctions: timingFunctions, keyTimes: keyTimes, referenceTime: referenceTime) { - Circle() + type.view + .foregroundColor(color) .frame(width: objectDimension, height: objectDimension) .offset(x: 0, y: values[$0]) } diff --git a/Sources/BallTrianglePath.swift b/Sources/BallTrianglePath.swift index b60d18a..2c30a92 100644 --- a/Sources/BallTrianglePath.swift +++ b/Sources/BallTrianglePath.swift @@ -8,7 +8,21 @@ import SwiftUI -fileprivate struct SmallRing: Shape { +public enum BallType { + case filled, outlined + + @ViewBuilder + var view: some View { + switch self { + case .filled: + Circle() + case .outlined: + SmallRing() + } + } +} + +internal struct SmallRing: Shape { func path(in rect: CGRect) -> Path { let dimension = min(rect.size.width, rect.size.height) @@ -26,12 +40,17 @@ public struct BallTrianglePath: View { private let directionValues: [[UnitPoint]] = [[.zero, .init(x: 0.5, y: 1), .init(x: -0.5, y: 1), .zero], [.zero, .init(x: -1, y: 0), .init(x: -0.5, y: -1), .zero], [.zero, .init(x: 0.5, y: -1), .init(x: 1, y: 0), .zero]] + private let color: Color + private let type: BallType public var body: some View { GeometryReader(content: render) } - public init() { } + public init(color: Color = .black, type: BallType = .outlined) { + self.color = color + self.type = type + } func render(geometry: GeometryProxy) -> some View { let dimension = min(geometry.size.width, geometry.size.height) @@ -54,7 +73,8 @@ public struct BallTrianglePath: View { duration: duration, timingFunctions: timingFunctions, keyTimes: keyTimes) { - SmallRing() + type.view + .foregroundColor(color) .frame(width: objectDimension, height: objectDimension) .position(x: positions[index].x, y: positions[index].y) .offset(x: values[index][$0].x, y: values[index][$0].y) diff --git a/Sources/BallZigZag.swift b/Sources/BallZigZag.swift index c18194e..a6249bf 100644 --- a/Sources/BallZigZag.swift +++ b/Sources/BallZigZag.swift @@ -14,12 +14,17 @@ public struct BallZigZag: View { private let keyTimes = [0, 0.33, 0.66, 1] private let directionValues: [[UnitPoint]] = [[.zero, .init(x: -1, y: -1), .init(x: 1, y: -1), .zero], [.zero, .init(x: 1, y: 1), .init(x: -1, y: 1), .zero]] - + private let color: Color + private let type: BallType + public var body: some View { GeometryReader(content: render) } - public init() { } + public init(color: Color = .black, type: BallType = .outlined) { + self.color = color + self.type = type + } func render(geometry: GeometryProxy) -> some View { let dimension = min(geometry.size.width, geometry.size.height) @@ -37,7 +42,8 @@ public struct BallZigZag: View { duration: duration, timingFunctions: timingFunctions, keyTimes: keyTimes) { - Circle() + type.view + .foregroundColor(color) .frame(width: objectDimension, height: objectDimension) .offset(x: values[index][$0].x, y: values[index][$0].y) } diff --git a/Sources/BallZigZagDeflect.swift b/Sources/BallZigZagDeflect.swift index 8888fcc..2993b06 100644 --- a/Sources/BallZigZagDeflect.swift +++ b/Sources/BallZigZagDeflect.swift @@ -14,12 +14,17 @@ public struct BallZigZagDeflect: View { private let keyTimes = [0, 0.16, 0.33, 0.5, 0.66, 0.83, 1] private let directionValues: [[UnitPoint]] = [[.zero, .init(x: -1, y: -1), .init(x: 1, y: -1), .zero, .init(x: 1, y: -1), .init(x: -1, y: -1), .zero], [.zero, .init(x: 1, y: 1), .init(x: -1, y: 1), .zero, .init(x: -1, y: 1), .init(x: 1, y: 1), .zero]] - + private let color: Color + private let type: BallType + public var body: some View { GeometryReader(content: render) } - public init() { } + public init(color: Color = .black, type: BallType = .outlined) { + self.color = color + self.type = type + } func render(geometry: GeometryProxy) -> some View { let dimension = min(geometry.size.width, geometry.size.height) @@ -37,7 +42,8 @@ public struct BallZigZagDeflect: View { duration: duration, timingFunctions: timingFunctions, keyTimes: keyTimes) { - Circle() + type.view + .foregroundColor(color) .frame(width: objectDimension, height: objectDimension) .offset(x: values[index][$0].x, y: values[index][$0].y) }