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: x15.lua 9533 2009-02-16 22:18:37Z smekal $ |
2 | |
3 | Shade plot demo. |
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 | -- initialise Lua bindings for PLplot examples. |
25 | dofile("plplot_examples.lua") |
26 | |
27 | XPTS = 35 -- Data points in x |
28 | YPTS = 46 -- Data points in y |
29 | |
30 | z = {} |
31 | |
32 | -- Function prototypes |
33 | |
34 | ---------------------------------------------------------------------------- |
35 | -- cmap1_init1 |
36 | -- |
37 | -- Initializes color map 1 in HLS space. |
38 | ---------------------------------------------------------------------------- |
39 | |
40 | function cmap1_init1() |
41 | i = { 0, 0,45, 0.55, 1 } -- left boundary, just before center, |
42 | -- just after center, right boundary |
43 | h = { 260, 260, 20, 20 } -- hue -- low: blue-violet, only change as we go over vertex |
44 | -- hue -- high: red, keep fixed |
45 | l = { 0.5, 0, 0, 0.5 } -- lightness -- low, lightness -- center |
46 | -- lightness -- center, lightness -- high |
47 | s = { 1, 1, 1, 1 } -- maximum saturation |
48 | |
49 | pl.scmap1l(0, i, h, l, s) |
50 | end |
51 | |
52 | |
53 | ---------------------------------------------------------------------------- |
54 | -- cmap1_init2 |
55 | -- |
56 | -- Initializes color map 1 in HLS space. |
57 | ---------------------------------------------------------------------------- |
58 | |
59 | function cmap1_init2() |
60 | i = { 0, 0.45, 0.55, 1 } -- left boundary, just before center, |
61 | -- just after center, right boundary |
62 | h = { 260, 260, 20, 20 } -- hue -- low: blue-violet, only change as we go over vertex |
63 | -- hue -- high: red, keep fixed |
64 | l = { 0.6, 0, 0, 0.6 } -- lightness -- low, lightness -- center |
65 | -- lightness -- center, lightness -- high |
66 | s = { 1, 0.5, 0.5, 1 } -- saturation -- low, saturation -- center |
67 | -- saturation -- center, saturation -- high |
68 | |
69 | pl.scmap1l(0, i, h, l, s) |
70 | end |
71 | |
72 | |
73 | ---------------------------------------------------------------------------- |
74 | -- plot1 |
75 | -- |
76 | -- Illustrates a single shaded region. |
77 | ---------------------------------------------------------------------------- |
78 | |
79 | function plot1() |
80 | sh_cmap = 0 |
81 | |
82 | pl.adv(0) |
83 | pl.vpor(0.1, 0.9, 0.1, 0.9) |
84 | pl.wind(-1, 1, -1, 1) |
85 | |
86 | -- Plot using identity transform |
87 | shade_min = zmin + (zmax-zmin)*0.4 |
88 | shade_max = zmin + (zmax-zmin)*0.6 |
89 | sh_color = 7 |
90 | sh_width = 2 |
91 | min_color = 9 |
92 | max_color = 2 |
93 | min_width = 2 |
94 | max_width = 2 |
95 | |
96 | pl.psty(8) |
97 | pl.shade(z, -1, 1, -1, 1, shade_min, shade_max, sh_cmap, sh_color, sh_width, |
98 | min_color, min_width, max_color, max_width, 1) |
99 | |
100 | pl.col0(1) |
101 | pl.box("bcnst", 0, 0, "bcnstv", 0, 0) |
102 | pl.col0(2) |
103 | pl.lab("distance", "altitude", "Bogon flux") |
104 | end |
105 | |
106 | |
107 | ---------------------------------------------------------------------------- |
108 | -- plot2 |
109 | -- |
110 | -- Illustrates multiple adjacent shaded regions, using different fill |
111 | -- patterns for each region. |
112 | ---------------------------------------------------------------------------- |
113 | |
114 | function plot2() |
115 | sh_cmap = 0 |
116 | min_color = 0 |
117 | min_width = 0 |
118 | max_color = 0 |
119 | max_width = 0 |
120 | |
121 | inc = { {450}, {-450}, {0}, {900}, {300}, |
122 | {450,-450}, {0, 900}, {0, 450}, {450, -450}, {0, 900} } |
123 | del = { {2000}, {2000}, {2000}, {2000}, {2000}, |
124 | {2000, 2000}, {2000, 2000}, {2000, 2000}, {4000, 4000}, {4000, 2000} } |
125 | |
126 | sh_width = 2 |
127 | |
128 | pl.adv(0) |
129 | pl.vpor(0.1, 0.9, 0.1, 0.9) |
130 | pl.wind(-1, 1, -1, 1) |
131 | |
132 | -- Plot using identity transform |
133 | |
134 | for i = 1, 10 do |
135 | shade_min = zmin + (zmax - zmin) * (i-1)/10 |
136 | shade_max = zmin + (zmax - zmin) * i/10 |
137 | sh_color = i+5 |
138 | pl.pat(inc[i], del[i]) |
139 | |
140 | pl.shade(z, -1, 1, -1, 1, shade_min, shade_max, sh_cmap, sh_color, sh_width, |
141 | min_color, min_width, max_color, max_width, 1) |
142 | end |
143 | |
144 | pl.col0(1) |
145 | pl.box("bcnst", 0, 0, "bcnstv", 0, 0) |
146 | pl.col0(2) |
147 | pl.lab("distance", "altitude", "Bogon flux") |
148 | end |
149 | |
150 | |
151 | ---------------------------------------------------------------------------- |
152 | -- plot3 |
153 | -- |
154 | -- Illustrates shaded regions in 3d, using a different fill pattern for |
155 | -- each region. |
156 | ---------------------------------------------------------------------------- |
157 | |
158 | function plot3() |
159 | xx = { {-1, 1, 1, -1, -1}, {-1, 1, 1, -1, -1} } |
160 | yy = { {1, 1, 0, 0, 1}, {-1, -1, 0, 0, -1} } |
161 | zz = { {0, 0, 1, 1, 0}, {0, 0, 1, 1, 0} } |
162 | |
163 | pl.adv(0) |
164 | pl.vpor(0.1, 0.9, 0.1, 0.9) |
165 | pl.wind(-1, 1, -1, 1.) |
166 | pl.w3d(1, 1, 1, -1, 1, -1, 1, 0, 1.5, 30, -40) |
167 | |
168 | -- Plot using identity transform |
169 | pl.col0(1) |
170 | pl.box3("bntu", "X", 0, 0, "bntu", "Y", 0, 0, "bcdfntu", "Z", 0.5, 0) |
171 | pl.col0(2) |
172 | pl.lab("","","3-d polygon filling") |
173 | |
174 | pl.col0(3) |
175 | pl.psty(1) |
176 | pl.line3(xx[1], yy[1], zz[1]) |
177 | pl.fill3(xx[1], yy[1], zz[1]) |
178 | pl.psty(2) |
179 | pl.line3(xx[2], yy[2], zz[2]) |
180 | pl.fill3(xx[2], yy[2], zz[2]) |
181 | end |
182 | |
183 | |
184 | ---------------------------------------------------------------------------- |
185 | -- f2mnmx |
186 | -- |
187 | -- Returns min & max of input 2d array. |
188 | ---------------------------------------------------------------------------- |
189 | |
190 | function f2mnmx(f, nx, ny) |
191 | fmax = f[1][1] |
192 | fmin = fmax |
193 | |
194 | for i=1, nx do |
195 | for j=1, ny do |
196 | fmax = math.max(fmax, f[i][j]) |
197 | fmin = math.min(fmin, f[i][j]) |
198 | end |
199 | end |
200 | |
201 | return fmin, fmax |
202 | end |
203 | |
204 | ---------------------------------------------------------------------------- |
205 | -- main |
206 | -- |
207 | -- Does a variety of shade plots. |
208 | ---------------------------------------------------------------------------- |
209 | |
210 | -- Parse and process command line arguments |
211 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
212 | |
213 | -- Set up color map 1 |
214 | cmap1_init2() |
215 | |
216 | -- Initialize plplot |
217 | pl.init() |
218 | |
219 | -- Set up data array |
220 | for i=1, XPTS do |
221 | xx = ((i-1) - math.floor(XPTS/2))/math.floor(XPTS/2) |
222 | z[i] = {} |
223 | for j = 1, YPTS do |
224 | yy = ((j-1) - math.floor(YPTS/2))/math.floor(YPTS/2) - 1 |
225 | z[i][j] = xx^2 - yy^2 + (xx - yy)/(xx^2+yy^2 + 0.1) |
226 | end |
227 | end |
228 | zmin, zmax = f2mnmx(z, XPTS, YPTS) |
229 | |
230 | plot1() |
231 | plot2() |
232 | plot3() |
233 | |
234 | pl.plend() |
235 |