Adding a speed boost to hasten the rate of spin

This commit is contained in:
Joe Fabisevich 2024-05-25 12:08:17 -04:00
parent 18b48455e4
commit 036e0c16e8
No known key found for this signature in database

View file

@ -44,10 +44,11 @@ public extension AnyChangeEffect {
/// - anchor: The location with a default of center that defines a point in 3D space about which the rotation is anchored.
/// - anchorZ: The location with a default of 0 that defines a point in 3D space about which the rotation is anchored.
/// - perspective: The relative vanishing point with a default of 1 / 6 for this rotation.
/// - perspective: An additional multipler you can provide to speed up the animation's runtime.
/// - rate: The rate of the spin.
static func spin(axis: (x: CGFloat, y: CGFloat, z: CGFloat), anchor: UnitPoint = .center, anchorZ: CGFloat = 0, perspective: CGFloat = 1 / 6, rate: SpinRate = .default) -> AnyChangeEffect {
static func spin(axis: (x: CGFloat, y: CGFloat, z: CGFloat), anchor: UnitPoint = .center, anchorZ: CGFloat = 0, perspective: CGFloat = 1 / 6, multiplier speedBoost: CGFloat = 0.0, rate: SpinRate = .default) -> AnyChangeEffect {
.simulation { change in
SpinSimulationModifier(impulseCount: change, axis: axis, anchor: anchor, anchorZ: anchorZ, perspective: perspective, rate: rate)
SpinSimulationModifier(impulseCount: change, axis: axis, anchor: anchor, anchorZ: anchorZ, perspective: perspective, additionalSpeed: speedBoost, rate: rate)
}
}
}
@ -67,6 +68,8 @@ internal struct SpinSimulationModifier: ViewModifier, Simulative {
var perspective: CGFloat
var additionalSpeed: CGFloat
var rate: AnyChangeEffect.SpinRate
@State
@ -124,7 +127,7 @@ internal struct SpinSimulationModifier: ViewModifier, Simulative {
if abs(angleVelocity.degrees) > 240 {
newValue = angle.degrees + angleVelocity.degrees * step
newVelocity = angleVelocity.degrees * 0.99
newVelocity = angleVelocity.degrees * (0.99 - self.additionalSpeed)
targetAngle = .degrees((angle.degrees / 360.0).rounded(.up) * 360.0)
} else if spring.response > 0 {
(newValue, newVelocity) = spring.value(