OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
Source at commit 868eb3b created 13 years 1 month ago. By Xiangfu Liu, rename nanonote-example files | |
---|---|
1 | --[[ $Id: x14.lua 10793 2010-02-06 01:48:39Z hbabcock $ |
2 | |
3 | Demo of multiple stream/window capability (requires Tk or Tcl-DP). |
4 | |
5 | Maurice LeBrun |
6 | IFS, University of Texas at Austin |
7 | |
8 | Copyright (C) 2009 Werner Smekal |
9 | |
10 | This file is part of PLplot. |
11 | |
12 | PLplot is free software you can redistribute it and/or modify |
13 | it under the terms of the GNU General Library Public License as published |
14 | by the Free Software Foundation either version 2 of the License, or |
15 | (at your option) any later version. |
16 | |
17 | PLplot is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | GNU Library General Public License for more details. |
21 | |
22 | You should have received a copy of the GNU Library General Public License |
23 | along with PLplot if not, write to the Free Software |
24 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
25 | --]] |
26 | |
27 | -- initialise Lua bindings for PLplot examples. |
28 | dofile("plplot_examples.lua") |
29 | |
30 | xs = {} |
31 | ys = {} |
32 | space0 = {} |
33 | mark0 = {} |
34 | space1 = { 1500 } |
35 | mark1 = { 1500 } |
36 | |
37 | |
38 | function plot1() |
39 | x = {} |
40 | y = {} |
41 | |
42 | for i = 1, 60 do |
43 | x[i] = xoff + xscale*i/60 |
44 | y[i] = yoff + yscale*x[i]^2 |
45 | end |
46 | |
47 | xmin = x[1] |
48 | xmax = x[60] |
49 | ymin = y[1] |
50 | ymax = y[60] |
51 | |
52 | for i = 1, 6 do |
53 | xs[i] = x[(i-1)*10 + 4] |
54 | ys[i] = y[(i-1)*10 + 4] |
55 | end |
56 | |
57 | -- Set up the viewport and window using PLENV. The range in X is |
58 | -- 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are |
59 | -- scaled separately (just = 0), and we just draw a labelled |
60 | -- box (axis = 0). |
61 | pl.col0(1) |
62 | pl.env(xmin, xmax, ymin, ymax, 0, 0) |
63 | pl.col0(6) |
64 | pl.lab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2") |
65 | |
66 | -- Plot the data points |
67 | pl.col0(9) |
68 | pl.poin(xs, ys, 9) |
69 | |
70 | -- Draw the line through the data |
71 | pl.col0(4) |
72 | pl.line(x, y) |
73 | pl.flush() |
74 | end |
75 | |
76 | |
77 | function plot2() |
78 | x = {} |
79 | y = {} |
80 | |
81 | -- Set up the viewport and window using PLENV. The range in X is -2.0 to |
82 | -- 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately |
83 | -- (just = 0), and we draw a box with axes (axis = 1). |
84 | pl.col0(1) |
85 | pl.env(-2, 10, -0.4, 1.2, 0, 1) |
86 | pl.col0(2) |
87 | pl.lab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function") |
88 | |
89 | -- Fill up the arrays |
90 | for i = 1, 100 do |
91 | x[i] = (i-20)/6 |
92 | y[i] = 1 |
93 | if x[i]~=0 then |
94 | y[i] = math.sin(x[i])/x[i] |
95 | end |
96 | end |
97 | |
98 | -- Draw the line |
99 | pl.col0(3) |
100 | pl.line(x, y) |
101 | pl.flush() |
102 | end |
103 | |
104 | |
105 | function plot3() |
106 | x = {} |
107 | y = {} |
108 | |
109 | -- For the final graph we wish to override the default tick intervals, and |
110 | -- so do not use PLENV |
111 | pl.adv(0) |
112 | |
113 | -- Use standard viewport, and define X range from 0 to 360 degrees, Y range |
114 | -- from -1.2 to 1.2. |
115 | pl.vsta() |
116 | pl.wind(0, 360, -1.2, 1.2) |
117 | |
118 | -- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. |
119 | pl.col0(1) |
120 | pl.box("bcnst", 60, 2, "bcnstv", 0.2, 2) |
121 | |
122 | -- Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl |
123 | -- expects a pointer!! |
124 | pl.styl(mark1, space1) |
125 | pl.col0(2) |
126 | pl.box("g", 30, 0, "g", 0.2, 0) |
127 | pl.styl(mark0, space0) |
128 | |
129 | pl.col0(3) |
130 | pl.lab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function") |
131 | |
132 | for i = 1, 101 do |
133 | x[i] = 3.6 * (i-1) |
134 | y[i] = math.sin(x[i]*math.pi/180) |
135 | end |
136 | |
137 | pl.col0(4) |
138 | pl.line(x, y) |
139 | pl.flush() |
140 | end |
141 | |
142 | |
143 | function plot4() |
144 | x0 = {} |
145 | y0 = {} |
146 | x = {} |
147 | y = {} |
148 | |
149 | dtr = math.pi/180 |
150 | for i = 1, 361 do |
151 | x0[i] = math.cos(dtr*(i-1)) |
152 | y0[i] = math.sin(dtr*(i-1)) |
153 | end |
154 | |
155 | -- Set up viewport and window, but do not draw box |
156 | pl.env(-1.3, 1.3, -1.3, 1.3, 1, -2) |
157 | for i = 1, 10 do |
158 | for j = 1, 361 do |
159 | x[j] = 0.1*i*x0[j] |
160 | y[j] = 0.1*i*y0[j] |
161 | end |
162 | |
163 | -- Draw circles for polar grid |
164 | pl.line(x, y) |
165 | end |
166 | |
167 | pl.col0(2) |
168 | for i = 1, 12 do |
169 | theta = 30.0 * (i-1) |
170 | dx = math.cos(dtr * theta) |
171 | dy = math.sin(dtr * theta) |
172 | |
173 | -- Draw radial spokes for polar grid |
174 | pl.join(0, 0, dx, dy) |
175 | |
176 | -- Write labels for angle |
177 | -- Slightly off zero to avoid floating point logic flips at 90 and 270 deg. |
178 | if dx>=-0.00001 then |
179 | pl.ptex(dx, dy, dx, dy, -0.15, tostring(theta)) |
180 | else |
181 | pl.ptex(dx, dy, -dx, -dy, 1.15, tostring(theta)) |
182 | end |
183 | end |
184 | |
185 | x = {} |
186 | y = {} |
187 | |
188 | -- Draw the graph |
189 | for i = 1, 361 do |
190 | r = math.sin(dtr * (5*(i-1))) |
191 | x[i] = x0[i] * r |
192 | y[i] = y0[i] * r |
193 | end |
194 | |
195 | pl.col0(3) |
196 | pl.line(x, y) |
197 | |
198 | pl.col0(4) |
199 | pl.mtex("t", 2, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh") |
200 | pl.flush() |
201 | end |
202 | |
203 | -- Demonstration of contour plotting |
204 | |
205 | XPTS = 35 |
206 | YPTS = 46 |
207 | XSPA = 2/(XPTS-1) |
208 | YSPA = 2/(YPTS-1) |
209 | |
210 | tr = { XSPA, 0, -1, 0, YSPA, -1 } |
211 | |
212 | function mypltr(x, y) |
213 | tx = tr[1]*x + tr[2]*y + tr[3] |
214 | ty = tr[4]*x + tr[5]*y + tr[6] |
215 | |
216 | return tx, ty |
217 | end |
218 | |
219 | clevel = { -1, -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1 } |
220 | |
221 | function plot5() |
222 | mark = { 1500 } |
223 | space = { 1500 } |
224 | |
225 | -- Set up function arrays |
226 | z = {} |
227 | w = {} |
228 | |
229 | for i = 1, XPTS do |
230 | xx = (i-1-math.floor(XPTS/2))/math.floor(XPTS/2) |
231 | z[i] = {} |
232 | w[i] = {} |
233 | for j = 1, YPTS do |
234 | yy = (j-1-math.floor(YPTS/2))/math.floor(YPTS/2)-1 |
235 | z[i][j] = xx * xx - yy * yy |
236 | w[i][j] = 2 * xx * yy |
237 | end |
238 | end |
239 | |
240 | pl.env(-1, 1, -1, 1, 0, 0) |
241 | pl.col0(2) |
242 | pl.cont(z, 1, XPTS, 1, YPTS, clevel, "mypltr") |
243 | pl.styl(mark, space) |
244 | pl.col0(3) |
245 | pl.cont(w, 1, XPTS, 1, YPTS, clevel, "mypltr") |
246 | pl.col0(1) |
247 | pl.lab("X Coordinate", "Y Coordinate", "Streamlines of flow") |
248 | pl.flush() |
249 | end |
250 | |
251 | |
252 | ---------------------------------------------------------------------------- |
253 | -- main |
254 | -- |
255 | -- Plots several simple functions from other example programs. |
256 | -- |
257 | -- This version sends the output of the first 4 plots (one page) to two |
258 | -- independent streams. |
259 | ---------------------------------------------------------------------------- |
260 | |
261 | -- Select either TK or DP driver and use a small window |
262 | -- Using DP results in a crash at the end due to some odd cleanup problems |
263 | -- The geometry strings MUST be in writable memory |
264 | geometry_master = "500x410+100+200" |
265 | geometry_slave = "500x410+650+200" |
266 | |
267 | -- plplot initialization |
268 | -- Parse and process command line arguments |
269 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
270 | |
271 | -- If valid geometry specified on command line, use it for both streams. |
272 | xp0, yp0, xleng0, yleng0, xoff0, yoff0 = pl.gpage() |
273 | valid_geometry = xleng0>0 and yleng0>0 |
274 | |
275 | -- Set up first stream |
276 | if valid_geometry==true then |
277 | pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0) |
278 | else |
279 | pl.setopt("geometry", geometry_master) |
280 | end |
281 | |
282 | pl.ssub(2, 2) |
283 | pl.init() |
284 | |
285 | driver = pl.gdev() |
286 | fam, num, bmax = pl.gfam() |
287 | |
288 | print("Demo of multiple output streams via the " .. driver .." driver.") |
289 | print("Running with the second stream as slave to the first.\n") |
290 | |
291 | -- Start next stream |
292 | pl.sstrm(1) |
293 | |
294 | if valid_geometry==true then |
295 | pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0) |
296 | else |
297 | pl.setopt("geometry", geometry_slave) |
298 | end |
299 | |
300 | -- Turn off pause to make this a slave (must follow master) |
301 | pl.spause(0) |
302 | pl.sdev(driver) |
303 | pl.sfam(fam,num,bmax) |
304 | |
305 | -- Currently number of digits in format number can only be |
306 | --set via the command line option |
307 | pl.setopt("fflen", "2") |
308 | pl.init() |
309 | |
310 | -- Set up the data & plot |
311 | -- Original case |
312 | pl.sstrm(0) |
313 | |
314 | xscale = 6 |
315 | yscale = 1 |
316 | xoff = 0 |
317 | yoff = 0 |
318 | plot1() |
319 | |
320 | -- Set up the data & plot |
321 | xscale = 1 |
322 | yscale = 1e6 |
323 | plot1() |
324 | |
325 | -- Set up the data & plot |
326 | xscale = 1. |
327 | yscale = 1.e-6 |
328 | digmax = 2 |
329 | pl.syax(digmax, 0) |
330 | plot1() |
331 | |
332 | -- Set up the data & plot |
333 | xscale = 1 |
334 | yscale = 0.0014 |
335 | yoff = 0.0185 |
336 | digmax = 5 |
337 | pl.syax(digmax, 0) |
338 | plot1() |
339 | |
340 | -- To slave |
341 | -- The pleop() ensures the eop indicator gets lit. |
342 | pl.sstrm(1) |
343 | plot4() |
344 | pl.eop() |
345 | |
346 | -- Back to master |
347 | pl.sstrm(0) |
348 | plot2() |
349 | plot3() |
350 | |
351 | -- To slave |
352 | pl.sstrm(1) |
353 | plot5() |
354 | pl.eop() |
355 | |
356 | -- Back to master to wait for user to advance |
357 | pl.sstrm(0) |
358 | pl.eop() |
359 | |
360 | -- Call plend to finish off. |
361 | pl.plend() |
362 |