• + 0 comments

    I wrote a little python script that will draw out the terrian, just because I thought it would be fun.

    image

    class AsciiArt:
        art = list(list())
        width = int()
        height = int()
    
        def __init__(self, width):
            self.width = width
            self.height = 1
            self.art = [[' ' for _ in range(width)]]
    
        def placeArt(self, symbol, x, y):
            if (y >= self.height):
                numberOfLinesToAdd = abs(y - self.height) + 1
                for _ in range(numberOfLinesToAdd):
                    self.art += [[' ' for _ in range(self.width)]]
    
                self.height += numberOfLinesToAdd
    
            self.art[y][x] = symbol
    
        def printArt(self):
            for line in self.art:
                print(str.join("", line))
    
    
    def getAsciiForStep(step):
        return '/' if step is 1 else '\\'
    
    
    def getMaxHeight(string_steps):
    
        mapStepsToInt = lambda x: 1 if x is 'U' else -1
        steps = list(map(mapStepsToInt, list(string_steps)))
    
        currentLevel = 0  # zero is sea level
        maxHeight = 0
        for step in steps:
            currentLevel += step
            if(currentLevel > maxHeight):
                maxHeight = currentLevel
    
        return maxHeight
    
    def getAsciiArtForSteps(string_steps):
        print(string_steps)
    
        # Create our display *steps* wide
        numberOfSteps = len(string_steps)
    
        OFFSET = getMaxHeight(string_steps)
    
        display = AsciiArt(numberOfSteps + 2)
        display.placeArt('_', 0, OFFSET)
    
        # Map our step values to integers
        mapStepsToInt = lambda x: 1 if x is 'U' else -1
        steps = list(map(mapStepsToInt, list(string_steps)))
    
    
        currentLevel = 0  # zero is sea level
        for step_i in range(numberOfSteps):
            step = steps[step_i]
    
            symbol = getAsciiForStep(step)
    
            y = ((OFFSET - currentLevel) - (1 if step is 1 else 0)) + 1
            currentLevel += step
    
            display.placeArt(symbol, step_i + 1, y)
    
        display.placeArt('_', numberOfSteps + 1, OFFSET)
    
        return display
    
    
    def main():
        display = getAsciiArtForSteps("UDUDDUUUDUDUDUUDUUDDDDDUDUDDDDUUDDUDDUUUUDUUDUDDDDUDUDUUUDDDUUUDUDDUUDDDUUDDUDDDUDUUDUUDUUDUDDDUUUUU")
        display.printArt()
    
    
    if __name__ == "__main__":
        main()