Debian Codegraph @

tclpkg/gdtclft/examples/gddemo.tcl

raw
1 #!/bin/sh
2 # next line is a comment in tcl \
3 exec tclsh "$0" ${1+"$@"}
4
5 package require Gdtclft
6
7 ################################################################
8 #
9 # gddemo in tcl
10 #
11
12 # open demoin.png or die
13 if {[catch {open demoin.png r} in]} {
14 puts stderr "Can't load source image; this demo is much";
15 puts stderr "more impressive if demoin.png is available";
16 exit
17 }
18
19 # Create output image 128 x 128
20 set im_out [gd create 128 128]
21
22 # First color is background
23 set white [gd color new $im_out 255 255 255]
24
25 # Set transparent
26 gd color transparent $im_out $white
27
28 # Load demoin.png and paste part of it into the output image.
29 set im_in [gd createFromPNG $in]
30 close $in
31
32 # Copy and shrink
33 gd copy $im_out $im_in 16 16 0 0 96 96 128 128
34
35 # Get some colors
36 set red [gd color new $im_out 255 0 0]
37 set green [gd color new $im_out 0 255 0]
38 set blue [gd color new $im_out 0 0 255]
39
40 # Draw a rectangle
41 gd line $im_out $green 8 8 120 8
42 gd line $im_out $green 120 8 120 120
43 gd line $im_out $green 120 120 8 120
44 gd line $im_out $green 8 120 8 8
45
46 # Text
47 gd text $im_out $red arial 20 0 16 16 hi
48 gd text $im_out $red arial 20 90 23 23 hi
49
50 # Circle
51 gd arc $im_out $blue 64 64 30 10 0 360
52
53 # Arc
54 gd arc $im_out $blue 64 64 20 20 45 135
55
56 # Flood fill
57 gd fill $im_out $blue 4 4
58
59 # Polygon
60 gd fillpolygon $im_out $green 32 0 0 64 64 64
61
62 # Brush. A fairly wild example also involving a line style!
63 if {$im_in != ""} {
64 set brush [gd create 8 8];
65 eval [concat gd copy $brush $im_in 0 0 0 0 [gd size $brush] [gd size $im_in]]
66 gd brush $im_out $brush
67 # Style so they won't overprint each other.
68 gd style $im_out "0 0 0 0 0 0 0 1"
69 gd line $im_out "styled brushed" 0 0 128 128
70 }
71
72 # Interlace the result for "fade in" in viewers that support it
73 gd interlace $im_out true
74
75 # Write PNG
76 set out [open demoout.png w]
77 gd writePNG $im_out $out
78 close $out
79 gd destroy $im_out