I'm creating a game that is supposed to run on the command line. The game uses text as a the canvas ( the software prints text in a shape of a rectangle, and when the text changes, the image changes). I've created a little scrip to test how this would work
import os
# function for printing out the game display grid
def printgrid(input):
for i in range(len(input)):
for j in range(len(input[0]):
print(input[i][j], end='')
print('') # newline after each row
grid = [['#' for x in range(10)] for x in range(10)]
while (True):
# refresh the screen and reprint
os.system('clear')
printgrid(grid)
Unfortunately the code seems to be printing the grid too slowly resulting in a noticable scrolling effect during the printing, which would make the game unplayable.
Is there a faster way to print text in python?
Could the cause of this scrolling effect just be the fact that I have not made any framerate cap on this code, and it just happens to show the current output when the computer monitor refreshes?
- If my approach is completely wrong, what would be the best way to do this?