![]() append ( 0 ) elif not cell_is_alive and cell_neighbours = 3 : next_universe. set_pixel ( x, y, universe ) def evolve ( universe ): next_universe = for y in range ( 0, 5 ): for x in range ( 0, 5 ): cell_neighbours = count_neighbours ( universe, x, y ) cell_is_alive = cell_state ( universe, x, y ) = 1 if cell_is_alive and cell_neighbours 3 : next_universe. set_pixel ( x, y, 6 ) def draw_universe ( universe ): for y in range ( 0, 5 ): for x in range ( 0, 5 ): display. Read moreįrom microbit import * def draw_cursor ( universe, mode, x, y ): if mode = "CONFIG" : if cell_state ( universe, x, y ) = 0 : display. In this case a grace zone of 200 is used to avoid unwanted cursor movements. The accelerometer values (x, y, z) goes from -1024 to +1024, when it is flat the x and the y values are both (more or less) 0. The interesting thing here is the accelerometer managing at row 71. The same trick is in the row 73 and following.Īt row 59 there's the main loop, it is basically divided in 2 parts: the RUN mode and the CONFIG mode. In count_neighbours at row 43 there's the trick for the toroidal universe: the module operator (%). The core is the function evolve (row 15), in this function there are all the rules defined on top of this page.Īt rows 33 and 39 there are 2 support function for evolve : cell_state and count_neighbours. These functions sets the led luminosity at various levels, 0 for an empty cell, 9 for a populated cell, 4 for and empty cell with the cursor on it and 6 for a populated cell with a cursor on it. Line and dot: an oscillator with period 4.Īt rows 3 an 5 there are the 2 "draw" functions: draw_universe and draw_cursor. Button A: enable or disable the cell under the cursor.In the CONFIG mode you can set up the start configuration, using the B button you can RUN it and watch the universe evolve, at any time you can modify the universe and watch what's happen. The script has 2 modes: "CONFIG" and "RUN". Name your project (top right).n Follow the "Instructions" on the right to compile and upload the script to your micro:bit. Remove the existing code and copy / paste the code below. Go to this BBC micro:bit page, press "Create Code" and choose "MicroPython", now you are in the Python Editor. If you don't know how to upload the hex file you can find a tutorial here, the detailed instructions are in step 3. With a so small space available some patterns acts in a strange way, we start exploring it.ĭownload the hex file below and upload it to the micro:bit. In this implementation the universe is a toroidal 5x5 grid, this means the top 5 cells are adjacent with the bottom 5 cells, the same for the left and right cells. The rules continue to be applied repeatedly to create further generations.Įxtracted from the Wikipedia page about Conway's Game of Life. The first generation is created by applying the above rules simultaneously to every cell in the seed-births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The initial pattern constitutes the seed of the system. At each step in time, the following transitions occur:Īny live cell with fewer than two live neighbours dies, as if caused by underpopulation.Īny live cell with two or three live neighbours lives on to the next generation.Īny live cell with more than three live neighbours dies, as if by overpopulation.Īny dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. Each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". At each step, the universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |