RosettaCodeData/Task/Grayscale-image/Tcl/grayscale-image.tcl
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

13 lines
380 B
Tcl

package require Tk
proc grayscale image {
set w [image width $image]
set h [image height $image]
for {set x 0} {$x<$w} {incr x} {
for {set y 0} {$y<$h} {incr y} {
lassign [$image get $x $y] r g b
set l [expr {int(0.2126*$r + 0.7152*$g + 0.0722*$b)}]
$image put [format "#%02x%02x%02x" $l $l $l] -to $x $y
}
}
}