File: example_heater.tcl

package info (click to toggle)
r-cran-tcltk2 1.2-10-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,356 kB
  • ctags: 1,386
  • sloc: tcl: 37,888; ansic: 792; python: 324; sh: 68; sed: 16; makefile: 1
file content (62 lines) | stat: -rwxr-xr-x 1,623 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package require Tk
source ./draw_diagram.tcl
#package require Diagrams
namespace import ::Diagrams::*

proc ::Diagrams::bracket {dir dist begin end} {
    variable state

    # Ad hoc!
    set coords [lrange $begin 1 2]
    if { $dir == "west" } {
       lappend coords [expr {[lindex $begin 1]-$dist}] [lindex $begin 2]
       lappend coords [expr {[lindex $begin 1]-$dist}] [lindex $end 2]
    }
    if { $dir == "east" } {
       lappend coords [expr {[lindex $begin 1]+$dist}] [lindex $begin 2]
       lappend coords [expr {[lindex $begin 1]+$dist}] [lindex $end 2]
    }
    if { $dir == "south" } {
       lappend coords [lindex $begin 1] [expr {[lindex $begin 2]+$dist}]
       lappend coords [lindex $end 1]   [expr {[lindex $begin 2]+$dist}]
    }
    if { $dir == "north" } {
       lappend coords [lindex $begin 1] [expr {[lindex $begin 2]-$dist}]
       lappend coords [lindex $end 1]   [expr {[lindex $begin 2]-$dist}]
    }
    lappend coords [lindex $end 1] [lindex $end 2]

    $state(canvas) create line $coords -arrow last
    # TODO: nice diagram object
}
namespace eval ::Diagrams {
    namespace export bracket
}
namespace import ::Diagrams::bracket

pack [canvas .c -width 300 -height 300 -bg white]
drawin .c

currentpos [position 100 20]
circle "Start"
direction south
arrow "" 40

#
# Store the object for later reference
#
set d [diamond "T > Tset?"]
arrow "no" 40
set b [box "Heat during\n1 minute"]
#
# Note: the order of direction/currentpos is important :(
#
direction east
currentpos [getpos E $d]

arrow "yes" 40
circle "Stop"

bracket west 30 [getpos W $b] [getpos W $d]

#saveps heater.ps