-
-
Save Pasanpr/28c5b0aad8bc7f24737bfbc73ca8462d to your computer and use it in GitHub Desktop.
Code snippet for Mixed Semantics video
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
struct Point { | |
let x: Double | |
let y: Double | |
} | |
struct Size { | |
let width: Double | |
let height: Double | |
} | |
struct Rect { | |
let origin: Point | |
let size: Size | |
} | |
struct Color { | |
let red: Double | |
let green: Double | |
let blue: Double | |
let alpha: Double | |
static var blue: Color { | |
return Color(red: 0, green: 0, blue: 1) | |
} | |
static var red: Color { | |
return Color(red: 1.0, green: 0, blue: 0) | |
} | |
static var white: Color { | |
return Color(red: 0, green: 0, blue: 0) | |
} | |
init(red: Double, green: Double, blue: Double, alpha: Double = 1.0) { | |
self.red = red/255.0 | |
self.green = green/255.0 | |
self.blue = blue/255.0 | |
self.alpha = alpha | |
} | |
} | |
class View { | |
var frame: Rect | |
var backgroundColor: Color = .white | |
init(frame: Rect) { | |
self.frame = frame | |
} | |
} | |
struct Shape { | |
let view: View | |
init(x: Double, y: Double, width: Double, height: Double, color: Color) { | |
let origin = Point(x: x, y: y) | |
let size = Size(width: width, height: height) | |
let rect = Rect(origin: origin, size: size) | |
self.view = View(frame: rect) | |
view.backgroundColor = color | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for the code