File: simplify.tcl

package info (click to toggle)
blt 3.0~1%2B08570046%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 45,556 kB
  • sloc: ansic: 278,852; tcl: 96,434; sh: 3,410; makefile: 2,026; cpp: 374
file content (63 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
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
#
# Example of BLT simplify command.  Performs line simplication on x and y 
# vectors, filling results in two output vectors.  The last argument is the 
# tolerance.
#

package require BLT

set afterId -1

proc UpdateGraph {} {
  global afterId
  after cancel $afterId
  set afterId [after idle Simplify]
}
proc Simplify {} {
  global afterId
  blt::simplify x0 y0 xs ys [.s get mark]
  set afterId -1
}

blt::graph .g \
    -width 700
blt::scale .s \
    -min 0.0 \
    -max 0.5 \
    -command UpdateGraph \
    -hide minarrow \
    -hide maxarrow

blt::table . \
    0,0 .g -fill both \
    1,0 .s -fill x
blt::table configure . c* r* -resize none
blt::table configure . c0 r0* -resize both
blt::vector x0
blt::vector y0
blt::vector xs
blt::vector ys

.g element create simplified \
    -x xs \
    -y ys \
    -pixels 3 \
    -label simplified \
    -color red4 -fill red1 \

.g element create original \
    -x x0 \
    -y y0 \
    -pixels 3 \
    -label original \
    -color green4 -fill green2 \
    -dashes 1

.g axis configure x  -title "radians"
.g axis configure y  -title "sine"
x0 seq -180 360 5
set pi 3.14159265358979323846
set pi1_2 [expr $pi/180.0]
x0 expr {x0 * $pi1_2}
y0 expr {(random(x0)-0.5) * 0.5 + sin(x0) }
.s set 0.25