Simple Animation with Megaimage

This will make a simple square move as you drag the mouse anywhere on the buffer using Megaimage and Megaimagetk.

  set dir [file dirname [info script]]
  set ext [info sharedlibextension]
  load [file join $dir megaimage$ext]
  load [file join $dir megaimagetk$ext]

  set size 100
  set obj_x 100
  set obj_y 50

  set canvas_width  600
  set canvas_height 800

  set obj [megaimage-blank $canvas_width $canvas_height]
  $obj rectangle 0 0 $canvas_width $canvas_height {0 0 0 255}
  $obj rectangle $obj_x $obj_y $size $size {255 255 255 255}

  pack [megaimage.frame .f] -fill both -expand 1
  .f size $canvas_width $canvas_height
  .f objsetimage $obj


  proc move_start {X Y} {
    global qx qy
    set qx $X ; set qy $Y
  }

  proc move_motion {X Y} {
    global qx qy
    set dx [expr {$X - $qx}]
    set dy [expr {$Y - $qy}]
    set qx $X ; set qy $Y

    global obj
    global size
    global obj_x obj_y
    global canvas_width canvas_height

    set obj_x [expr {$obj_x + $dx}]
    set obj_y [expr {$obj_y + $dy}]

    $obj rectangle 0 0 $canvas_width $canvas_height {0 0 0 255}
    $obj rectangle $obj_x $obj_y $size $size {255 255 255 255}
    .f objsetimage $obj

  }


  bind .f <1>               [list move_start   %X %Y]
  bind .f <Button1-Motion>  [list move_motion  %X %Y]

ABU 4-jan-2008

Is megaimage/tk fast enough to scroll/zoom a full-screen image without flickering ? (I'm thinking about the "Ken Burns" effect)

SupremeXeN.com KommandEr 2008-12-04

Currently, I would say no. But GPS is working on changing the back-end to be based on OpenGL, so I will say that most definitely it will be able to.