home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / square < prev    next >
Text File  |  1996-04-23  |  1KB  |  56 lines

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4.  
  5. # square --
  6. # This script generates a demo application containing only
  7. # a "square" widget.  It's only usable if Tk has been compiled
  8. # with tkSquare.c and with the -DSQUARE_DEMO compiler switch.
  9. # This demo arranges the following bindings for the widget:
  10. # Button-1 press/drag:        moves square to mouse
  11. # "a":                toggle size animation on/off
  12. #
  13. # @(#) square 1.5 95/09/07 11:13:21
  14.  
  15. square .s
  16. pack .s -expand yes -fill both
  17. wm minsize . 1 1
  18.  
  19. bind .s <1> {center %x %y}
  20. bind .s <B1-Motion> {center %x %y}
  21. bind .s a animate
  22. focus .s
  23.  
  24. # The procedure below centers the square on a given position.
  25.  
  26. proc center {x y} {
  27.     set a [.s size]
  28.     .s position [expr $x-($a/2)] [expr $y-($a/2)]
  29. }
  30.  
  31. # The procedures below provide a simple form of animation where
  32. # the box changes size in a pulsing pattern: larger, smaller, larger,
  33. # and so on.
  34.  
  35. set inc 0
  36. proc animate {} {
  37.     global inc
  38.     if {$inc == 0} {
  39.     set inc 3
  40.     timer
  41.     } else {
  42.     set inc 0
  43.     }
  44. }
  45.  
  46. proc timer {} {
  47.     global inc
  48.     set s [.s size]
  49.     if {$inc == 0} return
  50.     if {$s >= 40} {set inc -3}
  51.     if {$s <= 10} {set inc 3}
  52.     .s size [expr {$s+$inc}]
  53.     after 30 timer
  54. }
  55.