Richard Suchenwirth 2006-01-24 - In strimj - string image routines there was a converter from "string image" (intuitive ASCII graphics) to XBM. As I needed it, but didn't want to create a package requirement, here it is rewritten to be standalone, together with a warapper for image creation, and a little demo:
package req Tk proc strimj2xbm strimj { set width [string length [lindex $strimj 0]] set height [llength $strimj] set bytes {} foreach line [string map {. 0} $strimj] { regsub -all {[^0]} $line 1 line ;# black pixel foreach bin [split [binary format b* $line] ""] { lappend bytes [scan $bin %c] } } set res "#define i_width $width\n#define i_height $height\n" append res "static char i_bits\[\] = {\n[join $bytes ,]\n}" } proc strimj2image {strimj {fg black}} { image create bitmap -data [strimj2xbm $strimj] -foreground $fg }
#--------------------------- Usage demo, and test:
set test { @@...... @@@@.... @@@@@@.. @@@@@@@@ @@@@@@.. @@@@.... @@...... } set pause { @@@..@@@ @@@..@@@ @@@..@@@ @@@..@@@ @@@..@@@ @@@..@@@ @@@..@@@ } pack [button .1 -image [strimj2image $test red]] \ [button .2 -image [strimj2image $pause]] -padx 5 -pady 5 -side left
[Arts and crafts of Tcl-Tk programming