Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created July 29, 2023 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakajima/ead46b6089d2ed32a8bf71f21181541f to your computer and use it in GitHub Desktop.
Save nakajima/ead46b6089d2ed32a8bf71f21181541f to your computer and use it in GitHub Desktop.
blendmode playground
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State private var mode: BlendMode = .normal
let cases: [BlendMode] = [
.normal,
.multiply,
.screen,
.overlay,
.darken,
.lighten,
.colorDodge,
.colorBurn,
.softLight,
.hardLight,
.difference,
.exclusion,
.hue,
.saturation,
.color,
.luminosity,
.sourceAtop,
.destinationOver,
.destinationOut,
.plusDarker,
.plusLighter,
]
var body: some View {
VStack {
ZStack {
Text("Hi")
.foregroundStyle(.pink)
.font(.largeTitle)
.padding()
Color.blue.blendMode(mode)
}
Picker("Mode", selection: $mode) {
ForEach(cases) { blendMode in
Text("\(blendMode.description)")
.tag(blendMode)
}
}
.pickerStyle(.wheel)
}
.frame(width: 400, height: 600)
}
}
extension BlendMode {
var description: String {
switch self {
case .normal:
"normal"
case .multiply:
"multiply"
case .screen:
"screen"
case .overlay:
"overlay"
case .darken:
"darken"
case .lighten:
"lighten"
case .colorDodge:
"colorDodge"
case .colorBurn:
"colorBurn"
case .softLight:
"softLight"
case .hardLight:
"hardLight"
case .difference:
"difference"
case .exclusion:
"exclusion"
case .hue:
"hue"
case .saturation:
"saturation"
case .color:
"color"
case .luminosity:
"luminosity"
case .sourceAtop:
"sourceAtop"
case .destinationOver:
"destinationOver"
case .destinationOut:
"destinationOut"
case .plusDarker:
"plusDarker"
case .plusLighter:
"plusLighter"
}
}
}
extension BlendMode: Identifiable {
public var id: Int { hashValue }
}
PlaygroundPage.current.setLiveView(ContentView())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment