- A community for Conway's Game of Life and related cellular automata
Home  •  LifeWiki  •  Forums  •  Download Golly

A Python program with GUI

For general discussion about Conway's Game of Life.

A Python program with GUI

Postby PySimpleGUI » December 20th, 2018, 2:05 pm

I hope this is the right forum to post this....

I created a Python version of the Game of Life, complete with GUI. I utilized an existing game engine and added a GUI on top. You can use the mouse to create the initial board, control the speed and number of generations.

I'm open to adding reading an initial file, etc, if people are interested in using it.

https://user-images.githubusercontent.c ... a87c68.gif

Because PySimpleGUI code tends to be quite compact, the program is maybe 140 lines when you remove the large comment block. Not bad considering the interactivity of it all.

Comments and feedback welcomed.
Posts: 5
Joined: December 20th, 2018, 1:58 pm

Re: A Python program with GUI

Postby Senso » December 21st, 2018, 5:17 am

PySimpleGUI wrote:Comments and feedback welcomed.

Good job. I can't say anything else since you're not linking to your program.
User avatar
Posts: 18
Joined: November 1st, 2018, 11:36 am
Location: I call that one "shoving match"

Re: A Python program with GUI

Postby PySimpleGUI » December 21st, 2018, 12:25 pm

Ooops! Sorry about not linking the code...

Conways Life using PySimpleGUI
Posts: 5
Joined: December 20th, 2018, 1:58 pm

Re: A Python program with GUI

Postby Redstoneboi » December 30th, 2018, 11:50 am

I feel like
if (x != self.N and y != self.N):
                    s += self.old_grid[x][y]
                # The remaining branches handle the case where the neighbour is off the end of the grid.
                # In this case, we loop back round such that the grid becomes a "toroidal array".
                elif (x == self.N and y != self.N):
                    s += self.old_grid[0][y]
                elif (x != self.N and y == self.N):
                    s += self.old_grid[x][0]
                    s += self.old_grid[0][0]
could've been
int newX = x % self.N
int newY = y % self.N
# We need to make sure that the neighbor is still on the grid, so we make it wrap around using modulo.
s += self.old_grid[newX][newY]
saves a bunch of lines.
it uses the modulo (%) operator, which in x % y results in x wrapping around within range y, exactly what you want.

if (self.old_grid[i][j] == 1 and live < 2):
                        self.new_grid[i][j] = 0  # Dead from starvation.
                    elif (self.old_grid[i][j] == 1 and (live == 2 or live == 3)):
                        self.new_grid[i][j] = 1  # Continue living.
                    elif (self.old_grid[i][j] == 1 and live > 3):
                        self.new_grid[i][j] = 0  # Dead from overcrowding.
                    elif (self.old_grid[i][j] == 0 and live == 3):
                        self.new_grid[i][j] = 1  # Alive from reproduction.

"continue living" seems like a useless line, doesn't change anything considering you added the "starvation or overcrowding only" part.
also have you considered a list of boolean values to hold the rule? so you could get all the outer totalistic rules.
you could have like a 2*9 array, containing birth rules to survival, so you can explore highlife and life without death and seeds and more!
I'm not really a Python programmer, more of a C++ coder though.
This is Fluffy the cat.
Fluffy wants to discover new things that everyone likes.
Fluffy thinks about engineering replicators.
Fluffy likes to watch spaceship guns in Golly.
Fluffy knows Natsuki best girl.
User avatar
Posts: 332
Joined: May 14th, 2018, 3:57 am

Re: A Python program with GUI

Postby PySimpleGUI » December 30th, 2018, 1:26 pm

Thanks for checking out the Life-specific portions. I have barely read through that code to be honest. My contribution to this was strictly the GUI.

I grabbed the code off the net and used as-is, with no modification. I was happy it worked. Credit is at the top.

I appreciate you taking the time to look at the code and write up some concrete suggestions :!:
Posts: 5
Joined: December 20th, 2018, 1:58 pm

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests