diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView+Speckle.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView+Speckle.swift index eb7b17c..6f6f57f 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView+Speckle.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView+Speckle.swift @@ -92,11 +92,3 @@ public extension AnimatedMulticolorGradientView { } } } - -extension SpringInterpolation2D { - var distanceToTarget: CGFloat { - let dx = x.context.currentPos - x.context.targetPos - let dy = y.context.currentPos - y.context.targetPos - return sqrt(dx * dx + dy * dy) - } -} diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView+Update.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView+Update.swift index c0d3b8f..7f0211a 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView+Update.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView+Update.swift @@ -38,7 +38,15 @@ extension AnimatedMulticolorGradientView { speckle.position.update(withDeltaTime: moveDelta) } - if speckle.position.distanceToTarget < 50 { + let pos_x = speckle.position.x.context.currentPos + let tar_x = speckle.position.x.context.targetPos + let pos_y = speckle.position.y.context.currentPos + let tar_y = speckle.position.y.context.targetPos + let shouldUpdateLocation = false + || abs(pos_x - tar_x) < 0.125 + || abs(pos_y - tar_y) < 0.125 + + if shouldUpdateLocation { let rand = randomLocationPair() speckle.position.setTarget(.init(x: rand.x, y: rand.y)) } diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift index 55e8d6f..b7dce09 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift @@ -13,8 +13,8 @@ import SpringInterpolation private let SPRING_CONFIG = SpringInterpolation.Configuration( angularFrequency: 1.5, dampingRatio: 0.2, - threshold: 0.001, - stopWhenHitTarget: false + threshold: 0.0001, + stopWhenHitTarget: true ) private let SPRING_ENGINE = SpringInterpolation2D(SPRING_CONFIG) private let defaultFrameRate: Int = 60