Coder Social home page Coder Social logo

crixodia / java-game-of-life Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 14.22 MB

game of life in java with swing components

Home Page: http://crixodia.com/java-game-of-life/

License: GNU General Public License v3.0

Java 100.00%
java swing-gui game-of-life game-development game-dev automatons matrix-calculations object-oriented-programming

java-game-of-life's Introduction

Java Game Of Life

The Game of Life is a cellular automaton designed by the British mathematician John Horton Conway in 1970. It is a zero-player game, which means that its evolution is determined by the initial state and does not require any further input of data.

Contents

Rules

The "game board" is a flat, toroidal grid made up of squares (the "cells") that extends infinitely in all directions. Therefore, each cell has 8 "neighbors", which are the ones that are closest to it, including diagonals. The cells have two states: they are either "alive" or "dead" (or "on" and "off"). The state of the cells evolves over discrete units of time (you could say by turns). The state of all cells is taken into account to calculate their state in the next turn. All cells are updated simultaneously in each turn, following these rules:

  1. A dead cell with exactly 3 live neighboring cells "comes to life" (i.e., in the next turn it will be alive).
  2. A live cell with 2 or 3 live neighboring cells remains alive, otherwise it dies (due to "loneliness" or "overcrowding").

Extracted from Wikipedia

GUI

Controls

The control window will allow you to start the computation of the game's states. Use the Play button to start the game (you can stop it with the Stop button). Additionally, we will observe the population of each state and its respective generation.

Saving and Loading patterns

An important feature of the GUI is that we can save and load patterns. To save a pattern, simply draw one beforehand on the grid by clicking on the desired locations. Then, in the control window, the "Save" button will create a jglf format file with a list of coordinates where the cells are alive.

Once we have our own patterns, we can load them using the "Open" button. Then, it will automatically clear the grid and load the entire cells.

Grid

On the grid, we will visualize the change of states and (when the game is paused) we can draw custom patterns. The game is programmed toroidally (similar to the surface of a planet represented on a plane). Therefore, the grid is NOT infinite.

Animations

You can generate animations through the button specified in the GUI. Then, you will need to provide an output path for the generated images and the colors to use. Additionally, it is possible to take any file and convert it to a starting pattern for the game based on the bytes of the file. This is useful for generating various patterns without "drawing" them on the grid, especially for quick testing purposes.

Examples

You can download some patterns as examples. One of the most intriguing ones are the oscillators (osc.jglf).

When generating a gif animation, you will get something similar to the following image. You can define the possibility of an infinite loop for the gif.

๐Ÿง For suggestions or questions, you can contact @crixodia

java-game-of-life's People

Contributors

crixodia avatar imgbotapp avatar

Watchers

 avatar  avatar

Forkers

josanchezsa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.