Skip to content

Instantly share code, notes, and snippets.

@Pasanpr
Created December 19, 2016 15:38
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 Pasanpr/28c5b0aad8bc7f24737bfbc73ca8462d to your computer and use it in GitHub Desktop.
Save Pasanpr/28c5b0aad8bc7f24737bfbc73ca8462d to your computer and use it in GitHub Desktop.
Code snippet for Mixed Semantics video
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
}
}
@pcachia
Copy link

pcachia commented Aug 11, 2019

thank you for the code

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