Last active
February 11, 2025 23:41
-
-
Save Koshimizu-Takehito/2317e4b6f7dd9a50d15df5c83f2ed2d2 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 { | |
@State private var start = Date() | |
var body: some View { | |
TimelineView(.animation) { context in | |
let time = context.date | |
.timeIntervalSince(start) | |
let scale = 0.3 + 6 * (sin(time) + 1) / 2 | |
Rectangle() | |
.colorEffect(shader(scale: scale)) | |
.foregroundStyle(.white) | |
.ignoresSafeArea() | |
} | |
} | |
func shader(scale: Double) -> Shader { | |
ShaderLibrary | |
.spiral(.boundingRect, .float(scale)) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment