Version 15 of Flowers

Updated 2003-09-18 16:58:01

ulis, 2003-09-17 (Thanks to *NOT* change my formatting style)

KPV: Heaven help you if you ever add comments to your code. ulis ok


http://perso.wanadoo.fr/maurice.ulis/tcl/flowers.gif


Please, download the images files in the current directory before executing the script.

  http://perso.wanadoo.fr/maurice.ulis/tcl/flower-1.gif
  http://perso.wanadoo.fr/maurice.ulis/tcl/flower-2.gif
  http://perso.wanadoo.fr/maurice.ulis/tcl/flower-3.gif

  # -------------
  # nmage/bimage packages
  # -------------


  proc nmage {w args} \
  {
    set image [lindex $args 0]
    set ww [image width $image]
    set hh [image height $image]
    set x [expr {$ww / 2}]
    set y [expr {$hh / 2}]
    canvas $w -width $ww -height $hh -highlightt 0
    set n 0
    foreach image $args \
    { $w create image $x $y -anchor center -image $image -tags _[incr n] }
  }
  proc bimage {num flower image1 image2 {color ""}} \
  {
    set ww [image width $flower]
    set hh [image height $flower]
    foreach {type factor} {mini 4 micro 8} \
    {
      set ww2 [expr {$ww / $factor}]
      set hh2 [expr {$hh / $factor}]
      image create photo ${type}$num -width $ww2 -height $hh2
      ${type}$num copy flower$num -subsample $factor
    }
    nmage .$num $image1 $image2
    set ::info(.$num) [list $flower $color]
  }

  # -------------
  # mechanism
  # -------------

  proc change {num} \
  {
    foreach {name color} $::info(.$num) break
    select .0 $num 3
    .name config -text $name
    foreach w {. .name .0 .1 .2 .3} { $w config -bg $color }
    foreach w {.1 .2 .3} { select $w [expr {$w == ".$num" ? 1 : 2}] }
  }
  proc select {w n {max 2}} \
  {
    for {set i 1} {$i <= $max} {incr i} \
    {
      if {$i == $n} { $w itemconf _$i -state normal } \
      else { $w itemconf _$i -state hidden }
    }
  }

  # -------------
  # create images
  # -------------

  foreach image {flower1 flower2 flower3} \
          file  {flower-1.gif flower-2.gif flower-3.gif} \
  { image create photo $image -file $file }

  # -------------
  # create widgets
  # -------------

  nmage .0 flower1 flower2 flower3
  label .name -font {Times -24}
  foreach {i color} {1 DeepPink3 2 orange 3 blue} \
  { 
    bimage $i flower$i mini$i micro$i $color
    bind .$i <1> [list change $i]
  }

  # -------------
  # place & display widgets
  # -------------

  grid .0    -row 0 -column 1 -columnspan 3 
  grid .name -row 1 -column 1 -columnspan 3
  foreach i {1 2 3} { grid .$i -row 2 -column $i }

  # -------------
  # do it!
  # -------------

  wm title . flowers
  change 1

Category Example | Category Graphics