#
 #-----------------------------------------------------
 # proc : setRectangle (Zeichnet einen Punkt)
 #-----------------------------------------------------
 #

 proc setRectangle {x y} {

   
set Color [.window.color cget -background]
   .window.c create rectangle $x $y [
expr $x-2] [expr $y-2]
       -fill $Color -outline $Color

 }

 #
 #-----------------------------------------------------
 # proc : getNextColor (ermittelt die Zeichenfarbe)
 #-----------------------------------------------------
 #
 
proc getNextColor {Color} {

   
switch $Color {
     red {
set NextColor green}
     green {
set NextColor blue}
     blue {
set NextColor red}
   }
   
return $NextColor

 }

 #
 #-----------------------------------------------------
 # proc : createCanvasWindow (Zeichenfläche)
 #-----------------------------------------------------
 #
 
proc createCanvasWindow {} {

   
toplevel .window
   
wm title .window "Unser Malprogramm"
   
focus .window
   
canvas .window.c -background white
   
button .window.exit -text "Malprogramm beenden"
                       -command {destroy .window}
   
button .window.color
     -background red
     -command {
       set Color [getNextColor [.window.color cget -background]]
       .window.color configure -background $Color
      }
   
pack .window.c -side top -fill both -expand 1
   pack .window.color -side top -fill both -expand 1
   
pack .window.exit -side top -fill both -expand 1

 }
 #
 #-----------------------------------------------------
 # proc : createCanvasBindings (Ereignisprozeduren)
 #-----------------------------------------------------
 #
 
proc createCanvasBindings {} {

   
global LeftButtonPressed

   
bind .window.c <Button-1> {
     setRectangle %x %x
     
set LeftButtonPressed 1
   }
   
bind .window.c <Motion> {
     
if {$LeftButtonPressed} {
       setRectangle %x %y
     }
   }
   
bind .window.c <ButtonRelease-1> {
     
set LeftButtonPressed 0
   }

 }
 
#
 #-----------------------------------------------------
 # main program (Hauptprogramm)
 #-----------------------------------------------------
 #
 
set LeftButtonPressed 0
 createCanvasWindow
 createCanvasBindings