Updated 2010-06-14 21:59:38 by SES_home

ulis, 2004-03-13. A LCD hexa panel.


Digits stuff
  # --------
  # digits stuff
  # --------
  # font description
  array set hexdigits \
  {
    " " {0 0 0 0 0 0 0}
    "0" {1 1 1 0 1 1 1}
    "1" {0 0 1 0 0 1 0}
    "2" {1 0 1 1 1 0 1}
    "3" {1 0 1 1 0 1 1}
    "4" {0 1 1 1 0 1 0}
    "5" {1 1 0 1 0 1 1}
    "6" {1 1 0 1 1 1 1}
    "7" {1 0 1 0 0 1 0}
    "8" {1 1 1 1 1 1 1}
    "9" {1 1 1 1 0 1 1}
    "A" {1 1 1 1 1 1 0}
    "B" {0 1 0 1 1 1 1}
    "C" {1 1 0 0 1 0 1}
    "D" {0 0 1 1 1 1 1}
    "E" {1 1 0 1 1 0 1}
    "F" {1 1 0 1 1 0 0}
  }
  # add a digit to the panel
  proc add:digit {w x y tag} \
  {
    set dx $::(dx)
    set dy $::(dy)
    create:segment $w $tag:0 $x $y 0 0 $dx 0
    create:segment $w $tag:1 $x $y 0 0 0 $dy
    create:segment $w $tag:2 $x $y $dx 0 $dx $dy
    incr y $dy
    create:segment $w $tag:3 $x $y 0 0 $dx 0
    create:segment $w $tag:4 $x $y 0 0 0 $dy
    create:segment $w $tag:5 $x $y $dx 0 $dx $dy
    incr y $dy
    create:segment $w $tag:6 $x $y 0 0 $dx 0
  }
  # add a segment to a digit
  proc create:segment {w tag x y dx0 dy0 dx1 dy1} \
  {
    $w create line \
      [expr {$x + $dx0}] [expr {$y + $dy0}] \
      [expr {$x + $dx1}] [expr {$y + $dy1}] \
      -tags [list $tag $tag] \
      -fill $::(color) -width $::(width)
  }
  # set a digit
  proc set:digit {w tag digit} \
  {
    set n 0
    foreach segment $::hexdigits($digit) \
    {
      $w itemconfig $tag:$n -state [expr {$segment ? "normal" : "hidden"}]
      incr n
    }
  }

Demo
  # --------
  # demo
  # --------
  wm title . "LCD hexa panel"
  # parms
  array set {} \
  {
    dx    15
    dy    15
    color red
    width 3
  }
  # canvas
  pack [canvas .c]
  # digits
  set n 0
  set x 5
  foreach digit [lsort [array names hexdigits]] \
  {
    add:digit .c $x 5 d$n
    set:digit .c d$n $digit
    incr n
    incr x 20
  }
  foreach {- - width height} [.c bbox all] break
  .c config -width $width -height $height

See also


DKF: Here's another version, taken from a game at http://www.man.ac.uk/~zzcgudf/tcl/maze.tcl

 ### LCD NUMBER DISPLAY ENGINE ###

 # The shapes of individual elements of a digit
 array set lcdshape {
    a {3.0 5 5.2 3 7.0 5 6.0 15 3.8 17 2.0 15}
    b {6.3 2 8.5 0 18.5 0 20.3 2 18.1 4 8.1 4}
    c {19.0 5 21.2 3 23.0 5 22.0 15 19.8 17 18.0 15}
    d {17.4 21 19.6 19 21.4 21 20.4 31 18.2 33 16.4 31}
    e {3.1 34 5.3 32 15.3 32 17.1 34 14.9 36 4.9 36}
    f {1.4 21 3.6 19 5.4 21 4.4 31 2.2 33 0.4 31}
    g {4.7 18 6.9 16 16.9 16 18.7 18 16.5 20 6.5 20}
 }
 # Which elements are turned on for a given digit?
 array set llcd {
    0 {a b c d e f}
    1 {c d}
    2 {b c e f g}
    3 {b c d e g}
    4 {a c d g}
    5 {a b d e g}
    6 {a b d e f g}
    7 {b c d}
    8 {a b c d e f g}
    9 {a b c d e g}
    - {g}
    { } {}
 }
 # Which elements are turned off for a given digit?
 array set ulcd {
    0 {g}
    1 {a b e f g}
    2 {a d}
    3 {a f}
    4 {b e f}
    5 {c f}
    6 {c}
    7 {a e f g}
    8 {}
    9 {f}
    - {a b c d e f}
    { } {a b c d e f g}
 }

 # Displays a decimal number using LCD digits in the top-left of the canvas
 proc showLCD {c number {width 5} {colours {#ff8080 #ff0000 #404040 #303030}}} {
    global llcd ulcd lcdshape
    set lcdoffset 0
    $c delete lcd
    foreach {onRim onFill offRim offFill} $colours {break}
    foreach glyph [split [format %${width}d $number] {}] {
       foreach symbol $llcd($glyph) {
          $c move [$c create polygon $lcdshape($symbol) -tags lcd \
                 -outline $onRim -fill $onFill] $lcdoffset 0
       }
       foreach symbol $ulcd($glyph) {
          $c move [$c create polygon $lcdshape($symbol) -tags lcd \
                 -outline $offRim -fill $offFill] $lcdoffset 0
       }
       incr lcdoffset 22
    }
 }

 # Simple demo
 pack [canvas .c]
 showLCD .c 123

Larry Smith This is the version used in HP Calculator Simulations. It is based on the one right above from maze.tcl, but it can be resized and the shape of individual bars changed just by setting dx/dy and len. This version does decimal and hex digits, plus ".", ",", r, u, n, i, g, e, o, and space. The usage of "." and "," can be swapped by setting "eurostyle" to true.
 ### LCD NUMBER DISPLAY ENGINE ###
 package require Tk
 # hex segment

 set dx 2
 set dy 2
 set len 8
 set eurostyle 0

 set 2dx [expr $dx+$dx]
 set 2dy [expr $dy+$dy]

 set coord1 "0 0"
 set coord2 "$dx -$dy"
 set coord3 "[expr $dx+$len] -$dy"
 set coord4 "[expr $2dx+$len] 0"
 set coord5 "[expr $dx+$len] $dy"
 set coord6 "$dx $dy"
 set horseg "$coord1 $coord2 $coord3 $coord4 $coord5 $coord6"

 set coord1 "0 0"
 set coord2 "$dx -$dy"
 set coord3 "$2dx 0"
 set coord4 "$2dx $len"
 set coord5 "$dx [expr $len+$dy]"
 set coord6 "0 $len"
 set verseg "$coord1 $coord2 $coord3 $coord4 $coord5 $coord6"

 proc getseg { xoffset yoffset isHorizontal } {
   global horseg verseg dx dx 2dx 2dy len

   set xoffset [ expr $xoffset ]
   set yoffset [ expr $yoffset ]
   if $isHorizontal { set result $horseg } else { set result $verseg }
   for {set j 0 } { $j < 12 } { incr j } {
     set result [ lreplace $result $j $j [ expr [lindex $result $j] + $xoffset] ]
     incr j
     set result [ lreplace $result $j $j [ expr [lindex $result $j] + $yoffset] ]
   }
   return $result
 }

 # The shapes of individual elements of a digit
 set lcdshape(a) [ getseg 0 0 0 ]
 set lcdshape(b) [ getseg $dx -$dy 1 ]
 set lcdshape(c) [ getseg $2dx+$len 0 0 ]
 set lcdshape(d) [ getseg $2dx+$len $2dy+$len 0 ]
 set lcdshape(e) [ getseg $dx 3*$dy+2*$len 1 ]
 set lcdshape(f) [ getseg 0 $2dy+$len 0 ]
 set lcdshape(g) [ getseg $dx $dy+$len 1 ]
 set lcdshape(h) {18 22 18 28 23 28 23 22 }
 set lcdshape(i) {18 28 23 28 16 34}

 # Which elements are turned on for a given digit?
 array set llcd {
    0   {a b c d e f}
    1   {c d}
    2   {b c e f g}
    3   {b c d e g}
    4   {a c d g}
    5   {a b d e g}
    6   {a b d e f g}
    7   {b c d}
    8   {a b c d e f g}
    9   {a b c d e g}
    A   {a b c d f g}
    B   {a d e f g}
    C   {a b e f}
    D   {c d e f g}
    E   {a b e f g}
    F   {a b f g}
    -   {g}
    .   {h}
    ,   {h i}
    r   {a b}
    u   {a g c}
    n   {a b c}
    i   { c }
    g   {a b c d e g}
    e   {a b e f g}
    o   {a b c g}
    { } {}
 }

 # Displays a decimal str using LCD digits in the top-left of the canvas
 proc showLCD {str {colours {#929292 #000000 #929292 #A2A2A2}}} {
    global llcd lcdshape eurostyle display
    set lcdoffset 0
    $display delete lcd
    foreach {onRim onFill offRim offFill} $colours {break}
    set len [ string length $str ]
    for { set j 0 } { $j < $len } { incr j } {
       set glyph [ string index $str $j ]
       set next [ string index $str [ expr $j+1 ] ]
       foreach symbol {a b c d e f g} {
          if {[lsearch $llcd($glyph) $symbol] != -1} {
            $display move [$display create polygon $lcdshape($symbol) -tags lcd \
                 -outline $onRim -fill $onFill] $lcdoffset 8
          } else {
            $display move [$display create polygon $lcdshape($symbol) -tags lcd \
                 -outline $offRim -fill $offFill] $lcdoffset 8
          }
       }
       if { $next eq "." } {
          $display move [$display create polygon $lcdshape(h) -tags lcd \
               -outline $onRim -fill $onFill] $lcdoffset 0
          if $eurostyle {
            $display move [$display create polygon $lcdshape(i) -tags lcd \
               -outline $onRim -fill $onFill] $lcdoffset 0
          }
          incr j
       } elseif { $next eq "," } {
          $display move [$display create polygon $lcdshape(h) -tags lcd \
               -outline $onRim -fill $onFill] $lcdoffset 0
          if !$eurostyle {
            $display move [$display create polygon $lcdshape(i) -tags lcd \
               -outline $onRim -fill $onFill] $lcdoffset 0
          }
          incr j
       }
       incr lcdoffset 25
    }
    update
 }

 # Simple demo
 pack [set display [ canvas .c -bg #A2A2A2 -width 325 -height 48 ] ]
 showLCD "-1,234,567,890.00"
 after 5000
 showLCD "  running"
 after 5000
 showLCD "error"

TV I've done these in bwise here: simulating latch behaviour in Bwise , there's also a link to the real thing.

see also LCD-Editor.

SeS (14-6-2010) : and here you can see how the Layout Editor of tG² handles the LCD/display entries of DKF & Larry. Ofcourse, some necessary mod's had to be made in order to provide the user this interface-behavior. Release date of tG² is unknown, still developing the layout editor...