• What's your solution?
    33 replies, posted
I need to generate ASCII text in python. I have 26 variables, a to z, containing a multiline letter. I was able to combine these letters like so: [code] letter1 = y.splitlines() #or any other letter letter2 = z.splitlines() spacel = space.splitlines() # space charecter for i in range(1, len(letter1)): try: print "%s %s %s" % (letter1[i], spacel[i], letter2[i]) # print i line of all except: 1+1 # do nothing on error: some letters are longer than others, so just ignore it. [/code]What I need to do is convert a word into ascii text. I'm braindead right now, so I can't think of anything. What's your solution? I was also able to get the var from word, like this: [code] char = eval("%s" % word[i]) [/code]
Generate ASCII text? Can't you just, like, type it in a string? Anything that's plain-text and has only 7-bit character values is correct ASCII. What's your problem?
[QUOTE=esalaka;26489063]Generate ASCII text? Can't you just, like, type it in a string? Anything that's plain-text and has only 7-bit character values is correct ASCII. What's your problem?[/QUOTE] oh, sorry. I mean, ASCII art text, like this: [IMG]http://f.braxupload.se/9qagf0.jpg[/IMG]
So you need to take a line at a time from each of a sequence of variables and put them together. let me think... (somebody will have an answer posted before I finish thinking)
You could make a list of lines which contain lists of spaces and # corresponding to the letter, then extract them one at a time and print them. Since they are all the same length, it will work just fine with no distortion [editline]5th December 2010[/editline] Just hang there, I'm writing an example app.
Isn't your only problem that your have a load of string variables instead of an indexable list of strings? Wouldn't just putting 'em into a dictionary work? edit: Just wait for terabyte's example, I bet it will be more understandable than mine.
[QUOTE=TerabyteS;26502718]You could make a list of lines which contain lists of spaces and # corresponding to the letter, then extract them one at a time and print them. Since they are all the same length, it will work just fine with no distortion [editline]5th December 2010[/editline] Just hang there, I'm writing an example app.[/QUOTE] You could just use a list of strings, 1 string for each line of characters. Since you're printing whole lines at the same time, there's no need to separate the characters inside a line.
Here's my solution. Written pretty badly but it works. [code]line1 = [" ### ", "####### "] #To fill this up, just add the letters' lines separated by a comma line2 = [" ## ## ", "## ##"] line3 = [" ## ## ", "## ##"] line4 = ["## ##", "######## "] line5 = ["#########", "## ##"] line6 = ["## ##", "## ##"] line7 = ["## ##", "######## "] stringToPrint = "ABBA" letterPositions = { "A":0, "B":1, #Remember to fill this up } for letter in stringToPrint: #Let's print all 1st lines of the letters in the string print line1[letterPositions[letter]], print #I put a carriage return to start line 2 for letter in stringToPrint: #This prints all 2nd lines of the letters print line2[letterPositions[letter]], print #And so on for letter in stringToPrint: print line3[letterPositions[letter]], print for letter in stringToPrint: print line4[letterPositions[letter]], print for letter in stringToPrint: print line5[letterPositions[letter]], print for letter in stringToPrint: print line6[letterPositions[letter]], print for letter in stringToPrint: print line7[letterPositions[letter]], [/code] [editline]5th December 2010[/editline] [QUOTE=pebkac;26502889]You could just use a list of strings, 1 string for each line of characters. Since you're printing whole lines at the same time, there's no need to separate the characters inside a line.[/QUOTE] That's exactly what I did
I'd use a separate array for each letter, containing all the letter's lines, rather than a separate array for each line spanning all the letters. It makes the drawing code a little more complex, but I think it makes more sense for line 1 of A to be more closely associated with line 2 of A than with line 1 of B.
My problem isn't printing them, i have that set. The problem is converting a word into them.
What do you mean by "converting a word into them"? The only significant step other than the actual printing is looking up the picture data that corresponds to each letter. TerabyteS's code uses an associative array (letterPositions) for that.
[QUOTE=supersnail11;26513271]My problem isn't printing them, i have that set. The problem is converting a word into them.[/QUOTE] Did you read the code I posted? It does that.
[QUOTE=Wyzard;26513695]What do you mean by "converting a word into them"? The only significant step other than the actual printing is looking up the picture data that corresponds to each letter. TerabyteS's code uses an associative array (letterPositions) for that.[/QUOTE] I can print as many letters as I want by doing it manually. The code in the first post shows how. What I need is a way to do it automattically.
Use GNU Unifont.
[QUOTE=supersnail11;26518123]What I need is a way to do it automattically.[/QUOTE] To do [i]what[/i] automatically? TerabyteS gave you code that can make an "ASCII art" picture of any arbitrary string, as long as you've defined a "picture" for each letter. What missing capability are you still looking for? Do you need it to produce the individual letter "pictures" on its own so that you don't have to provide them in the code?
[QUOTE=Wyzard;26519756]To do [i]what[/i] automatically? TerabyteS gave you code that can make an "ASCII art" picture of any arbitrary string, as long as you've defined a "picture" for each letter. What missing capability are you still looking for? Do you need it to produce the individual letter "pictures" on its own so that you don't have to provide them in the code?[/QUOTE] I have each letter, each in a multiline string (""") and I need to print them together.
[QUOTE=supersnail11;26519920]I have each letter, each in a multiline string (""") and I need to print them together.[/QUOTE] [QUOTE=Wyzard;26519756]TerabyteS gave you code that can make an "ASCII art" picture of any arbitrary string, as long as you've defined a "picture" for each letter.[/QUOTE] TerabyteS' code does what you want, just split the lines of your characters.
[QUOTE=supersnail11;26519920]I have each letter, each in a multiline string (""") and I need to print them together.[/QUOTE] Did you try the code I posted? It's just a matter of expanding the list to add all letters, numbers and symbols you need.
[QUOTE=TerabyteS;26532265]Did you try the code I posted? It's just a matter of expanding the list to add all letters, numbers and symbols you need.[/QUOTE] It was more of that I'm lazy and wanted to use the letters I had already done... Anyways, I converted it and it works
dude python sucks
[QUOTE=Tweep;26642269]dude python sucks[/QUOTE] dude you suck
I suck
[QUOTE=Collin665;26668366]I suck[/QUOTE] Everyone sucks But Tweep most of all
[QUOTE=Tweep;26642269]dude python sucks[/QUOTE] [B][I][U][url=http://www.facepunch.com/threads/1027400-Little-physics-sandbox]Yes?[/url][/U][/I][/B]
From what I hear, PHP sucks and still there are lots of web-servers using PHP. That doesn't make it a good language really. Though I do agree that it is a dumb statement.
[QUOTE=ZeekyHBomb;26690098]From what I hear, PHP sucks and still there are lots of web-servers using PHP. That doesn't make it a good language really. Though I do agree that it is a dumb statement.[/QUOTE] PHP has obviously done something right to get such a large userbase. I find the code ugly to look at though, I'd much rather write web systems in python using a framework such as django.
[QUOTE=eXeC64;26690429]PHP has obviously done something right to get such a large userbase.[/QUOTE] The thing they've done 'right' to get a large userbase is make the barrier to entry so incredibly low anyone can start writing crap code in PHP.
[QUOTE=eXeC64;26690429]PHP has obviously done something right to get such a large userbase.[/QUOTE] So has VB, by that reasoning.
[QUOTE=eXeC64;26690429]PHP has obviously done something right to get such a large userbase.[/QUOTE] [url=http://www.kotsc.net/fucklogic.php]You can't apply logic to PHP.[/url] :suicide:
[QUOTE=supersnail11;26487889] [code] 1+1 # do nothing on error: some letters are longer than others, so just ignore it. [/code][/QUOTE] [url=http://docs.python.org/tutorial/controlflow.html#pass-statements]The term you're looking for is pass.[/url]
Sorry, you need to Log In to post a reply to this thread.