Last active
February 11, 2025 23:43
-
-
Save Koshimizu-Takehito/6823c17ee460797154bf99cf2d8f751a 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 + 30 * (sin(time) + 1) | |
Image("waterwheel") | |
.layerEffect( | |
mosaic(scale: scale), | |
maxSampleOffset: .zero | |
) | |
} | |
} | |
func mosaic(scale: Double) -> Shader { | |
ShaderLibrary | |
.mosaic(.float(scale)) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment