Posted to tcl by evilotto at Wed Jul 19 21:45:48 GMT 2017view pretty
set plotsize 7 proc textplot {values} { set xvals [lmap {x y} $values {set x}] set yvals [lmap {x y} $values {set y}] set minx [tcl::mathfunc::min {*}$xvals] set miny [tcl::mathfunc::min 0 {*}$yvals] set maxx [tcl::mathfunc::max {*}$xvals] set maxy [tcl::mathfunc::max {*}$yvals] set maxx [expr {$maxx + 1}] set maxy [expr {$maxy + 1}] # 10x10 grid set grid [lrepeat $::plotsize [lrepeat $::plotsize { }]] foreach {x y} $values { set gx [expr {int((double($x) - $minx) / (double($maxx) - $minx) * $::plotsize)}] set gy [expr {int((double($y) - $miny) / (double($maxy) - $miny) * $::plotsize)}] # puts "$gx $gy " for {set _y 0} {$_y <= $gy} {incr _y} { lset grid $_y $gx "**" } } foreach row [lreverse $grid] { puts "|[join $row ""]" } puts "+[string repeat "--" $::plotsize]" }