tkar 0.63
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/FAQ.rdoc +39 -0
- data/History.txt +175 -0
- data/README.rdoc +153 -0
- data/TODO +67 -0
- data/bin/tkar +104 -0
- data/examples/dial.rb +172 -0
- data/examples/help.gif +0 -0
- data/examples/home.gif +0 -0
- data/examples/mkgrid.rb +58 -0
- data/examples/ps.rb +47 -0
- data/examples/rotate +26 -0
- data/examples/s +3 -0
- data/examples/sample +14 -0
- data/examples/sample.rb +98 -0
- data/examples/sample2 +48 -0
- data/examples/sample3 +57 -0
- data/examples/server.rb +45 -0
- data/examples/tavis.rb +90 -0
- data/install.rb +1015 -0
- data/lib/tkar.rb +109 -0
- data/lib/tkar/argos.rb +214 -0
- data/lib/tkar/canvas.rb +370 -0
- data/lib/tkar/help-window.rb +168 -0
- data/lib/tkar/primitives.rb +376 -0
- data/lib/tkar/stream.rb +284 -0
- data/lib/tkar/timer.rb +174 -0
- data/lib/tkar/tkaroid.rb +95 -0
- data/lib/tkar/version.rb +5 -0
- data/lib/tkar/window.rb +383 -0
- data/protocol.rdoc +539 -0
- data/rakefile +56 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- metadata +116 -0
data/examples/dial.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# based on the 24hr_clock example from the tkruby demos
|
4
|
+
|
5
|
+
# run like this: ruby dial.rb | tkar
|
6
|
+
|
7
|
+
# Do the housekeeping associated with each step in the animation
|
8
|
+
def draw s, delay = nil
|
9
|
+
puts s # note if s is array, it is joined with "\n"
|
10
|
+
if delay
|
11
|
+
puts "wait #{delay}"
|
12
|
+
end
|
13
|
+
puts "update"
|
14
|
+
$stdout.flush
|
15
|
+
end
|
16
|
+
|
17
|
+
# Output the shape def for a circle
|
18
|
+
def circle radius, foreground, background
|
19
|
+
coords = [-radius, -radius, radius, radius]
|
20
|
+
"oval#{coords.join(",")},fc:#{foreground},oc:#{background}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Output the shape def for a clock hand
|
24
|
+
def hand length, width, offset, color
|
25
|
+
coords = [
|
26
|
+
0, -offset,
|
27
|
+
width, -offset-width,
|
28
|
+
width, -length+width,
|
29
|
+
0, -length,
|
30
|
+
-width, -length+width,
|
31
|
+
-width, -offset-width
|
32
|
+
]
|
33
|
+
"poly#{coords.join(",")},fc:#{color},oc:#{color}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def mark radius, length, width, color, font = nil, offset = nil, text = nil
|
37
|
+
coords = [radius-length, 0, radius, 0]
|
38
|
+
|
39
|
+
s = "line#{coords.join(",")},wi:#{width},fc:#{color}"
|
40
|
+
|
41
|
+
if text
|
42
|
+
s << " text#{radius+offset},0,anchor:center,justify:center,text:#{text}"
|
43
|
+
s << ",fc:#{color},font:#{font}"
|
44
|
+
end
|
45
|
+
|
46
|
+
return s
|
47
|
+
end
|
48
|
+
|
49
|
+
def pie radius, extent, start, color
|
50
|
+
"arc0,0,#{radius},#{radius},extent:#{extent},start:#{start},style:pieslice," +
|
51
|
+
"fill:#{color}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Parameters for this drawing
|
55
|
+
|
56
|
+
size = 200
|
57
|
+
radius = size*0.9
|
58
|
+
cdot_size = 5
|
59
|
+
cdot_color = 'black'
|
60
|
+
hour_hand_color = 'black'
|
61
|
+
minute_hand_color = 'gray25'
|
62
|
+
second_hand_color = 'gray50'
|
63
|
+
face_color = "white"
|
64
|
+
|
65
|
+
mark_font = "-*-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-*"
|
66
|
+
mark_width = 3
|
67
|
+
mark_color = 'black'
|
68
|
+
submark_color = 'gray50'
|
69
|
+
|
70
|
+
hour_hand_len = 0.55*size
|
71
|
+
minute_hand_len = 0.85*size
|
72
|
+
second_hand_len = 0.88*size
|
73
|
+
|
74
|
+
hour_hand_width = 1.8*cdot_size
|
75
|
+
minute_hand_width = 1.0*cdot_size
|
76
|
+
second_hand_width = 0.4*cdot_size
|
77
|
+
|
78
|
+
# Draw the shapes
|
79
|
+
|
80
|
+
draw %{
|
81
|
+
|
82
|
+
# window setup
|
83
|
+
|
84
|
+
title dial example
|
85
|
+
background gray90
|
86
|
+
width #{2*size + 20}
|
87
|
+
height #{2*size + 20}
|
88
|
+
zoom 1.0
|
89
|
+
|
90
|
+
# shape definitions (most are not parametrized because they do not need
|
91
|
+
# to change shape or color dynamically or have individual configuration
|
92
|
+
# other than position and rotation)
|
93
|
+
|
94
|
+
shape face #{circle(radius, face_color, "black")}
|
95
|
+
|
96
|
+
shape cdot #{circle(cdot_size, cdot_color, cdot_color)}
|
97
|
+
|
98
|
+
shape hour_hand #{
|
99
|
+
hand(hour_hand_len, hour_hand_width, cdot_size*0.5, hour_hand_color)
|
100
|
+
}
|
101
|
+
|
102
|
+
shape minute_hand #{
|
103
|
+
hand(minute_hand_len, minute_hand_width, cdot_size*0.5, minute_hand_color)
|
104
|
+
}
|
105
|
+
|
106
|
+
shape second_hand #{
|
107
|
+
hand(second_hand_len, second_hand_width, cdot_size*0.5, second_hand_color)
|
108
|
+
}
|
109
|
+
|
110
|
+
shape mark #{
|
111
|
+
mark(radius, radius*0.025, mark_width, submark_color)
|
112
|
+
}
|
113
|
+
|
114
|
+
# params: *0 is text
|
115
|
+
shape labelled_mark #{
|
116
|
+
mark(radius, radius*0.05, mark_width, mark_color,
|
117
|
+
mark_font, radius*0.1, "*0")
|
118
|
+
}
|
119
|
+
|
120
|
+
# params: *0 is extent angle, *1 is start angle, *2 is color
|
121
|
+
shape pie #{
|
122
|
+
pie(radius, "*0", "*1", "*2")
|
123
|
+
}
|
124
|
+
|
125
|
+
# Add some objects
|
126
|
+
|
127
|
+
# shape ID flags layer x y rot params...
|
128
|
+
#--------------------------------------------------------------
|
129
|
+
|
130
|
+
add face 1 - 10 0 0 0
|
131
|
+
add cdot 2 - 20 0 0 0
|
132
|
+
add hour_hand 3 - 15 0 0 0
|
133
|
+
add minute_hand 4 - 16 0 0 0
|
134
|
+
add second_hand 5 - 17 0 0 0
|
135
|
+
add pie 6 - 12 0 0 0 15 75 red
|
136
|
+
add pie 7 - 12 0 0 0 67 -72 green
|
137
|
+
add pie 8 - 12 0 0 0 17 187 blue
|
138
|
+
}
|
139
|
+
|
140
|
+
draw %{
|
141
|
+
# move the view to the right place to see object #1
|
142
|
+
view_id 1
|
143
|
+
}
|
144
|
+
|
145
|
+
mark_strs = (0..11).map do |i|
|
146
|
+
"add mark #{100+i} - 14 0 0 #{30*i+15}"
|
147
|
+
end
|
148
|
+
|
149
|
+
draw mark_strs
|
150
|
+
|
151
|
+
labelled_mark_strs = (0..11).map do |i|
|
152
|
+
"add labelled_mark #{200+i} - 14 0 0 #{30*i-90} #{i*2}"
|
153
|
+
end
|
154
|
+
|
155
|
+
draw labelled_mark_strs
|
156
|
+
|
157
|
+
# Animate!
|
158
|
+
|
159
|
+
1_000_000.times do |i|
|
160
|
+
h = i*0.001
|
161
|
+
draw %{
|
162
|
+
rot 3 #{h}
|
163
|
+
rot 4 #{60*h}
|
164
|
+
rot 5 #{60*60*h}
|
165
|
+
# param 201 0 #{i}
|
166
|
+
# param 8 0 #{i%100}
|
167
|
+
# param 7 2 ##{s="%06x"%(i*32)}
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
$stderr.puts "Press Enter to finish"
|
172
|
+
gets
|
data/examples/help.gif
ADDED
Binary file
|
data/examples/home.gif
ADDED
Binary file
|
data/examples/mkgrid.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# mkgrid -- generate grid code for a tkar shape file
|
2
|
+
#
|
3
|
+
# To see what the grid looks like by itself:
|
4
|
+
#
|
5
|
+
# ruby mkgrid.rb | tkar --radians --persist
|
6
|
+
#
|
7
|
+
# (The --radians is because this is designed to be used from
|
8
|
+
# code that uses radians for angles. The --persist is because
|
9
|
+
# this is just some static objects, not an animation, so it will
|
10
|
+
# close after drawing without the persist option.)
|
11
|
+
#
|
12
|
+
# To use with other code, run like this:
|
13
|
+
#
|
14
|
+
# ruby mkgrid > grid.shp
|
15
|
+
#
|
16
|
+
# Then, add a line like this to your shape file:
|
17
|
+
#
|
18
|
+
# load grid.shp
|
19
|
+
#
|
20
|
+
# It doesn't really matter what part of the file you put the line in.
|
21
|
+
# Near the top is ok.
|
22
|
+
#
|
23
|
+
# Make sure grid.shp is in the same dir as the shape file, or enter the
|
24
|
+
# relative path.
|
25
|
+
#
|
26
|
+
# Adjust the parameters as needed: xmin, interval, mark_font, etc.
|
27
|
+
#
|
28
|
+
# You can disable the grid by commenting the "load grid.shp" line in
|
29
|
+
# the shape file (insert a # character at the beginning of the line)
|
30
|
+
#
|
31
|
+
# Note: if you are using this without simulink, remember to use the --radians
|
32
|
+
# option to tkar, otherwise it will look funny!
|
33
|
+
|
34
|
+
mark_font = "-*-Helvetica-Bold-R-Normal--*-90-*-*-*-*-*-*"
|
35
|
+
|
36
|
+
puts "shape grid_line line0,0,*0,0,wi:0.1,fc:black"
|
37
|
+
puts "shape mark text0,0,anchor:sw,justify:center,text:*0,fc:red,font:#{mark_font}"
|
38
|
+
puts
|
39
|
+
|
40
|
+
id = 12000 # high enough not to interfere (hacky!)
|
41
|
+
r = Math::PI/2 # when called from the tkar simulink block, tkar uses radians
|
42
|
+
|
43
|
+
xmin = -2000; xmax = 2000; xmid = 0
|
44
|
+
ymin = -2000; ymax = 2000; ymid = 0
|
45
|
+
interval = 100
|
46
|
+
|
47
|
+
xlen = xmax - xmin
|
48
|
+
ylen = ymax - ymin
|
49
|
+
|
50
|
+
(xmin..xmax).step(interval) do |x|
|
51
|
+
puts "add grid_line #{id+=1} - 0 #{x} #{ymin} #{r} #{ylen}"
|
52
|
+
puts "add mark #{id+=1} - 0 #{x} #{ymid} 0 #{x}"
|
53
|
+
end
|
54
|
+
|
55
|
+
(ymin..ymax).step(interval) do |y|
|
56
|
+
puts "add grid_line #{id+=1} - 0 #{xmin} #{y} 0 #{xlen}"
|
57
|
+
puts "add mark #{id+=1} - 0 #{xmid} #{y} 0 #{y}"
|
58
|
+
end
|
data/examples/ps.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Visualization of cpu usage from ps output. Run like this:
|
2
|
+
#
|
3
|
+
# ruby ps.rb | tkar
|
4
|
+
#
|
5
|
+
# If you don't see the pids, scroll down.
|
6
|
+
|
7
|
+
$stdout.sync = true
|
8
|
+
|
9
|
+
puts %{
|
10
|
+
title Process Status
|
11
|
+
height 600
|
12
|
+
width 600
|
13
|
+
bg white
|
14
|
+
update
|
15
|
+
|
16
|
+
shape bar \
|
17
|
+
poly0,0,50,0,50,*0,0,*0,oc:black,width:2,fc:*2 \
|
18
|
+
text25,20,anchor:c,justify:center,width:50,text:*1,fc:black
|
19
|
+
|
20
|
+
# SHAPE_NAME ID FLAGS LAYER X Y R PARAMS...
|
21
|
+
add bar 1 - 100 50 550 0 0 unknown blue
|
22
|
+
add bar 2 - 100 150 550 0 0 unknown blue
|
23
|
+
add bar 3 - 100 250 550 0 0 unknown blue
|
24
|
+
add bar 4 - 100 350 550 0 0 unknown blue
|
25
|
+
add bar 5 - 100 450 550 0 0 unknown blue
|
26
|
+
update
|
27
|
+
}
|
28
|
+
|
29
|
+
PS_FIELDS = "pcpu,pmem,s,time,pid,cmd"
|
30
|
+
TOP_CPU_CMD = "ps -A --sort=-pcpu -o cputime,#{PS_FIELDS} | head -n 6"
|
31
|
+
|
32
|
+
loop do
|
33
|
+
s = `#{TOP_CPU_CMD}`
|
34
|
+
a = s.map {|l| l[/[0-9:]*\s+(\S+)/, 1]}.map {|t| Float(t) rescue nil}.compact
|
35
|
+
b = s.map {|l| l[30,5]}.map {|t| Integer(t) rescue nil}.compact
|
36
|
+
i = 1
|
37
|
+
a.zip(b) do |pcpu, pid|
|
38
|
+
puts "param #{i} 1 #{pid}"
|
39
|
+
puts "param #{i} 0 -#{pcpu*5}"
|
40
|
+
i += 1
|
41
|
+
$stderr.puts [pcpu, pid].inspect
|
42
|
+
end
|
43
|
+
puts "update"
|
44
|
+
|
45
|
+
sleep 1
|
46
|
+
end
|
47
|
+
|
data/examples/rotate
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Rotation is not a built-in operation in TkCanvas, but it is in tkar.
|
2
|
+
# Run like:
|
3
|
+
#
|
4
|
+
# cat rotate | tkar
|
5
|
+
|
6
|
+
shape box poly0,0,10,0,10,10,0,10,fc:green,oc:red
|
7
|
+
|
8
|
+
add box 3 - 4 50 20 0
|
9
|
+
update
|
10
|
+
|
11
|
+
wait 1.0
|
12
|
+
rot 3 45
|
13
|
+
update
|
14
|
+
|
15
|
+
wait 1.0
|
16
|
+
rot 3 90
|
17
|
+
update
|
18
|
+
|
19
|
+
wait 1.0
|
20
|
+
rot 3 135
|
21
|
+
update
|
22
|
+
|
23
|
+
wait 1.0
|
24
|
+
rot 3 180
|
25
|
+
update
|
26
|
+
|
data/examples/s
ADDED
data/examples/sample
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This sample is written directly in the tkar protocol, rather
|
2
|
+
# than generated by another program. Usually, you don't do this
|
3
|
+
# directly, since it would be very tedious to enter all the
|
4
|
+
# movement commands. To run it:
|
5
|
+
#
|
6
|
+
# cat sample | tkar --persist
|
7
|
+
#
|
8
|
+
# Note that you can drag the boxes around and see the commands on stdout.
|
9
|
+
|
10
|
+
shape box rect50,50,0,0 rect5,5,10,10
|
11
|
+
add box 3 - 4 10 10 0
|
12
|
+
shape box2 rect10,10,0,1
|
13
|
+
add box2 4 - 4 100 10 0
|
14
|
+
|
data/examples/sample.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# A sample of many of the TkCanvas features usable in tkar.
|
4
|
+
#
|
5
|
+
# Run like:
|
6
|
+
#
|
7
|
+
# ruby sample.rb | tkar
|
8
|
+
#
|
9
|
+
# Not that if you click and drag on things, you can see the commands in the
|
10
|
+
# stdout. If your program is listening to that stream, it can feedback into
|
11
|
+
# the animation.
|
12
|
+
|
13
|
+
puts %{
|
14
|
+
title Strange bits of stuff: Tkar demo
|
15
|
+
background gray95
|
16
|
+
height 600
|
17
|
+
width 600
|
18
|
+
|
19
|
+
shape box polybox50,50,fc:*1,oc:*0 polybox5,5,fc:*0,oc:*1 \
|
20
|
+
oval30,-30,60,-60,fc:white,oc:gray
|
21
|
+
|
22
|
+
shape box2 polybox10,10,fc:*0,oc:*1
|
23
|
+
|
24
|
+
shape cone arc*0,*1,*2,*2,fc:yellow,oc:black,extent:30,start:-15,style:pieslice
|
25
|
+
|
26
|
+
shape thang polybox40,60,fc:*0,oc:*1,wi:5 \
|
27
|
+
polybox*2,10,fc:*1,oc:red,da:48,wi:3 \
|
28
|
+
cone20,40,60 \
|
29
|
+
line20,40,80,40,fc:purple,da:44
|
30
|
+
|
31
|
+
shape radar \
|
32
|
+
cone0,0,*0 \
|
33
|
+
cone20,0,*0,style:chord \
|
34
|
+
cone40,0,*0,style:chord \
|
35
|
+
line0,0,-20,-20,*1,0,*1,*1,0,-60,arrow:last,arrowshape:10+8+6,\
|
36
|
+
smooth:true,wi:2,fc:0x609000
|
37
|
+
|
38
|
+
shape blob \
|
39
|
+
poly0,0,10,0,20,5,15,30,-3,6,-20,40,-15,-10,5,5,smooth:true,oc:red,fc:0 \
|
40
|
+
text0,50,anchor:c,justify:center,width:40,text:*0,fc:0 \
|
41
|
+
image25,50,anchor:c,image:home.gif
|
42
|
+
|
43
|
+
add box 3 - 4 210 210 0 0xff0000 0x00ff00
|
44
|
+
add box2 4 - 4 300 210 0 0x0000ff 0x00ff00
|
45
|
+
update
|
46
|
+
}
|
47
|
+
|
48
|
+
$stdout.flush; sleep 1
|
49
|
+
|
50
|
+
puts %{
|
51
|
+
del 4
|
52
|
+
update
|
53
|
+
}
|
54
|
+
|
55
|
+
$stdout.flush; sleep 1
|
56
|
+
|
57
|
+
puts %{
|
58
|
+
move 3 165 150
|
59
|
+
param 3 0 0xffffff
|
60
|
+
param 3 1 blue
|
61
|
+
add box2 1 - 2 280 220 25 orange cyan
|
62
|
+
add thang 2 - 3 200 200 45 magenta green 80
|
63
|
+
add radar 6 - 5 360 360 25 60 -40
|
64
|
+
add blob 7 - 6 140 280 0
|
65
|
+
param 7 0 This is some text
|
66
|
+
update
|
67
|
+
}
|
68
|
+
|
69
|
+
$stdout.flush; sleep 1
|
70
|
+
|
71
|
+
45.step(3600,5) do |i|
|
72
|
+
xy = 200 + i/15.0
|
73
|
+
puts %{
|
74
|
+
rot 2 #{i}
|
75
|
+
move 2 #{xy} #{xy}
|
76
|
+
param 2 2 #{80-(i/30.0)}
|
77
|
+
rot 1 #{-i}
|
78
|
+
param 6 0 #{60+i%40}
|
79
|
+
param 6 1 #{-20-i%80}
|
80
|
+
update
|
81
|
+
}
|
82
|
+
$stdout.flush; #sleep 0.02
|
83
|
+
end
|
84
|
+
|
85
|
+
500.times do |i|
|
86
|
+
puts %{
|
87
|
+
scale 3 #{1.0 + 0.005 * Math::sin(i/100.0)} 1.0
|
88
|
+
update
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
$stdout.flush; sleep 1
|
93
|
+
|
94
|
+
puts "done"
|
95
|
+
$stdout.flush
|
96
|
+
|
97
|
+
$stderr.puts "Press enter to finish."
|
98
|
+
gets
|
data/examples/sample2
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# A very simple animation. Run like this:
|
2
|
+
#
|
3
|
+
# cat sample2 | tkar --persist
|
4
|
+
|
5
|
+
# Global settings for the window
|
6
|
+
title sample2
|
7
|
+
height 500
|
8
|
+
width 500
|
9
|
+
bg azure1
|
10
|
+
|
11
|
+
# -------------------------------------------------------------------------
|
12
|
+
# Shape definitions
|
13
|
+
shape box2 poly0,0,50,0,50,20,0,20,fc:red,oc:blue
|
14
|
+
|
15
|
+
# -------------------------------------------------------------------------
|
16
|
+
# Add some shapes
|
17
|
+
# -------------------------------------------------------------------------
|
18
|
+
# SHAPE_NAME ID FLAGS LAYER X Y R PARAMS...
|
19
|
+
|
20
|
+
add box2 1 - 100 10 10 0
|
21
|
+
|
22
|
+
# -------------------------------------------------------------------------
|
23
|
+
# draw them
|
24
|
+
update
|
25
|
+
|
26
|
+
# -------------------------------------------------------------------------
|
27
|
+
# animate
|
28
|
+
|
29
|
+
wait 1.0
|
30
|
+
move 1 20 20
|
31
|
+
rot 1 10
|
32
|
+
update
|
33
|
+
|
34
|
+
wait 1.0
|
35
|
+
move 1 30 30
|
36
|
+
rot 1 20
|
37
|
+
update
|
38
|
+
|
39
|
+
wait 1.0
|
40
|
+
move 1 40 40
|
41
|
+
rot 1 30
|
42
|
+
update
|
43
|
+
|
44
|
+
wait 1.0
|
45
|
+
move 1 50 50
|
46
|
+
rot 1 40
|
47
|
+
update
|
48
|
+
|