Skip to content

Instantly share code, notes, and snippets.

View BeauNouvelle's full-sized avatar
👨‍💻
Working

Beau Nouvelle BeauNouvelle

👨‍💻
Working
View GitHub Profile
case 3 where cell.state == .dead:
let liveCell = Cell(x: cell.x, y: cell.y, state: .alive)
updatedCells.append(liveCell)
let livingNeighbors = liveCells.filter { $0.isNeighbor(to: cell) }
switch livingNeighbors.count {
case 2...3 where cell.state == .alive:
updatedCells.append(cell)
}
var updatedCells = [Cell]()
let liveCells = cells.filter { $0.state == .alive }
for cell in cells {
}
cells = updatedCells
let view = WorldView(worldSize: 10, cellSize: 10)
PlaygroundPage.current.liveView = view
for cell in world.cells {
let rect = CGRect(x: cell.x * cellSize, y: cell.y * cellSize, width: cellSize, height: cellSize)
let color = cell.state == .alive ? UIColor.green.cgColor : UIColor.white.cgColor
context?.addRect(rect)
context?.setFillColor(color)
context?.fill(rect)
}
let context = UIGraphicsGetCurrentContext()
context?.saveGState()
public override func draw(_ rect: CGRect) {
}
public override init(frame: CGRect) {
super.init(frame: frame)
}
public required init?(coder aDecoder: NSCoder) {
fatalError("Not implemented")
}