Skip to content

Instantly share code, notes, and snippets.

@robb
Created June 26, 2022 09:52
Show Gist options
  • Star 62 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save robb/094f4f946d7f02c69b65bed19b0f25d9 to your computer and use it in GitHub Desktop.
Save robb/094f4f946d7f02c69b65bed19b0f25d9 to your computer and use it in GitHub Desktop.
import SwiftUI
struct GooeyView: View {
@State
var yPos: Double = 0.75
@State
var threshold: Double = 0.5
@State
var radius: Double = 15
var body: some View {
VStack(alignment: .leading) {
Text("Preview")
Color.pink.mask {
Canvas { ctx, size in
ctx.addFilter(.alphaThreshold(min: threshold))
ctx.addFilter(.blur(radius: radius))
// This drawing operation needs to happen on a separate layer
// for the effect to work.
ctx.drawLayer { ctx in
var rect = CGRect(x: 10, y: 50, width: 150, height: 150)
ctx.fill(Circle().path(in: rect), with: .color(.black))
rect.origin.x += yPos * (size.width - rect.width - 20.0)
ctx.fill(Circle().path(in: rect), with: .color(.black))
}
}
}
Group {
Text("y-Position")
Slider(value: $yPos)
Divider()
Text("Threshold")
Slider(value: $threshold, in: 0.01 ... 0.99)
Divider()
Text("Radius")
Slider(value: $radius, in: 0 ... 30)
}
}
.padding()
.font(.caption2)
}
}
struct GooeyView_Previews: PreviewProvider {
static var previews: some View {
GooeyView()
}
}
@aheze
Copy link

aheze commented Jun 26, 2022

Super clever!

@Elichartnett
Copy link

^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment