Skip to content

Commit

Permalink
Fixed SetColor Not Updating @ Speed = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Aug 14, 2024
1 parent b1acbe1 commit 14c17d7
Show file tree
Hide file tree
Showing 27 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Lakr233/SpringInterpolation.git",
"state" : {
"revision" : "be8721cffc87ec514fa13ba5dab586a2730f51c9",
"version" : "1.1.2"
"revision" : "ff526fec3ef6df62395141a0cc55a4ba2d82ee81",
"version" : "1.2.2"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{
"images" : [
{
"filename" : "RoundedIconTemplate.png",
"filename" : "新建项目.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"filename" : "icon_16x16.png",
"filename" : "icon-16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "icon_16x16@2x.png",
"filename" : "icon-16@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "icon_32x32.png",
"filename" : "icon-32.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "icon_32x32@2x.png",
"filename" : "icon-32@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "icon_128x128.png",
"filename" : "icon-128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "icon_128x128@2x.png",
"filename" : "icon-128@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "icon_256x256.png",
"filename" : "icon-256.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "icon_256x256@2x.png",
"filename" : "icon-256@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "icon_512x512.png",
"filename" : "icon-512.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "icon_512x512@2x.png",
"filename" : "icon-512@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Lakr233/SpringInterpolation.git",
"state" : {
"revision" : "be8721cffc87ec514fa13ba5dab586a2730f51c9",
"version" : "1.1.2"
"revision" : "ff526fec3ef6df62395141a0cc55a4ba2d82ee81",
"version" : "1.2.2"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/Lakr233/ColorVector.git", from: "1.0.3"),
.package(url: "https://github.com/Lakr233/SpringInterpolation.git", from: "1.1.2"),
.package(url: "https://github.com/Lakr233/SpringInterpolation.git", from: "1.2.2"),
],
targets: [
.target(
Expand Down
28 changes: 20 additions & 8 deletions Sources/ColorfulX/AnimatedMulticolorGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import SpringInterpolation

private let SPRING_CONFIG = SpringInterpolation.Configuration(
angularFrequency: 1.5,
dampingRatio: 0.2
dampingRatio: 0.2,
threshold: 0.001,
stopWhenHitTarget: true
)
private let SPRING_ENGINE = SpringInterpolation2D(SPRING_CONFIG)
private let defaultFrameRate: Int = 60
Expand Down Expand Up @@ -119,6 +121,22 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView {
return realDeltaTime
}

@inline(__always)
func isColorTransitionCompleted() -> Bool {
colorElements
.filter(\.enabled)
.allSatisfy { $0.transitionProgress.context.currentPos >= 1 }
}

@inline(__always)
public func shouldRenderNextFrameWithinSynchornization() -> Bool {
// if transition not completed, keep ticking until complete
if !isColorTransitionCompleted() { return true }
guard frameLimiterShouldScheduleNextFrame() else { return false }
guard speed > 0 || renderInputWasModified else { return false }
return true
}

// MARK: - RENDER LIFE CYCLE

override public func layoutSublayers(of layer: CALayer) {
Expand All @@ -140,14 +158,8 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView {
}

override func vsync() {
// check if we should render
guard frameLimiterShouldScheduleNextFrame() else { return }

// check if we need to update the render parameter
// the underlying MulticolorGradientView will only render if parameter was modified
guard speed > 0 || renderInputWasModified else { return }
guard shouldRenderNextFrameWithinSynchornization() else { return }
updateRenderParameters(deltaTime: deltaTimeForRenderParametersUpdate())

// sine the render parameters were updated, we call super.vsync to render
super.vsync()
}
Expand Down

0 comments on commit 14c17d7

Please sign in to comment.