Created
February 15, 2025 10:50
-
-
Save Koshimizu-Takehito/d1de708e3c4820e4bf759bea14cf08ad to your computer and use it in GitHub Desktop.
Circle SDF
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 ShaderView: View { | |
let name: String | |
private let start = Date() | |
var body: some View { | |
TimelineView(.animation) { context in | |
Rectangle().colorEffect(shader( | |
seconds: context.date.timeIntervalSince(start) | |
)) | |
} | |
.ignoresSafeArea() | |
} | |
private func shader(seconds: TimeInterval) -> Shader { | |
let function = ShaderFunction(library: .default, name: name) | |
return function(.boundingRect, .float(seconds)) | |
} | |
} | |
#Preview("SDF") { | |
ShaderView(name: "SDF::main") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment