diff --git a/Sources/Vortex/Presets/Magic.swift b/Sources/Vortex/Presets/Magic.swift index 394545a..ff5d18c 100644 --- a/Sources/Vortex/Presets/Magic.swift +++ b/Sources/Vortex/Presets/Magic.swift @@ -19,7 +19,15 @@ extension VortexSystem { speedVariation: 0.2, angleRange: .degrees(360), angularSpeedVariation: [0, 0, 10], - colors: .random(.red, .pink, .orange, .blue, .green, .white), + colors: .randomRamp( + [.red, .red, .red.opacity(0)], + [.pink, .pink, .pink.opacity(0)], + [.orange, .orange, .orange.opacity(0)], + [.blue, .blue, .blue.opacity(0)], + [.green, .green, .green.opacity(0)], + [.white, .white, .white.opacity(0)], + fixed: false + ), size: 0.5, sizeVariation: 0.5, sizeMultiplierAtDeath: 0.01 diff --git a/Sources/Vortex/System/ColorMode.swift b/Sources/Vortex/System/ColorMode.swift index 03287ab..cf0d9e4 100644 --- a/Sources/Vortex/System/ColorMode.swift +++ b/Sources/Vortex/System/ColorMode.swift @@ -19,9 +19,11 @@ extension VortexSystem { /// Particles should move through an array of colors over time. case ramp(_ colors: [Color]) - /// The system should select one random color array, and give that - /// to each particle it creates. - case randomRamp(_ colors: [[Color]]) + /// Particles should move through one of several possible color arrays. + /// - Parameter fixed: When true, the system will select one random color array, + /// and give that to each particle. When false, the system will select a random + /// color array for each particle. + case randomRamp(_ colors: [[Color]], fixed: Bool = true) /// A convenience method to create random colors because Swift does not /// support variadic enum cases. @@ -37,8 +39,8 @@ extension VortexSystem { /// A convenience method to create random color ramps because Swift does not /// support variadic enum cases. - public static func randomRamp(_ colors: [Color]...) -> ColorMode { - .randomRamp(colors) + public static func randomRamp(_ colors: [Color]..., fixed: Bool = true) -> ColorMode { + .randomRamp(colors, fixed: fixed) } } } diff --git a/Sources/Vortex/System/VortexSystem-Behavior.swift b/Sources/Vortex/System/VortexSystem-Behavior.swift index c4e7ce9..43b29e5 100644 --- a/Sources/Vortex/System/VortexSystem-Behavior.swift +++ b/Sources/Vortex/System/VortexSystem-Behavior.swift @@ -227,8 +227,15 @@ extension VortexSystem { case .ramp(let colors): return colors - case .randomRamp(let colors): + case .randomRamp(let colors, true): return colors[selectedColorRamp] + + case .randomRamp(let colors, false): + if let randomRamp = colors.randomElement() { + return randomRamp + } else { + return [.white] + } } } } diff --git a/Sources/Vortex/System/VortexSystem.swift b/Sources/Vortex/System/VortexSystem.swift index ab330c3..ede0331 100644 --- a/Sources/Vortex/System/VortexSystem.swift +++ b/Sources/Vortex/System/VortexSystem.swift @@ -154,7 +154,7 @@ public class VortexSystem: Codable, Identifiable, Equatable, Hashable { /// then this system picks one possible color ramp to use. public var colors: ColorMode { didSet { - if case let .randomRamp(allColors) = colors { + if case let .randomRamp(allColors, true) = colors { self.selectedColorRamp = Int.random(in: 0..