Last active
January 13, 2025 07:57
-
-
Save Koshimizu-Takehito/0a8bd5123fcd081d082081ba1a48489f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
let start = Date() | |
var body: some View { | |
TimelineView(.animation) { context in | |
let time = context.date.timeIntervalSince(start) | |
let radius = 20 * (sin(time - .pi/2) + 1) | |
Image("waterwheel") | |
.modifier(ProgressiveBlur(radius: radius)) | |
} | |
} | |
} | |
struct ProgressiveBlur: ViewModifier { | |
let radius: Double | |
func body(content: Content) -> some View { | |
let offset = CGSize(width: radius, height: radius) | |
let shader = ShaderLibrary | |
.progressiveBlur(.boundingRect, .float(radius)) | |
content.layerEffect(shader, maxSampleOffset: offset) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment