File: plgrid.tcl

package info (click to toggle)
plplot 5.15.0%2Bdfsg-19
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 31,312 kB
  • sloc: ansic: 79,707; xml: 28,583; cpp: 20,033; ada: 19,456; tcl: 12,081; f90: 11,431; ml: 7,276; java: 6,863; python: 6,792; sh: 3,274; perl: 828; lisp: 75; makefile: 50; sed: 34; fortran: 5
file content (70 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
#----------------------------------------------------------------------------
# Demo polar grid plotter
#
#
# This programme uses the loopback widget so it can be run from either pltcl
# with a choice of the standard drivers or plserver with the plframe widget.
# (1) pltcl:
#     execute pltcl and type plinit to get a selection of
#     device types.  Choose one of the devices then type
#     "source plgrid.tcl" (this file), then type "plgrid"
#     with no arguments.
# (2) plserver
#     execute plserver then type the following (see ../tk/tkdemos.tcl for
#     many other working examples of this method).
#     plstdwin .
#     plxframe .plw
#     pack append . .plw {left expand fill}
#     source plgrid.tcl
#     proc 1 {} "plgrid .plw.plwin"
#     to execute this procedure that you have just created execute the "1"
#     command.
#----------------------------------------------------------------------------

proc plgrid {{w loopback}} {
    set ni 10
    set nj 20
    set nj1 [expr $nj + 1]

    matrix xi f $ni
    matrix yi f $ni
    matrix xj f $nj1
    matrix yj f $nj1

    set dr     [expr 1. / $ni]
    set dtheta [expr 2. * 3.14159265358979323846 / $nj]

# Set up viewport and window, but do not draw box

    $w cmd plssub 1 1
    $w cmd plcol0 1
    $w cmd plenv -1.3 1.3 -1.3 1.3 1 -2

# Draw i-lines

    for {set i 0} {$i < $ni} {incr i} {
	for {set j 0} {$j < $nj1} {incr j} {
	    set r     [expr $i * $dr]
	    set theta [expr $j * $dtheta]
	    set psi   [expr $theta + 0.5 * $r * sin($theta)]

	    xj $j = [expr $r * cos($psi)]
	    yj $j = [expr $r * sin($psi)]
	}
	$w cmd plline xj yj
    }

# Draw j-lines

    for {set j 0} {$j < $nj} {incr j} {
	for {set i 0} {$i < $ni} {incr i} {
	    set r     [expr $i * $dr]
	    set theta [expr $j * $dtheta]
	    set psi   [expr $theta + 0.5 * $r * sin($theta)]

	    xi $i = [expr $r * cos($psi)]
	    yi $i = [expr $r * sin($psi)]
	}
	$w cmd plline xi yi
    }
}