diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView+SwiftUI.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView+SwiftUI.swift index b9b18bf..9f620c9 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView+SwiftUI.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView+SwiftUI.swift @@ -16,6 +16,7 @@ public struct AnimatedMulticolorGradientViewRepresentable { @Binding var transitionSpeed: Double let frameLimit: Int + let repeatToFillColorSlots: Bool public init( color: Binding<[ColorVector]>, @@ -23,7 +24,8 @@ public struct AnimatedMulticolorGradientViewRepresentable { bias: Binding = .constant(0.01), noise: Binding = .constant(0), transitionSpeed: Binding = .constant(3.25), - frameLimit: Int = 0 + frameLimit: Int = 0, + repeatToFillColorSlots: Bool = true ) { _color = color _speed = speed @@ -32,10 +34,15 @@ public struct AnimatedMulticolorGradientViewRepresentable { _transitionSpeed = transitionSpeed self.frameLimit = frameLimit + self.repeatToFillColorSlots = repeatToFillColorSlots } public func updatePropertyToView(_ view: AnimatedMulticolorGradientView) { - view.setColors(color, interpolationEnabled: transitionSpeed > 0) + view.setColors( + color, + interpolationEnabled: transitionSpeed > 0, + repeatToFillColorSlots: repeatToFillColorSlots + ) view.speed = speed view.bias = bias view.noise = noise diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift index f080d7f..f76565d 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift @@ -51,12 +51,12 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView { initializeRenderParameters() } - public func setColors(_ colors: [ColorVector], interpolationEnabled: Bool = true, fillColorsIfNeeded: Bool = true) { + public func setColors(_ colors: [ColorVector], interpolationEnabled: Bool = true, repeatToFillColorSlots: Bool = true) { var colors = colors if colors.isEmpty { colors.append(.init(v: .zero, space: .rgb)) } colors = colors.map { $0.color(in: .lab) } - let endingIndex = fillColorsIfNeeded ? Uniforms.COLOR_SLOT : min(colors.count, Uniforms.COLOR_SLOT) + let endingIndex = repeatToFillColorSlots ? Uniforms.COLOR_SLOT : min(colors.count, Uniforms.COLOR_SLOT) guard endingIndex > 0 else { return } for idx in 0 ..< endingIndex { var read = colorElements[idx]