[Tutor] ASCII art generator

Michael Janssen Janssen@rz.uni-frankfurt.de
Sun Feb 2 11:31:06 2003


Hello Michael,

okey, i've commented out the dialog import as you advised me personnally
and import Image as PIL.Image.

You better should have told me, that an 7MB file with 250000 font-tags is
not that nice in a browser ;-)

Now I'm working with a downscaled image of 50x60 Pixel. That's fine.
Before spend it a GUI, why not gather the color-info from a couple of
pixel in case width and or height is about 50!


A simple version of a "status-bar" can be added like this:

def ascgen():
   .....

    print width * height
    while x < width:
        if nn % 1000 == 0:
            print nn,"iterations"
        nn += 1
   ......

This fills up the console, but the script doesn't sits any longer there
silently. To enhance these messages:
sys.stdout.write("%6s iterations\n\033[A" % nn)

\033[A is the ansi-code to scrollback one line, i.e. to the start of the
last written status (and overwrite it). From here it's not hard to compute
procents.

minor hints:
your main function needn't a return statement. Leave it away
(ascgen need it - not to actually return something but to jump out of the
while loop;  on the other hand: a simple "break" would be enough)

"out" should be a string not a tuple. The html-file becomes cleaner.

I assume the file-handling is meant for expert use only and leave this
point for further versions ;-)

Michael

On Sun, 2 Feb 2003, Michael Miller wrote:

> I got this thing working in about 4 hours time the other night (an amazing
> feat for me) and have been messing with it sense. It's a very simple script
> that takes the value of a pixel, changes it to the hex value, then formats in
> in HTML and writes the info to a file. I'm happy with the way it works like
> it is, but I'd like for it to be usable for other people too. I plan to add a
> gui to it sometime soo, but need to learn to make a gui first (Walking?
> Forget that, I'm all about running. Usually into trees).
>
> The two more pressing issues are making sure that the user is using an image
> file as the input and not, for instance, their grocery list (I haven't
> checked to see what happens if they do). Second, I need a status indicator.
> Right now all it does is sit until it's done and as slow as this thing is,
> that's a problem. I was thinking of a percentage indicator based on the total
> amount of pixels in the image, but I have no clue how to implement that right
> now (I'll give it a shot later).
>
> I realise that this is a rather brute force method of doing this, but I just
> don't have the skill to make anything more elegant. Any idea on how to do so,
> or any help with the problems I mentioned above would be most appreciated.
> Also, sorry that I had to attach the file. My crappy free webhost (my good
> free webhost is down ATM) won't allow Python files. Thanks for any help.
>
> Michael Miller
>