animation?

Brian Keck (b.keck@trl.telstra.com.au)
Tue, 25 Feb 1997 12:20:47 +1100 (EST)

This is a resend - sorry if you've seen it. It never came back to me,
except in a bounce from somewhere I've never heard of, though it made
it into the htmlized archive.

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

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

#!/bin/sh
# $Source: /nfs/chook/proj/keck/manage/scotty/tkined/RCS/path,v $
# $Revision: 1.8 $$Date: 1997/02/24 09:39:03 $ \
exec scotty "$0" "$@"
# 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
# 1.7
# handles loops
# but doesn't find shortest path
# pointless recursion in path2 removed
# uses 1st 2 objects in selection instead of hardwired objects
# but no good because "ined select" doesn't return objects in order selected
# 1.8
# less silly paths ... won't visit same network (or host) twice
# but still doesn't find shortest path
# still too long inside nodes
# +tkined

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

#2# constants

# chook:/usr/include/X11/bitmaps not liked ("obsolete X10 bitmaps")

if [file isdirectory /usr/openwin/include/X11] {
set bitmapdir /usr/openwin/include/X11/bitmaps
} else {
set bitmapdir /usr/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 {
set NODE($name) $id
set NAME($id) $name
}
NETWORK {
set NETWORK($name) $id
set NAME($id) $name
}
LINK {
set src [ined src $id]
set dst [ined dst $id]
set LINK($name) $id
set NAME($id) $name
}
}
}

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

#4# path

# returns sequence of link ids

# recursion is over id2 so get links from id1 to id2 using lappend

proc path {id1 id2} {
global seen
foreach link [ined links $id2] {
if [info exists seen($link)] continue
set seen($link) 1
set src [ined src $link]
set dst [ined dst $link]
if {$src == $id2} {set id3 $dst} else {set id3 $src}
if [info exists seen($id3)] continue
set seen($id3) 1
if {$id3 == $id1} {return $link}
set part [path $id1 $id3]
if {$part != ""} {return [lappend part $link]}
}
}

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

#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} {
global NAME
set path2 {}
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 {set path2 [concat $path2 "{$a $b}" "{$c $d}"]}
cb {set path2 [concat $path2 "{$c $b}" "{$a $d}"]}
ad {set path2 [concat $path2 "{$a $d}" "{$c $b}"]}
cd {set path2 [concat $path2 "{$c $d}" "{$a $b}"]}
}
}
return $path2
}

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

#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]
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)]
foreach point $points {
set blob [ined create IMAGE $bitmapdir/dot]
ined move $blob [lindex $point 0] [lindex $point 1]
}
exit
}

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

#8# example

set selected [ined select]
set src [lindex $selected 0]
set dst [lindex $selected 1]
set points [path2 $src $dst]
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]
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.