Created
February 16, 2025 08:09
-
-
Save Koshimizu-Takehito/9b67e5c91cb1440344c8708ae5a12430 to your computer and use it in GitHub Desktop.
Circle SDF2
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 | |
@State var k: Double = 0.36 | |
@State var time: Double = .pi | |
var body: some View { | |
ZStack { | |
Rectangle() | |
.colorEffect(shader) | |
VStack { | |
Button("Reset", action: reset) | |
.frame(maxWidth: .infinity, alignment: .leading) | |
.font(.title) | |
.fontWeight(.bold) | |
Slider(value: $time, in: 0...(2.0 * .pi)) | |
Slider(value: $k, in: 0...0.72) | |
} | |
.frame(maxHeight: .infinity, alignment: .bottom) | |
.padding() | |
} | |
.animation(.default, value: k) | |
.animation(.default, value: time) | |
} | |
private var shader: Shader { | |
let function = ShaderFunction(library: .default, name: name) | |
return function(.boundingRect, .float(time), .float(k)) | |
} | |
private func reset() { | |
k = 0.36 | |
time = .pi | |
} | |
} | |
#Preview("SDF") { | |
ShaderView(name: "SDF::main") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment