|
Post by Rod on Apr 15, 2024 13:48:03 GMT
This is a first attempt at producing Ascii Art from a bmp image. Currently you will need to feed it a 120x170 grey scale image but at 24bit color. My first crude attempt at creating a pallet isn't working that well. test4.bmp (59.81 KB) nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.g, 0,0,4000,4000 open "ASCII Graphics Printing" for window as #1 #1 "trapclose [quit]" #1.g "down ; color black ; backcolor white" #1.g "font Courier_New 10"
'create a table of characters in order of how many dots are used to display the character dim asctable(128,2) for asc=32 to 127 #1.g "place 0 12 ;\";chr$(asc) #1.g "getbmp bmp 0 0 10 16 ; place 50 50 ; drawbmp bmp" bmpsave "bmp","image.bmp" open "image.bmp" for input as #f bmp$ = input$(#f, lof(#f)) close #f kill "image.bmp" c=0 for y=0 to 15 for x=0 to 9 c$=getpixel$(bmp$,x,y) if c$<>chr$(255)+chr$(255)+chr$(255)then c=c+1 next next asctable(asc,1)=asc asctable(asc,2)=c next sort asctable(),32,127,2
'for asc=32 to 127 'print asc,asctable(asc,1);" ";asctable(asc,2);" ";chr$(asctable(asc,1)) 'next
open "test4.bmp" for input as #f bmp$ = input$(#f, lof(#f)) close #f #1.g "cls" for y=0 to 170 step 2 for x=0 to 127 c$=getpixel$(bmp$,x,y) clr=asc(mid$(c$,1,1)) a=int(127-clr/2.7) if a=58 then a=59 '\ character eliminated if a=124 then a=123 '[] character eliminated l$=l$+chr$(asctable(a,1)) '#1.g "color ";clr;" ";clr;" ";clr '#1.g "set ";x;" ";y
next #1.g "\";l$ l$="" next
#1.g "flush" '#1.g "print 1100"
wait
[quit] close #1 end
'Richard Russell's getpixel color function function getpixel$(bmp$, x, y) b = asc(mid$(bmp$,29,1)) / 8 o = asc(mid$(bmp$,11,1)) + 256*asc(mid$(bmp$,12,1)) + 1 w = asc(mid$(bmp$,19,1)) + 256*asc(mid$(bmp$,20,1)) h = asc(mid$(bmp$,23,1)) + 256*asc(mid$(bmp$,24,1)) w = ((w * b) + 3) and -4 y = h - y - 1 getpixel$ = mid$(bmp$,o+b*int(x)+w*int(y),3) end function
|
|
|
Post by tenochtitlanuk on Apr 15, 2024 19:22:21 GMT
I'll be interested in how this works out. Takes me back to teleprinter days.
I played briefly at LB code for this some years back, like you, measuring dot-density per character. If I remember, I got best results by boxing values into groups, and using a non-linear conversion of dot-density to ASCII char chosen. Can't find any code in my files...
For interest, I always used to use the 'standard' image of 'Lena' for such exercises. Apparently she has now asked for her image to be retired from use because it isn't representative of who she now is. Much like how I feel about early photos of myself!
EDIT
It may be worth limiting the grey scale to say 16 levels, and using a limited range of ASCII chars to represent them. Below is from an online converter
#####################################%%%%%#####################################% ###########%%%%%%%%%%%%#%##%%##%%%%#%%%%%%%%%%#%%%##%#%%%%%%%%%%%%%%#%%%#####%%% ########%%%%%%%%%%%%%%%%%%%%%%%%%%%%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%####%%%% #######%%%%%%%%%%%%%%%%%%%%%%%%%%######%%%%%#%%%%%%%%%%%%%%%%%%%%%%%%##########% ##########%#%#############%######%&&&&@@@@@@@@@&%#%%%%%%%%%%%%%##%%#%##########% ###############################%&&%#/(#%&&@@@@@@@@&%###########################% #(############################,......,,*#&@@@@@@@@%#########################(% ##((##############((#((######&&*........,*/#%&@@@@@@@########((((((((((((((((% %###############(((((((((((%&@%*........,,,*/#&@@@@@@@%%%%%%%#(((((((((((((((((% %#%#####((####(##(((((((#&&/(/*..,######%%&@&@@@@@&%%%%%%##((((((((((((((##% &&%#%%##%%%%%%%%&%%%(((##(#&&@(/*//,,((**(#(*(&@@@@@@@@%&%%%%%%#((((((((((#####% &%##%%%%%%%%&&&&&&&&%%&%&&&,....,*,...,,*#&@@@@@@@@%&%%%%%%%#((((((((((####% &&%%&&&%&&&&&&&&&&&&&&@&&&&&&@&*,,,.,**.,,,/#%@@@@@@@@@&&&%%%%%%%%%%%%&&%#%&&&&& &&%&&&&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@&&&*/&&%#%@@@@@@&@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&& &&&&&&@@@@&@@@@@@@@&(*/%&@@@@@@@@@@@@@@&%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&@&&& &&&&&&&&&@@@@@@@@@@@@&%&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&& %%%&&&&&&&&&@&&@@&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&@&&& %%%%%%&&&&&&&&&&&@@&&&&@&&@@@&&&&&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&&&& #%%%&&&%%%%%%&&&&&&&&&&&&&&&&&%&&&&&&&&&&&&&&&&&&&&&&@&&&&&&&@@@&@@&&@@@@@&&&&&&
|
|
|
Post by tenochtitlanuk on Apr 15, 2024 20:23:42 GMT
If instead of printing a line at a time you position each character by x,y you can effectively kern the characters closer vertically and horizontally. Less inter-character space makes for a more solid picture. As does using a bold font..
|
|
|
Post by tsh73 on Apr 15, 2024 20:57:35 GMT
Rod, your code as is does not work for me Some lines are broken Probably "\" elimination did not work as supposed to (is it only thing to be eliminated, right?) we should fix for
asctable(a,1) = 92 ("/") but code uses some other numbers Likely these are results of sorting, which could differ depending on font/size/font smoothing used.
Also, I see that on my Windows Courier New chr$(127) violates character width (I see empty rectangle, it is smaller then other characters) I think it is "missing glyph" rectangle.
So, version without 127 and with another fix for "\" (I had to make character size smaller to see picture in full)
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.g, 0,0,4000,4000 open "ASCII Graphics Printing" for window as #1 #1 "trapclose [quit]" #1.g "down ; color black ; backcolor white" #1.g "font Courier_New 10" #1.g "font Courier_New 6" 'fits 1024 screen height
'create a table of characters in order of how many dots are used to display the character dim asctable(128,2) for asc=32 to 126 '127 is missing glyph, smaller size - had to exclude it #1.g "place 0 12 ;\";chr$(asc) #1.g "getbmp bmp 0 0 10 16 ; place 50 50 ; drawbmp bmp" bmpsave "bmp","image.bmp" open "image.bmp" for input as #f bmp$ = input$(#f, lof(#f)) close #f ''kill "image.bmp" 'somehow does not work for me c=0 for y=0 to 15 for x=0 to 9 c$=getpixel$(bmp$,x,y) if c$<>chr$(255)+chr$(255)+chr$(255)then c=c+1 next next asctable(asc,1)=asc asctable(asc,2)=c next sort asctable(),32,126,2
'for asc=32 to 127 'print asc,asctable(asc,1);" ";asctable(asc,2);" ";chr$(asctable(asc,1)) 'next
open "test4.bmp" for input as #f bmp$ = input$(#f, lof(#f)) close #f #1.g "cls" for y=0 to 170 step 2 for x=0 to 127 c$=getpixel$(bmp$,x,y) clr=asc(mid$(c$,1,1)) a=int(126-clr/2.7)
aa=asctable(a,1) if aa=asc("\") then aa=asc("/")
'if a=58 then a=59 '\ character eliminated 'if a=92 then a=93 '\ character eliminated
'l$=l$+chr$(asctable(a,1))
l$=l$+chr$(aa) '#1.g "color ";clr;" ";clr;" ";clr '#1.g "set ";x;" ";y
next #1.g "\";l$ l$="" next
#1.g "flush" '#1.g "print 1100"
wait
[quit] close #1 end
'Richard Russell's getpixel color function function getpixel$(bmp$, x, y) b = asc(mid$(bmp$,29,1)) / 8 o = asc(mid$(bmp$,11,1)) + 256*asc(mid$(bmp$,12,1)) + 1 w = asc(mid$(bmp$,19,1)) + 256*asc(mid$(bmp$,20,1)) h = asc(mid$(bmp$,23,1)) + 256*asc(mid$(bmp$,24,1)) w = ((w * b) + 3) and -4 y = h - y - 1 getpixel$ = mid$(bmp$,o+b*int(x)+w*int(y),3) end function
|
|
|
Post by tsh73 on Apr 15, 2024 21:01:56 GMT
It actually looks OK even as Courier New 6 Please post Courier New 10 to compare - I have no easy way of saving it since it does not fit screen
|
|
|
Post by Rod on Apr 16, 2024 10:23:34 GMT
Yep, I was replacing the sorted table character, much better to replace as you do. Also character 127 needs eliminated as you show. They were the only two characters causing problems.
As I had it set, at font Courier New 10, it was printing a full A4 sheet of ascii art. The problem is that while your condensed ascii art image has some contrast the larger A4 image is bland and lacks contrast.
Also to get printed perspective right I had to skip Y lines.
Ultimate aim is some wall sized art!
|
|
|
Post by Rod on Apr 16, 2024 13:11:32 GMT
Little squares are more effective but it isnt Ascii Art.
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.g, 0,0,4000,4000 open "ASCII Graphics Printing" for window as #1 #1 "trapclose [quit]" #1.g "down ; fill black ; color white ; backcolor white" #1.g "font Courier_New 10 Bold"
open "test4.bmp" for input as #f bmp$ = input$(#f, lof(#f)) close #f
for y=0 to 170 for x=0 to 127 c$=getpixel$(bmp$,x,y) clr=asc(mid$(c$,1,1)) a=int(sqr(clr/2))
#1.g "place ";x*8;" ";y*8 #1.g "boxfilled ";x*8+a;" ";y*8+a
next
next
#1.g "flush" #1.g "print 1100"
wait
[quit] close #1 end
'Richard Russell's getpixel color function function getpixel$(bmp$, x, y) b = asc(mid$(bmp$,29,1)) / 8 o = asc(mid$(bmp$,11,1)) + 256*asc(mid$(bmp$,12,1)) + 1 w = asc(mid$(bmp$,19,1)) + 256*asc(mid$(bmp$,20,1)) h = asc(mid$(bmp$,23,1)) + 256*asc(mid$(bmp$,24,1)) w = ((w * b) + 3) and -4 y = h - y - 1 getpixel$ = mid$(bmp$,o+b*int(x)+w*int(y),3) end function
|
|
|
Post by tenochtitlanuk on Apr 22, 2024 18:36:22 GMT
Not directly relevant, but a modified version using your La Giaconda image. Some may remember my 'rasterbator' images from a decade ago, and also the raster-width versions. Web pages still up- will update them. nomainwin
WindowWidth = 800 WindowHeight = 1100
graphicbox #1.g, 0, 0, 4000, 4000
open "ASCII Graphics Printing" for window as #1
#1 "trapclose [quit]" #1.g "down ; fill white ; color black ; backcolor black" #1.g "font Courier_New 10 Bold"
open "test4.bmp" for input as #f bmp$ = input$( #f, lof( #f)) close #f
for y =0 to 170 if y mod 2 =0 then delta =4 else delta =0 for x =0 to 120 c$ =getpixel$( bmp$, x, y) clr =asc( mid$( c$, 1, 1)) a =int( sqr( clr /5))
#1.g "place "; 10 +x *6 +delta; " "; 12 +y *6 #1.g "circlefilled "; 5 -a scan next next
#1.g "flush" '#1.g "print 1100" wait
[quit] close #1 end
'Richard Russell's getpixel color function function getpixel$(bmp$, x, y) b = asc( mid$( bmp$, 29, 1)) / 8 o = asc( mid$( bmp$, 11, 1)) + 256 *asc( mid$( bmp$, 12, 1)) + 1 w = asc( mid$( bmp$, 19, 1)) + 256 *asc( mid$( bmp$, 20, 1)) h = asc( mid$( bmp$, 23, 1)) + 256 *asc( mid$( bmp$, 24, 1)) w = ( (w * b) + 3) and -4 y = h - y - 1 getpixel$ = mid$( bmp$, o +b *int( x) +w *int( y), 3) end function
EDITIt is of course easy to step across/down an image and print each section to a full sheet of paper. And it helps to be able to load/size the chosen image within LB.
|
|