Created
July 29, 2023 08:11
-
-
Save nakajima/ead46b6089d2ed32a8bf71f21181541f to your computer and use it in GitHub Desktop.
blendmode playground
This file contains 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 | |
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