animation?

Brian Keck (b.keck@trl.telstra.com.au)
Sun, 23 Feb 1997 22:23:46 +1100 (EST)

I've been trying to do some animation, & have a few questions.
The idea is to show packets moving around a network.

The obvious question is whether anyone else has done it. I fetched the
1966 mail archive & couldn't see anything.

My attempts are a bit clumsy, but attached since it might make my
meaning clearer.

Is there a way of getting the coordinates of the endpoints of a link?
The method below uses the bounding box (ined size ...), but has to
mess around to figure out which 2 of the 4 corners are the endpoints.

Is it possible to draw more than bitmaps (and graphs etc)?
(Here as elsewhere I'm hoping not to have to change tkined itself.)

Is it possible to make keyboard or mouse events on the main canvas (if
that's the right expression) notify my application? I know my
application can add a menu but I'd like more flexibility.

Can I add entries to the button-3 per-object menus that send to my
application?

Sorry to sound ungrateful - I really like tkined.

Thanks for any help,
Brian Keck

========================================================================

#!/usr/bin/scotty
# $Source: /home/keck/tkined/RCS/path,v $
# $Revision: 1.6 $$Date: 1997/02/23 05:53:42 $
# Contents
# 1 notes 3 label->id 5 path2 7 debug
# 2 constants 4 path 6 move 8 example

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

#1# notes

# for animation
# ie to show packet moving from one node to another
# defines procs path & path2 & move
# other stuff for testing & debugging

# 1.6
# first where blob stayed on the rails
# proc move still has time argument, so blob stays too long on nodes
# blob wobbles a bit

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

#2# constants

set bitmapdir /usr/X11R6/include/X11/bitmaps

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

#3# label->id

# for testing

set objects [ined retrieve]

foreach obj $objects {
set id [ined id $obj]
set name [ined name $obj]
switch [ined type $obj] {
NODE {
puts "$id $name"
set NODE($name) $id
}
NETWORK {
puts "$id $name"
set NETWORK($name) $id
}
LINK {
set src [ined src $id]
set dst [ined dst $id]
puts "$id $src $dst"
set LINK($name) $id
}
}
}

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

#4# path

# returns sequence of link ids

# recursion is over id2 so get links from id1 to id2
# link2 needed for recursion (is some link with id2 at one end)

proc path {id1 id2 {link2 ""}} {
foreach link [ined links $id2] {
if {$link == $link2} continue
set src [ined src $link]
set dst [ined dst $link]
if {$src == $id2} {set id3 $dst} else {set id3 $src}
if {$id3 == $id1} {return $link}
set part [path $id1 $id3 $link]
if {$part != ""} {return [lappend part $link]}
}
}

# puts [path node1 node4]
# puts [path node0 node3]

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

#5# path2

# returns sequence of coordinates ({x1 y1} {x2 y2} ...}
# uses proc path

# defect is that bbox corners are used as the ends of a link,
# so moving blob slants across link

proc path2 {id1 id2} {
set links [path $id1 $id2]
set first $id1
foreach link $links {
set size [ined size $link]
set a [lindex $size 0]
set b [lindex $size 1]
set c [lindex $size 2]
set d [lindex $size 3]
set xy [ined move $first]
set x [lindex $xy 0]
set y [lindex $xy 1]
set ab [expr (0.0+$a-$x)*($a-$x) + ($b-$y)*($b-$y)]
set cd [expr (0.0+$c-$x)*($c-$x) + ($d-$y)*($d-$y)]
set ad [expr (0.0+$a-$x)*($a-$x) + ($d-$y)*($d-$y)]
set cb [expr (0.0+$c-$x)*($c-$x) + ($b-$y)*($b-$y)]
if {$ab <= $cd} {
if {$ab <= $ad} {
if {$ab <= $cb} {set least ab} else {set least cb}
} else {
if {$ad <= $cb} {set least ad} else {set least cb}
}
} else {
if {$cd <= $ad} {
if {$cd <= $cb} {set least cd} else {set least cb}
} else {
if {$ad <= $cb} {set least ad} else {set least cb}
}
}
set src [ined src $link]
set dst [ined dst $link]
if {$src == $first} {set first $dst} else {set first $src}
switch $least {
ab {return [concat "{$a $b}" "{$c $d}" [path2 $first $id2]]}
cb {return [concat "{$c $b}" "{$a $d}" [path2 $first $id2]]}
ad {return [concat "{$a $d}" "{$c $b}" [path2 $first $id2]]}
cd {return [concat "{$c $d}" "{$a $b}" [path2 $first $id2]]}
}
}
}

# puts [path2 node1 node4]
# puts [path2 node0 node3]

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

#6# move

proc move {x1 y1 x2 y2 bitmap time} {
set initial [ined move $bitmap]
set x0 [lindex $initial 0]
set y0 [lindex $initial 1]
ined move $bitmap [expr $x1 - $x0] [expr $y1 - $y0]
set n [expr round($time * 10)]
set dx [expr (0.0 + $x2 - $x1) / $n]
set dy [expr (0.0 + $y2 - $y1) / $n]
puts "$dx $dy"
while {$n > 0} {
ined move $bitmap $dx $dy
incr n -1
after 100
}
}

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

#7# debug

if 0 {
# just makes a new blob at each link endpoint
set blob [ined create IMAGE $bitmapdir/dot]
set x0 0
set y0 0
set points [path2 $NODE(modem) $NODE(pollux)]
puts $points
foreach point $points {
puts $point
set blob [ined create IMAGE $bitmapdir/dot]
ined move $blob [lindex $point 0] [lindex $point 1]
}
exit
}

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

#8# example

set points [path2 $NODE(modem) $NODE(pollux)]
puts $points
set steps [llength $points]
set first [lindex $points 0]

set blob [ined create IMAGE $bitmapdir/dot]
ined move $blob [lindex $first 0] [lindex $first 1]

for {set i 0} {$i < $steps - 1} {incr i} {
set first [lindex $points $i]
set second [lindex $points [expr $i + 1]]
set x1 [lindex $first 0]
set y1 [lindex $first 1]
set x2 [lindex $second 0]
set y2 [lindex $second 1]
puts "$x1 $y1 $x2 $y2"
move $x1 $y1 $x2 $y2 $blob 2
}

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.