Skip to content

Instantly share code, notes, and snippets.

@rudrankriyam
Created October 9, 2020 20:21
Show Gist options
  • Select an option

  • Save rudrankriyam/c68d1bd27308c8a84a171e7a521e1203 to your computer and use it in GitHub Desktop.

Select an option

Save rudrankriyam/c68d1bd27308c8a84a171e7a521e1203 to your computer and use it in GitHub Desktop.
Protocols of Gradient Game
import SwiftUI
protocol ColorProtocol {
var red: Double { get set }
var green: Double { get set }
var blue: Double { get set }
func newColor() -> Color
}
extension ColorProtocol {
func newColor() -> Color {
Color(red: red, green: green, blue: blue, opacity: 1.0)
}
}
import SwiftUI
protocol GradientProtocol {
var leftColor: ColorProtocol { get set }
var rightColor: ColorProtocol { get set }
func newGradient() -> Gradient
}
extension GradientProtocol {
func newGradient() -> Gradient {
Gradient(colors: [leftColor.newColor(), rightColor.newColor()])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment