1

I have a 512x512 map in a text file (which contains only '@', 'T', 'W' and '.' characters) and I want to display it with Python, in the shell or another window. The map is a WC3 map I downloaded from here.

I'm testing and implementing search algorithms (A* right now), and testing on some big maps. The thing is, I want to be able to see the map after every try of my implementation, to check whether the program is working properly or not.

Printing it as I would do it normally with any .txt file doesn't work for me because I don't get to see the entire map in the shell.

I need some way to print it zoomed out (a lot). I tried with Zelle's graphics.py but couldn't do it.

And well, a less optimal solution could be achieved without Python. Maybe there's a program or a way to open a .txt file and zoom out a lot (Notepad can't), but in this way I would need to close the file, run my program, open the file, etc, again and again.

[TEMPORARY SOLUTION]
As Rad Lexus suggested, I created a map.html document and it's working relatively fine better than any text editor I've tried for my purposes. Still can't see the whole map at minimum zoom with Chrome. I'll be doing this in the meantime, but would be nice to print the file in a smaller window anyway.

[PREFERRED SOLUTION]
I'll use PIL, even though it will not print the original map, but an semi-equivalent colored one, changing each of my four characters into a RGB triplet.

  • And `print` didn't work for you because...? – Kevin J. Chase May 01 '16 at 04:44
  • 1
    file is 512 characters wide and tall.. My need is to see it altogether, and printing it doesn't allow that. Maybe a zoom out function might work @kevin – Matias Correa May 01 '16 at 05:02
  • You haven't told us what you've already tried, and what went wrong (or why it wasn't good enough). That's why you're getting such basic questions and answers. Please read "[ask]", and [edit] your question to give us enough information to answer your question. For instance, _why_ do you want to display the map with Python? Is it to debug map files for someone else's game? Is it to play the game? Are you already using a window package like [`tkinter`](https://docs.python.org/3/library/tkinter.html)? In short, what are your _requirements_? – Kevin J. Chase May 01 '16 at 05:11
  • 1
    possible duplicate of http://stackoverflow.com/questions/434583/what-is-the-fastest-way-to-draw-an-image-from-discrete-pixel-values-in-python – Aaron Brick May 01 '16 at 06:16
  • Write out an HTML file. You can easily refresh the page in your browser after each rewrite, and zoom in and out using the regular browser keys for 'larger' and 'smaller' view (depends on the browser). Also, when zoomed in, you automatically get scrollbars. – Jongware May 01 '16 at 10:42

2 Answers2

0

use the Python Imaging Library:

https://en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels

Aaron Brick
  • 236
  • 2
  • 11
-1

Try the open command along with readline

file = open('filename', 'r')
lines = file.readlines()
for line in lines:
    print(line)
Max Dignan
  • 99
  • 1
  • 3
  • thx but I cant see the map as a whole like that. Maybe i have to mention im not a beginner so i know the common ways to print a file. – Matias Correa May 01 '16 at 05:04