Exemple #1
0
def main(script, *args):
    """Constructs the rabbits methusela.

    http://www.argentum.freeserve.co.uk/lex_r.htm#rabbits
    """

    rabbits = ['1000111', '111001', '01']

    n = 400
    m = 600
    life = Life(n, m)
    life.add_cells(n // 2, m // 2, *rabbits)
    viewer = LifeViewer(life)
    anim = viewer.animate(frames=100, interval=1)
    plt.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99)
    plt.show()
def make_viewer(n, m, row, col, *strings):
    """Makes a Life and LifeViewer object.
    n, m: rows and columns of the Life array 
    row, col: upper left coordinate of the cells to be added   
    strings: list of strings of '0' and '1'
    """
    life = Life(n, m)  # n行m列的格子
    life.add_cells(row, col, *strings)  # 左上角坐标
    viewer = LifeViewer(life)  # 瞅一眼
    return viewer
def main(script, *args):
    """Constructs the rabbits methusela.

    http://www.argentum.freeserve.co.uk/lex_r.htm#rabbits
    """

    rabbits = [
        '1000111',
        '111001',
        '01'
    ]

    n = 400
    m = 600
    life = Life(n, m)
    life.add_cells(n//2, m//2, *rabbits)
    viewer = LifeViewer(life)
    anim = viewer.animate(frames=100, interval=1)
    plt.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99)
    plt.show()
Exemple #4
0
def main(script, *args):
    """Constructs a puffer train.

    Uses the entities in this file:
    http://www.radicaleye.com/lifepage/patterns/puftrain.lif
    """
    lwss = ['0001', '00001', '10001', '01111']

    bhep = ['1', '011', '001', '001', '01']

    n = 400
    m = 600
    life = Life(n, m)

    col = 120
    life.add_cells(n // 2 + 12, col, *lwss)
    life.add_cells(n // 2 + 26, col, *lwss)
    life.add_cells(n // 2 + 19, col, *bhep)
    viewer = LifeViewer(life)
    anim = viewer.animate(frames=100, interval=1)
    plt.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99)
    plt.show()
Exemple #5
0
    def run_life(self):
        dic = {}
        check_repeat = self.ui.cbCheckRepeat.isChecked()
        world = LifeWorld(self.ui.sbWorldSize.value(),
                          self.ui.cbRandomInit.isChecked())
        # vm = input("select viewer: 0 - text, 1 - graphics\n")
        # if vm not in {'0', '1'}:
        #    raise Exception("error")

        if self.ui.cbOutType.currentIndex() == 0:
            viewer = LifeViewer()
        else:
            viewer = TurtleViewer(self.ui.sbWindowSize.value(),
                                  self.ui.sbWindowSize.value())

        while world.next_generation():
            if check_repeat:
                _hash = world.get_hash()
                val = dic.get(_hash)
                if val is None:
                    dic[_hash] = world.get_generation()
                else:
                    break
            viewer.show_world(world, False, '')
            #    viewer.show_world(world)
            time.sleep(self.ui.dsbDelay.value())

        legend = ''
        print(
            "-------------COMPLETION OF EVOLUTION  {}-----------------".format(
                world.get_generation()))

        if world.get_empty():
            legend = "-------------EXTINCTION IN GENERATION {}-----------------".format(
                world.get_generation())
        else:
            _hash = world.get_hash()
            gen = dic.get(_hash)
            if gen is not None:
                if world.get_generation() - gen == 1:
                    legend = "-------------STABLE CONFIGURATION IN GENERATION {}-----------------".format(
                        gen)
                else:
                    legend = "-------------REPEAT CONFIGURATION FROM GENERATION {}-----------------".format(
                        gen)

        viewer.show_world(world, True, legend)
        print(legend)
Exemple #6
0
    for i in str:
        a = int(i)

    dic = {}
    check_repeat = True
    world = LifeWorld(10, 10)
    # vm = input("select viewer: 0 - text, 1 - graphics\n")
    # if vm not in {'0', '1'}:
    #    raise Exception("error")

    #if self.ui.cbOutType.currentIndex() == 0:
    #    viewer = LifeViewer()
    #else:

    #viewer = TurtleViewer(800, 800)
    viewer = LifeViewer()

    while world.next_generation():
        if check_repeat:
            _hash = world.get_hash()
            val = dic.get(_hash)
            if val is None:
                dic[_hash] = world.get_generation()
            else:
                break
        viewer.show_world(world, False, '')
        #    viewer.show_world(world)
        time.sleep(0.05)

    legend = ''
    print("-------------COMPLETION OF EVOLUTION  {}-----------------".format(