Skip to content

Commit

Permalink
Revert Location Update Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Aug 17, 2024
1 parent 8dbe5e3 commit 1f667fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 9 additions & 1 deletion Sources/ColorfulX/AnimatedMulticolorGradientView+Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ColorfulX/AnimatedMulticolorGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f667fe

Please sign in to comment.