AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Conway game of life python8/30/2023 Let’s suggest the following, in order of priority: We are flexible to decide on some intuitive rules for our new game, where we are aiming to model invasions. You can imagine the uses for this type of thinking in opposing sides of a war or invasions and spread of tribes or even disease. We can start thinking about how one may adapt these basic rules to analyse and model new systems.įor example, we can model two opposing populations, (“red” and “blue” say) where the presence of one species eliminates the other. Try out some different starting configurations and you may see particular cycles of shapes that researches have identified and named (see any source on Conway’s game of life for more info on these).Ī good one to draw is Gosper’s glider gun, which spawns “gliders” which travel off indefinitely. NewGrid = *GRIDWIDTH for i in range(GRIDHEIGHT)]Īnd that’s all you need. It then returns the new grid to be printed to the screen. For larger images I got an annoying error where would automatically save it in a different format meaning the colors were no longer recognised by the Python program.įinally, tick() counts live neighbours around each cell and implements Conway’s rules to decide if the cell lives or dies next generation. Also make sure to save the picture as a png and also 24 bit. The image also has to have the dimensions (GRIDWIDTH, GRIDHEIGHT) e.g in our scenario the image is 100 x 100. Make sure to change the path/ image file to wherever you save and call the image file. Grid = *GRIDWIDTH for i in range(GRIDHEIGHT)] GridImage = Image.open(path+'gridImage.png', 'r') The idea is that we can draw an image, save it and let the program read in each pixel, making any pixel we drew in black into a live cell. We will allow ourselves to create visual patterns and read them in using “pillow” or “PIL” module in python. Inputting initial configurations manually takes ages. The only things left to do are to define “initialConfiguration”, which is where we can input our desired starting pattern and “tick()” function, which updates the simulation to the next generation. (DISPLAYSURF, BLACK, (x*RW, y*RH, RW, RH)) import pygame, sys, timeĭISPLAYSURF = _mode((WINDOWWIDTH, WINDOWHEIGHT))ĬurrentGrid = initialConfiguration(GRIDWIDTH, GRIDHEIGHT) The following is the main method for displaying the current generation’s grid to the screen. Indeed, most of the code that follows actually only concerns printing the simulation to the screen the actual logic of the simulation is straightforward. I use the PyGame module (see the abundance of support online for installing/ information on it) to handle the visual side of things. The patterns and behaviours that are observed are entirely dependent on the initial configuration of dead and live cells on the grid, leading to interesting and often chaotic patterns, even between very similar looking starting configurations. The following gives examples of what happens to a particular square (blue) in different neighborhood scenarios.Īnd that’s it! Very simple rules but Conway’s game of life has been subject of much research since it’s conception.
0 Comments
Read More
Leave a Reply. |