-
-
Save Erica-Iris/f43e528d3dff203cb1578ca9d5223ef3 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