Skip to content

Instantly share code, notes, and snippets.

@ashishkakkad8
Created July 30, 2024 19:18
Show Gist options
  • Save ashishkakkad8/e222dfa1e118575c0ade2eea58a25aa3 to your computer and use it in GitHub Desktop.
Save ashishkakkad8/e222dfa1e118575c0ade2eea58a25aa3 to your computer and use it in GitHub Desktop.
Animate MeshGradient in SwiftUI
TimelineView(.animation) { timeline in
let x = (sin(timeline.date.timeIntervalSince1970) + 1) / 2
MeshGradient(
width: 3,
height: 3,
points: [
[0.0, 0.0], [0.5, 0.0], [1.0, 0.0],
[0.0, 0.5], [Float(x), 0.5], [1.0, 0.5],
[0.0, 1.0], [0.5, 1.0], [1.0, 1.0]
], colors: [
.red, .red, .red,
.black, .red, .black,
.black, .red, .black
])
.edgesIgnoringSafeArea(.all)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment