Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/Vortex/Presets/Magic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions Sources/Vortex/System/ColorMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}
}
9 changes: 8 additions & 1 deletion Sources/Vortex/System/VortexSystem-Behavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
}
4 changes: 2 additions & 2 deletions Sources/Vortex/System/VortexSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<allColors.count)
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public class VortexSystem: Codable, Identifiable, Equatable, Hashable {

lastUpdate -= startTimeOffset

if case let .randomRamp(allColors) = colors {
if case let .randomRamp(allColors, true) = colors {
selectedColorRamp = Int.random(in: 0..<allColors.count)
}
}
Expand Down