Tworzenie krzyżyka z gwiazdek - jak wrócić kursor do góry?

0

Hej, chciałbym stworzyć taki krzyżyk z gwiazdek. Mam taki kod:

 
for i in range(5):
    for j in range(5):
        print " ",
    print

for i in range(5):
    for j in range(5):
        print "*",
    print

for i in range(5):
    for j in range(5):
        print " ",
    print

Wyświetla mi teraz kwadrat 5x5 pustych znaków, pod nim kwadrat 5x5 gwiazdek i pod tym jeszcze jeden kwadrat 5x5 pustych znaków. Jak teraz zrobić, by kursor wrócił mi na samą górę, na prawą stronę od tego pustego kwadrata tak, by tam zrobić kwadrat gwiazdek?

PS. Nie wiem czy dobrze to wyjaśniłem, jak coś to piszcie to postaram się wyjaśnić to jakoś inaczej.

0

Całość rysuj na jakiejś wewnętrznej mapie będącą buforem konsoli, wtedy nie będzie problemu z żadnym przesuwaniem kursora.
Rysuj jak na płótnie.

class Map2D:
    def __init__(self, width, height, val):
        self._internalMap = [[val]*height for width in range(height)]
    def fromArray2D(self, array2D):
    	self.internalMap = array2D
    def at(self, x, y):
        return self._internalMap[x][y]
    def putAt(self, x, y, val):
        self._internalMap[x][y] = val
        return self
    def putMap2DAt(self, x, y, another):
    	for ix in range(x, x+another.width()):
    		for iy in range(y, y+another.height()):
    			self.putAt(ix, iy, another.at(ix-x, iy-y))
    	return self
    def width(self):
        return len(self._internalMap[0])
    def height(self):
        return len(self._internalMap)

def printPureMap2D(map2d):
	for y in range(map2d.height()):
		row = []
		for x in range(map2d.width()):
			row.extend(map2d.at(x, y))
		print ''.join(row)

canvas = Map2D(20, 20, ' ')
stars = Map2D(5, 5, '*')

canvas.putMap2DAt(0, 0, stars).putAt(5+3, 0, 'x').putMap2DAt(10, 0, stars)
canvas.putMap2DAt(5, 5, stars)
canvas.putMap2DAt(0, 10, stars).putMap2DAt(10, 10, stars)

printPureMap2D(canvas)

http://ideone.com/uOLCii
Wynik:

*****   x *****     
*****     *****     
*****     *****     
*****     *****     
*****     *****     
     *****          
     *****          
     *****          
     *****          
     *****          
*****     *****     
*****     *****     
*****     *****     
*****     *****     
*****     *****     

1 użytkowników online, w tym zalogowanych: 0, gości: 1