Created
January 12, 2025 06:10
-
-
Save Koshimizu-Takehito/4314dc875d4e0fcc8ae70447f827177a 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 = 1 + 10 * (sin(time) + 1) | |
Rectangle() | |
.colorEffect(shader(scale: scale)) | |
.foregroundStyle(.white) | |
.ignoresSafeArea() | |
} | |
} | |
func shader(scale: Double) -> Shader { | |
ShaderLibrary | |
.tile(.boundingRect, .float(scale)) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment