project/main.py
def langtons_ant():
    """
    Creates field for Langton's ant
    """

    ####################
    # Initialize field #
    ####################
    # screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE)
    screen = pygame.display.set_mode(size_monitor, pygame.RESIZABLE)
    screen.fill(black)
    langton.reset(screen)
    langton.transition(screen)

    #############
    # Game Loop #
    #############
    generation = 0
    while True:
        pygame.display.set_caption(
            "Langston's Ant - Generation " + str(generation))
        # clock.tick(fps)  # Comment out for fastest performance
        keys = pygame.key.get_pressed()

        # Continually iterates through generations while space is held
        if keys[pygame.K_SPACE]:
            langton.transition(screen)
            generation += 1

        # Resets field and generation to 0 using command Ctrl + R
        if (keys[pygame.K_LCTRL] or keys[pygame.K_RCTRL]) and keys[pygame.K_r]:
            langton.reset(screen)
            generation = 0
            pygame.display.set_caption(
                "Langston's Ant - Generation " + str(generation))

        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                button, choice = event.button, 'N'  # default orientation is North
                if keys[pygame.K_UP]:  # Hold up arrow for North
                    choice = "N"
                if keys[pygame.K_RIGHT]:  # Hold up arrow for East
                    choice = "E"
                if keys[pygame.K_DOWN]:  # Hold up arrow for South
                    choice = "S"
                if keys[pygame.K_LEFT]:  # Hold up arrow for West
                    choice = "W"

                if button == 1:  # place ant in new location
                    pos = pygame.mouse.get_pos()
                    generation = 0
                    pygame.display.set_caption(
                        "Langston's Ant - Generation " + str(generation))
                    langton.click(pos, choice, screen)
                elif button == 3:  # iterate through next generation once right click
                    langton.transition(screen)
                    generation += 1
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        pygame.display.update()

    Creates field for Langton's ant
    
Creates field for Langton's ant
Creates field for Langton ' s ant
def langtons_ant():
    screen = pygame.display.set_mode(size_monitor, pygame.RESIZABLE)
    screen.fill(black)
    langton.reset(screen)
    langton.transition(screen)
    generation = 0
    while True:
        pygame.display.set_caption(
            "Langston's Ant - Generation " + str(generation))
        keys = pygame.key.get_pressed()
        if keys[pygame.K_SPACE]:
            langton.transition(screen)
            generation += 1
        if (keys[pygame.K_LCTRL] or keys[pygame.K_RCTRL]) and keys[pygame.K_r]:
            langton.reset(screen)
            generation = 0
            pygame.display.set_caption(
                "Langston's Ant - Generation " + str(generation))
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                button, choice = event.button, 'N'  
                if keys[pygame.K_UP]:  
                    choice = "N"
                if keys[pygame.K_RIGHT]:  
                    choice = "E"
                if keys[pygame.K_DOWN]:  
                    choice = "S"
                if keys[pygame.K_LEFT]:  
                    choice = "W"
                if button == 1:  
                    pos = pygame.mouse.get_pos()
                    generation = 0
                    pygame.display.set_caption(
                        "Langston's Ant - Generation " + str(generation))
                    langton.click(pos, choice, screen)
                elif button == 3:  
                    langton.transition(screen)
                    generation += 1
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.update()
def langtons_ant ( ) : screen = pygame . display . set_mode ( size_monitor , pygame . RESIZABLE ) screen . fill ( black ) langton . reset ( screen ) langton . transition ( screen ) generation = 0 while True : pygame . display . set_caption ( "Langston's Ant - Generation " + str ( generation ) ) keys = pygame . key . get_pressed ( ) if keys [ pygame . K_SPACE ] : langton . transition ( screen ) generation += 1 if ( keys [ pygame . K_LCTRL ] or keys [ pygame . K_RCTRL ] ) and keys [ pygame . K_r ] : langton . reset ( screen ) generation = 0 pygame . display . set_caption ( "Langston's Ant - Generation " + str ( generation ) ) for event in pygame . event . get ( ) : if event . type == pygame . MOUSEBUTTONDOWN : button , choice = event . button , 'N' if keys [ pygame . K_UP ] : choice = "N" if keys [ pygame . K_RIGHT ] : choice = "E" if keys [ pygame . K_DOWN ] : choice = "S" if keys [ pygame . K_LEFT ] : choice = "W" if button == 1 : pos = pygame . mouse . get_pos ( ) generation = 0 pygame . display . set_caption ( "Langston's Ant - Generation " + str ( generation ) ) langton . click ( pos , choice , screen ) elif button == 3 : langton . transition ( screen ) generation += 1 if event . type == pygame . QUIT : pygame . quit ( ) sys . exit ( ) pygame . display . update ( )
Creates field for Langton's ant
Creates field for Langton ' s ant
"""
    Creates field for Langton's ant
    """ #################### # Initialize field # #################### # screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE) ############# # Game Loop # ############# # clock.tick(fps)  # Comment out for fastest performance # Continually iterates through generations while space is held # Resets field and generation to 0 using command Ctrl + R # default orientation is North # Hold up arrow for North # Hold up arrow for East # Hold up arrow for South # Hold up arrow for West # place ant in new location # iterate through next generation once right click