OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
Source at commit a08dac6 created 13 years 1 month ago. By Xiangfu Liu, nanonote-example-files, install to data, prepare for add script-files | |
---|---|
1 | --[[ $Id: x17.lua 9526 2009-02-13 22:06:13Z smekal $ |
2 | |
3 | Plots a simple stripchart with four pens. |
4 | |
5 | Copyright (C) 2008 Werner Smekal |
6 | |
7 | This file is part of PLplot. |
8 | |
9 | PLplot is free software you can redistribute it and/or modify |
10 | it under the terms of the GNU General Library Public License as published |
11 | by the Free Software Foundation either version 2 of the License, or |
12 | (at your option) any later version. |
13 | |
14 | PLplot is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU Library General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Library General Public License |
20 | along with PLplot if not, write to the Free Software |
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | --]] |
23 | |
24 | |
25 | -- initialise Lua bindings for PLplot examples. |
26 | dofile("plplot_examples.lua") |
27 | |
28 | |
29 | -------------------------------------------------------------------------- |
30 | -- main |
31 | -------------------------------------------------------------------------- |
32 | |
33 | nsteps = 1000 |
34 | colline = {} |
35 | legline = {} |
36 | |
37 | -- plplot initialization |
38 | -- Parse and process command line arguments |
39 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
40 | |
41 | -- User sets up plot completely except for window and data |
42 | -- Eventually settings in place when strip chart is created will be |
43 | -- remembered so that multiple strip charts can be used simultaneously. |
44 | |
45 | -- Specify some reasonable defaults for ymin and ymax |
46 | -- The plot will grow automatically if needed (but not shrink) |
47 | ymin = -0.1 |
48 | ymax = 0.1 |
49 | |
50 | -- Specify initial tmin and tmax -- this determines length of window. |
51 | -- Also specify maximum jump in t |
52 | -- This can accomodate adaptive timesteps |
53 | tmin = 0 |
54 | tmax = 10 |
55 | tjump = 0.3 -- percentage of plot to jump |
56 | |
57 | -- Axes options same as plbox. |
58 | -- Only automatic tick generation and label placement allowed |
59 | -- Eventually I'll make this fancier |
60 | colbox = 1 |
61 | collab = 3 |
62 | styline = { 2, 3, 4, 5 } -- line style |
63 | colline = { 2, 3, 4, 5 } -- pens color |
64 | |
65 | legline= { "sum", "sin", "sin*noi", "sin+noi" } -- pens legend |
66 | |
67 | xlab = 0 -- legend position |
68 | ylab = 0.25 |
69 | |
70 | autoy = 1 -- autoscale y |
71 | acc = 1 -- don't scrip, accumulate |
72 | |
73 | -- Initialize plplot |
74 | pl.init() |
75 | |
76 | pl.adv(0) |
77 | pl.vsta() |
78 | |
79 | id1 = pl.stripc("bcnst", "bcnstv", |
80 | tmin, tmax, tjump, ymin, ymax, |
81 | xlab, ylab, |
82 | autoy, acc, |
83 | colbox, collab, |
84 | colline, styline, legline, |
85 | "t", "", "Strip chart demo") |
86 | |
87 | autoy = 0 -- autoscale y |
88 | acc = 1 -- accumulate |
89 | |
90 | -- This is to represent a loop over time |
91 | -- Let's try a random walk process |
92 | |
93 | y1 = 0 |
94 | y2 = 0 |
95 | y3 = 0 |
96 | y4 = 0 |
97 | dt = 0.1 |
98 | |
99 | for n = 0, nsteps-1 do |
100 | for i = 0, 200000 do end |
101 | t = n * dt |
102 | noise = pl.randd() - 0.5 |
103 | y1 = y1 + noise |
104 | y2 = math.sin(t*math.pi/18) |
105 | y3 = y2 * noise |
106 | y4 = y2 + noise/3 |
107 | |
108 | -- There is no need for all pens to have the same number of |
109 | -- points or beeing equally time spaced. |
110 | if math.mod(n, 2)~=0 then pl.stripa(id1, 0, t, y1) end |
111 | if math.mod(n, 3)~=0 then pl.stripa(id1, 1, t, y2) end |
112 | if math.mod(n, 4)~=0 then pl.stripa(id1, 2, t, y3) end |
113 | if math.mod(n, 5)~=0 then pl.stripa(id1, 3, t, y4) end |
114 | end |
115 | |
116 | -- Destroy strip chart and it's memory |
117 | pl.stripd(id1) |
118 | pl.plend() |
119 |