Animation in Tcl/Tk/ET 8.0 ? 
Author Message
 Animation in Tcl/Tk/ET 8.0 ?

Levien,

A much better approach is to make all the images, and use a single
label to display then, and just change the -image option for the
label.  So make a whole bunch of tk images, and store their names in a
list, say imageList.  Then do

pack [label .l1 -image [lindex $imageList 0]]

proc showImage {pos} {
    global imageList

    if {$pos >= [llength $imageList]} {
        set pos 0
    }
    #
    # This is the important bit
    #
    .l1 configure -image [lindex $imageList $pos]

    incr pos
    after 100 "showImage $pos"

Quote:
}

showImage 0

This or something very like it should work.  

Note one other trick, due to George Howlett: because of the way that tk
handles images, you can get a substantial speedup in image display if
you put each of the images in your animation on a Tk widget, even
though that widget is not mapped.  So do:

set unique 1
foreach image $imageList {
    label .placeHolder[incr unique] -image $image

Quote:
}

after you have loaded all your images, and you will notice that the
swapping of images will go much faster.  Note, you never pack these
labels, they are just to keep Tk from garbage collecting some of the
computations that it has made for them images (colormaps if I
remember rightly...).  

Jim.

+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===

SunScript

+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===



Mon, 20 Mar 2000 03:00:00 GMT  
 Animation in Tcl/Tk/ET 8.0 ?

Hello all,

I'm trying to create an animation out of a series of black/white Photo images.
My current approach is putting them all over one another on the same location
and then raising them sequentially. The problem I have with this is that
each time the next image is being displayed, the screen is blackened by
Tcl/Tk, causing the animation to flicker heavily. Does anyone have any ideas
on how to solve this, have pointers for a better approach to animation, or
general comments ?

Levien
--
"Do you hear the people sing, Lost in the valley of the night?
 It is the music of a people, Who are climbing to the light.
 For the wretched of the earth, There is a flame that never dies.
 Even the darkest night will end, And the sun will rise." -- Les Miserables



Mon, 20 Mar 2000 03:00:00 GMT  
 Animation in Tcl/Tk/ET 8.0 ?


: I'm trying to create an animation out of a series of black/white Photo images.
: My current approach is putting them all over one another on the same location
: and then raising them sequentially. The problem I have with this is that
: each time the next image is being displayed, the screen is blackened by
: Tcl/Tk, causing the animation to flicker heavily. Does anyone have any ideas
: on how to solve this, have pointers for a better approach to animation, or
: general comments ?

I'm going the same thing with GIF images, and it seems to work smoothly under all platforms (Win, Mac, and Unix). Here is a code snippet:

---8<---------8<---------8<---------8<---------8<---------8<---------8<---
# -------------------------------------------------------------------------
# Function    : AnimateFrames { }
#
# Description : This procedure cycles through the frames for the
#               the current animation.
#
# Parameters  : void.
#
# Returns     : void.

proc AnimateFrames { }  {
  global Animations
  global CurAni
  global FrameSpeed

  if { $CurAni == -1 }  {
    return
  }
  # Start with a clean slate.
  set bitmapFile "bitmaps/blank.gif"
  .Bitmap configure -file $bitmapFile
  update
  # Sleep for a while. (WinTcl is broken, so use a special wait function).
  WasteTime $FrameSpeed

  # "bm" is the frame number, and "BuildBitmapName" creates a pathname
  # to the correct frame.
  for { set bm 0 } { $bm < $Animations($CurAni,animate) } { incr bm }  {
    set bitmapFile [ BuildBitmapName $bm ]
    .Bitmap configure -file $bitmapFile
    update
    # Sleep for a while. (WinTcl is broken, so use a special wait function).
    WasteTime $FrameSpeed
  }

  # Put the old start image back up.
  set bitmapFile [ BuildBitmapName ]
  .Bitmap configure -file $bitmapFile
  update

Quote:
};

# -------------------------------------------------------------------------

---8<---------8<---------8<---------8<---------8<---------8<---------8<---

.Bitmap was created with:

  image create photo .Bitmap -file $bitmapFile
  label .chart.bitmap -image .Bitmap -relief raised -bd 5

Hope this helps!
---
         _/     _/     _/     _/   *  Robert W. Lindeman, Research Fellow
_/_/  _/  _/ _/  _/ _/  _/ _/  _/  *  SEAS - GWU

        _/            _/           *  http://www.seas.gwu.edu/student/gogo/
   _/_/_/        _/_/_/            *  http://www.lindeman.com/



Tue, 21 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ET for tcl/tk 8.0

2. et w/ tcl/tk 8.0

3. Weird Error. Tcl/Tk/ET 8.0

4. Mixing Xevents and Tcl/Tk events with tcl/tk version 8.0/8.2

5. tcl/tk 8.0 problem with Windows app that calls tcl/tk script

6. Problems with HP-UX 8.0 and Tcl/TK 8.0

7. ANNOUNCE: Tcl 8.0 and Tk 8.0 releases

8. Bug Found in Tcl 8.0/Tk 8.0

9. ANNOUNCE: DiET (Dp in ET) Embedded Tcl with Tcl-Dp now supports ET 1.1c

10. Is Tcl-DP for tcl/tk 8.0 available?

11. Hypothe'tcl's in Tcl/Tk 8.0 and Plugins

12. Recursion with Tcl/Tk & ET

 

 
Powered by phpBB® Forum Software