You can create an image with the image create command
image create type ?name? ?option value ...?
type |
The type of image.
May be photo for multicolor images,
or bitmap for bitmap images.
|
?name? |
An optional name for this image. If not provided, Tcl will assign a name. |
?option value ...? |
Keyword/Value pairs that define the image object. Options
include -height and -width , etc.
|
You can retrieve individual pixels from an image with the
$imageName get
command.
imageName get xLoc yLoc
imageName |
The name of the image as
returned by image create
xloc yloc The x and y location for the pixel
| |
You can assign a value to a pixel with the
$imageName put
command.
imageName put colorList -to x1 y1 ?x2 y2?
imageName |
The name of the image as
returned by image create
colorList A list of colors to assign to the pixels in
Tcl color format.
| -to x1 y1 ?x2 y2? The X/Y location for a pixel, or a rectangular area
for a set of pixels.
| |
The format of the pixel needs to be something like #rrggbb
where rr
is a 2 digit hex value for the red intensity, etc.
To encode 3 decimal values into a Tcl color, use the format
command:
format formatString ?data1? ?data2? ...
format
command returns a new string based on a format
definition and a set of data values.
format | Returns a new string, formatted as
defined by the formatString string.
|
data# | Data to substitute into the format string. |
The format string to use for this is #02x02x02x
.
An image can be written to a file with the imageName write
command:
imageName write fileName -format fmt
imageName |
The name of the image as
returned by image create
fileName Path to the file to create
| -format fmt Define the image format for the file. By default
the format is | ppm . The gif format is
supported by default.
|
Write a Tcl script that will create an image and fill it with values
that fade from blue at the top to green at the bottom and then save
the image to a file named earthNsky.ppm
.
You can test your code with any image viewing software that supports
the ppm
format - gimp or xview on a Linux system, or openoffice
on Windows and Mac systems. Other viewing tools or the Tk/Wish canvas
can also be used.