# Make a canvas with an image on it,
# and draw a red line across it.
# If the user clicks with the left mouse button,
# move a small green square to that point.

canvas .c -wid 300 -hei 300
pack app . .c top
set pit .c-[.c create photo 20 20 275 275]
readppm $pit teapot.ppm
.c create line 0 0 299 299 -width 3 -fill red
set bit [.c create line 0 0 1 1 -fill green]

proc box {x y} {
    global bit
    set x1 [expr {$x - 5}]
    set y1 [expr {$y - 5}]
    set x2 [expr {$x + 5}]
    set y2 [expr {$y + 5}]
    .c coords $bit $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1
}

bind .c <1> {box %x %y}
bind .c <B1-Motion> {box %x %y}
