Version 3 of Xmas tree

Updated 2005-12-23 20:20:00

Richard Suchenwirth 2005-12-22 - Ho ho ho, here we go:

http://mini.net/files/xmas.jpg


  package require Tk

  proc every {ms body} {eval $body; after $ms [info level 0]}
  proc lpick list {lindex $list [expr {int(rand()*[llength $list])}]}

  proc Candle {id} {
    set Color [lpick {yellow linen white orange gold "light yellow" goldenrod}]
    .c itemconfig $id -fill $Color
    if {$Color != "yellow" } {after 5 Candle $id}
  }
  proc Flicker {} { Candle [lpick $::Selection] }

  pack [canvas .c -width 200 -height 300 -background darkblue]
  .c create rect 95 250 105 280 -fill brown
  .c create rect 70 270 130 290 -fill black

  foreach dx {40 55 70 85 100} y {20 60 100 140 180} {
    .c create poly 100 $y [expr 100-$dx] [expr $y+70] \
                          [expr 100+$dx] [expr $y+70] -fill darkgreen -tag Tree

    .c create rect [expr 108-$dx] [expr $y+45] \
                   [expr 112-$dx] [expr $y+65] -fill red    -tag Candle
    .c create oval [expr 107-$dx] [expr $y+36] \
                   [expr 113-$dx] [expr $y+44] -fill yellow -tag Flame

    .c create rect [expr  88+$dx] [expr $y+45] \
                   [expr  92+$dx] [expr $y+65] -fill red    -tag Candle
    .c create oval [expr  87+$dx] [expr $y+36] \
                   [expr  93+$dx] [expr $y+44] -fill yellow -tag Flame
  }

  wm title . "Xmas" 
  set Selection [.c find withtag Flame]
  every 200 { Flicker }

HJG Animated candles ! See also Design your own Christmas Tree


Category Example | Category Graphics | Category Toys | Arts and crafts of Tcl-Tk programming