Skip to content

Instantly share code, notes, and snippets.

View danwatford's full-sized avatar

Daniel Watford danwatford

View GitHub Profile
/**
* A Panel which will draw a grid of cells as either On or Off according to a given function.
*/
class OnOffGrid(val cellsX: Int, val cellsY: Int, cellWidth: Int = 20, cellHeight: Int = 20) extends Panel with Publishe
r {
preferredSize = new Dimension(cellsX * cellWidth, cellsY * cellHeight)
listenTo(mouse.clicks)
reactions += {
case MouseClicked(_, point, _, _, _) => publish(CellClicked(this, point.x / cellWidth, point.y / cellHeight))
@danwatford
danwatford / GofLUI.scala
Last active August 29, 2015 14:01
UI for Game of Life in Scala
object GofUI extends SimpleSwingApplication {
val grid = new OnOffGrid(20, 20) {
onOff = gridCellIsLive
}
val tickButton = new Button {
text = "Tick"
}
def top = new MainFrame {
title = "Game of Life"