project/grid.py
def transition(self, surface):
        """
        Updates cells colors on field between each transition
        """
        ant_xpos, ant_ypos = self.ant[0], self.ant[1]
        ant_xcoord, ant_ycoord = ant_xpos * self.scale, ant_ypos * self.scale

        if self.curr_array[ant_xpos][ant_ypos] == -1:  # curr cell is white (default)
            self.curr_array[ant_xpos][ant_ypos] = 0  # change cell to first color
            self.rotate(self.rules[0])  # rotate direction based on first rule

            # Update color of cell ant is currently on
            # Move ant forward in current direction
            # Draw ant on that forward cell
            pygame.draw.rect(surface, self.colors[0],
                             [ant_xcoord, ant_ycoord, self.scale - self.border, self.scale - self.border])
            self.move()
            pygame.draw.rect(surface, (255, 0, 0),
                             [self.ant[0] * self.scale, self.ant[1] * self.scale,
                              self.scale - self.border, self.scale - self.border])

        else:
            # updates value of cell to n+1 color
            # if end of color list, return to index 0
            update_idx = (int(self.curr_array[ant_xpos][ant_ypos]) + 1) % len(self.colors)
            self.curr_array[ant_xpos][ant_ypos] = update_idx

            # rotate direction based on rule of next color
            self.rotate(self.rules[update_idx])

            # Update color of cell ant is currently on
            # Move ant forward in current direction
            # Draw ant on that forward cell
            pygame.draw.rect(surface, self.colors[update_idx],
                             [ant_xcoord, ant_ycoord, self.scale - self.border, self.scale - self.border])
            self.move()
            pygame.draw.rect(surface, (255, 0, 0),
                             [self.ant[0] * self.scale, self.ant[1] * self.scale,
                              self.scale - self.border, self.scale - self.border])

        Updates cells colors on field between each transition
        
Updates cells colors on field between each transition
Updates cells colors on field between each transition
def transition(self, surface):
        ant_xpos, ant_ypos = self.ant[0], self.ant[1]
        ant_xcoord, ant_ycoord = ant_xpos * self.scale, ant_ypos * self.scale
        if self.curr_array[ant_xpos][ant_ypos] == -1:  
            self.curr_array[ant_xpos][ant_ypos] = 0  
            self.rotate(self.rules[0])  
            pygame.draw.rect(surface, self.colors[0],
                             [ant_xcoord, ant_ycoord, self.scale - self.border, self.scale - self.border])
            self.move()
            pygame.draw.rect(surface, (255, 0, 0),
                             [self.ant[0] * self.scale, self.ant[1] * self.scale,
                              self.scale - self.border, self.scale - self.border])
        else:
            update_idx = (int(self.curr_array[ant_xpos][ant_ypos]) + 1) % len(self.colors)
            self.curr_array[ant_xpos][ant_ypos] = update_idx
            self.rotate(self.rules[update_idx])
            pygame.draw.rect(surface, self.colors[update_idx],
                             [ant_xcoord, ant_ycoord, self.scale - self.border, self.scale - self.border])
            self.move()
            pygame.draw.rect(surface, (255, 0, 0),
                             [self.ant[0] * self.scale, self.ant[1] * self.scale,
                              self.scale - self.border, self.scale - self.border])
def transition ( self , surface ) : ant_xpos , ant_ypos = self . ant [ 0 ] , self . ant [ 1 ] ant_xcoord , ant_ycoord = ant_xpos * self . scale , ant_ypos * self . scale if self . curr_array [ ant_xpos ] [ ant_ypos ] == - 1 : self . curr_array [ ant_xpos ] [ ant_ypos ] = 0 self . rotate ( self . rules [ 0 ] ) pygame . draw . rect ( surface , self . colors [ 0 ] , [ ant_xcoord , ant_ycoord , self . scale - self . border , self . scale - self . border ] ) self . move ( ) pygame . draw . rect ( surface , ( 255 , 0 , 0 ) , [ self . ant [ 0 ] * self . scale , self . ant [ 1 ] * self . scale , self . scale - self . border , self . scale - self . border ] ) else : update_idx = ( int ( self . curr_array [ ant_xpos ] [ ant_ypos ] ) + 1 ) % len ( self . colors ) self . curr_array [ ant_xpos ] [ ant_ypos ] = update_idx self . rotate ( self . rules [ update_idx ] ) pygame . draw . rect ( surface , self . colors [ update_idx ] , [ ant_xcoord , ant_ycoord , self . scale - self . border , self . scale - self . border ] ) self . move ( ) pygame . draw . rect ( surface , ( 255 , 0 , 0 ) , [ self . ant [ 0 ] * self . scale , self . ant [ 1 ] * self . scale , self . scale - self . border , self . scale - self . border ] )
Updates cells colors on field between each transition
Updates cells colors on field between each transition
"""
        Updates cells colors on field between each transition
        """ # curr cell is white (default) # change cell to first color # rotate direction based on first rule # Update color of cell ant is currently on # Move ant forward in current direction # Draw ant on that forward cell # updates value of cell to n+1 color # if end of color list, return to index 0 # rotate direction based on rule of next color # Update color of cell ant is currently on # Move ant forward in current direction # Draw ant on that forward cell
self
surface