1#!/bin/sh 2# the next line restarts using wish \ 3exec 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# 11# Button-1 press/drag: moves square to mouse 12# "a": toggle size animation on/off 13# 14# SCCS: @(#) square 1.6 96/02/16 10:49:21 15 16square .s 17pack .s -expand yes -fill both 18wm minsize . 1 1 19 20bind .s <1> {center %x %y} 21bind .s <B1-Motion> {center %x %y} 22bind .s a animate 23focus .s 24 25# The procedure below centers the square on a given position. 26 27proc center {x y} { 28 set a [.s size] 29 .s position [expr $x-($a/2)] [expr $y-($a/2)] 30} 31 32# The procedures below provide a simple form of animation where 33# the box changes size in a pulsing pattern: larger, smaller, larger, 34# and so on. 35 36set inc 0 37proc animate {} { 38 global inc 39 if {$inc == 0} { 40 set inc 3 41 timer 42 } else { 43 set inc 0 44 } 45} 46 47proc timer {} { 48 global inc 49 set s [.s size] 50 if {$inc == 0} return 51 if {$s >= 40} {set inc -3} 52 if {$s <= 10} {set inc 3} 53 .s size [expr {$s+$inc}] 54 after 30 timer 55} 56