diff --git a/src/main/scala/conways/ConwaysGameProcessing.scala b/src/main/scala/conways/ConwaysGameProcessing.scala index 0564de4..7c92da3 100644 --- a/src/main/scala/conways/ConwaysGameProcessing.scala +++ b/src/main/scala/conways/ConwaysGameProcessing.scala @@ -18,14 +18,14 @@ object ConwaysGameProcessing extends App { class ConwaysGame extends PApplet { val black = 0 val white = 255 - val screenSize = 1000 + val screenSize = 500 var current = new Grid(20) var started = false - var boxThickness = screenSize / current.size + def boxThickness = screenSize / current.size override def setup() = { - frameRate(10) + frameRate(20) size(screenSize, screenSize) background(0) } @@ -38,7 +38,6 @@ class ConwaysGame extends PApplet { } def drawGrid() { - boxThickness = screenSize / current.size background(0) current.liveCells.foreach {c => fill(white) @@ -57,6 +56,6 @@ class ConwaysGame extends PApplet { } override def keyPressed(e: KeyEvent) { - started = true + started = !started } } \ No newline at end of file diff --git a/src/main/scala/conways/Grid.scala b/src/main/scala/conways/Grid.scala index 8d9e456..02291ef 100644 --- a/src/main/scala/conways/Grid.scala +++ b/src/main/scala/conways/Grid.scala @@ -28,13 +28,15 @@ class Grid(minSize: Int) { } def fit { - val xMin = liveCells.map(_.x).min - val yMin = liveCells.map(_.y).min - if (xMin < 0 || yMin < 0) { - liveCells = liveCells.map(e => Cell(e.x - xMin, e.y - yMin)) - } - if ((xMin > 0 || yMin > 0) && size > minSize) { - liveCells = liveCells.map(e => Cell(e.x - (xMin - 1), e.y - (yMin - 1))) + if (!liveCells.isEmpty) { + val xMin = liveCells.map(_.x).min + val yMin = liveCells.map(_.y).min + if (xMin < 0 || yMin < 0) { + liveCells = liveCells.map(e => Cell(e.x - xMin, e.y - yMin)) + } + if ((xMin > 0 || yMin > 0) && size > minSize) { + liveCells = liveCells.map(e => Cell(e.x - (xMin - 1), e.y - (yMin - 1))) + } } } }