Created
November 12, 2015 21:07
-
-
Save osvein/08ffeeb09b051e7d36af to your computer and use it in GitHub Desktop.
Game of Life for TI-Nspire
This file contains hidden or 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
| --[[ | |
| The MIT License (MIT) | |
| Copyright (c) 2015 Oskar Sveinsen | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all | |
| copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| SOFTWARE. | |
| ]]-- | |
| pause = true | |
| editMode = false | |
| period = 0.1 | |
| pix_width = 16 | |
| pix_height = 16 | |
| width = 0 | |
| height = 0 | |
| grid = {} | |
| menu = { | |
| {"Edit", edit}, | |
| {"Clear", clear}, | |
| "-", | |
| {"Resize", resize}, | |
| {"Adjust speed", speed} | |
| } | |
| function on.draw(gc) | |
| end | |
| function on.timer() | |
| end | |
| function on.escapeKey() | |
| if pause then | |
| timer.start(period) | |
| else | |
| timer.stop() | |
| end | |
| end | |
| function on.mouseDown(x, y) | |
| if editMode then | |
| -- flip pixel | |
| grid[x / pix_width][y / pix_height] = not grid[x / pix_width][y / pix_height] | |
| else | |
| -- skip tick | |
| end | |
| end | |
| function on.charIn(char) | |
| if char == "+" then | |
| period = period - 0.01 | |
| else if char == "-" then | |
| period = period + 0.01 | |
| else if char == "*" then | |
| period = period - 0.1 | |
| else if char == "/" then | |
| period = period + 0.1 | |
| end | |
| timer.start(period) | |
| end | |
| function on.save() | |
| end | |
| function on.restore(state) | |
| end | |
| function edit() | |
| end | |
| function clear() | |
| end | |
| function resize() | |
| math.eval("Request \"Pixel width:\",pixel_width") | |
| pixel_width = var.recall("pixel_width") | |
| math.eval("Request \"Pixel height:\",pixel_height") | |
| pixel_height = var.recall("pixel_height") | |
| math.eval("Request \"Grid width (0 = auto):\",width") | |
| width = var.recall("width") | |
| math.eval("Request \"Grid height (0 = auto):\",height") | |
| height = var.recall("height") | |
| end | |
| function speed() | |
| math.eval("Request \"Seconds per tick:\",period") | |
| period = var.recall("period") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment