Skip to content

Commit 0e121ca

Browse files
author
Werner Smekal
committed
Added new (working) example x02.lua.
pl.parseopt() is now supported. All commands are now in the "pl" namespace by default and the "pl" is ripped off from the default names, so e.g. pllab() in Lua is pl.lab(), except end, which is still called via pl.plend() svn path=/trunk/; revision=9351
1 parent 9b7041e commit 0e121ca

9 files changed

Lines changed: 242 additions & 111 deletions

File tree

examples/lua/x02.lua

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
-- $Id: $
2+
3+
-- Multipl.e window and color map 0 demo.
4+
5+
-- initialise Lua bindings to pl.pl.ot
6+
if string.sub(_VERSION,1,7)=='Lua 5.0' then
7+
lib=loadlib('./plplotluac.so','luaopen_plplotluac') or loadlib('plplotluac.dll','luaopen_plplotluac')
8+
assert(lib)()
9+
else
10+
require('plplotluac')
11+
end
12+
13+
14+
----------------------------------------------------------------------------
15+
-- draw_windows
16+
--
17+
-- Draws a set of numbered boxes with colors according to cmap0 entry.
18+
----------------------------------------------------------------------------
19+
20+
function draw_windows(nw, cmap0_offset)
21+
pl.schr(0, 3.5)
22+
pl.font(4)
23+
24+
for i = 0, nw-1 do
25+
pl.col0(i+cmap0_offset)
26+
pl.adv(0)
27+
vmin = 0.1
28+
vmax = 0.9
29+
for j = 0, 2 do
30+
pl.wid(j + 1)
31+
pl.vpor(vmin, vmax, vmin, vmax)
32+
pl.wind(0, 1, 0, 1)
33+
pl.box("bc", 0, 0, "bc", 0, 0)
34+
vmin = vmin + 0.1
35+
vmax = vmax - 0.1
36+
end
37+
pl.wid(1)
38+
pl.ptex(0.5, 0.5, 1, 0, 0.5, tostring(i))
39+
end
40+
end
41+
42+
43+
----------------------------------------------------------------------------
44+
-- demo1
45+
--
46+
-- Demonstrates multipl.e windows and default color map 0 palette.
47+
----------------------------------------------------------------------------
48+
49+
function demo1()
50+
pl.bop()
51+
52+
-- Divide screen into 16 regions
53+
pl.ssub(4, 4)
54+
55+
draw_windows(16, 0)
56+
57+
pl.eop()
58+
end
59+
60+
61+
----------------------------------------------------------------------------
62+
-- demo2
63+
--
64+
-- Demonstrates multipl.e windows, user-modified color map 0 palette, and
65+
-- HLS -> RGB translation.
66+
----------------------------------------------------------------------------
67+
68+
function demo2()
69+
-- Set up cmap0
70+
-- Use 100 custom colors in addition to base 16
71+
r = {}
72+
g = {}
73+
b = {}
74+
75+
-- Min & max lightness values
76+
lmin = 0.15
77+
lmax = 0.85
78+
79+
pl.bop()
80+
81+
-- Divide screen into 100 regions
82+
83+
pl.ssub(10, 10)
84+
85+
for i = 0, 99 do
86+
-- Bounds on HLS, from pl.hlsrgb() commentary --
87+
-- hue [0., 360.] degrees
88+
-- lightness [0., 1.] magnitude
89+
-- saturation [0., 1.] magnitude
90+
91+
-- Vary hue uniformly from left to right
92+
h = (360/10) * math.mod(i, 10)
93+
94+
-- Vary lightness uniformly from top to bottom, between min & max
95+
l = lmin + (lmax - lmin) * math.floor(i/10)/9
96+
97+
-- Use max saturation
98+
s = 1
99+
100+
r1, g1, b1 = pl.hlsrgb(h, l, s)
101+
102+
-- Use 255.001 to avoid close truncation decisions in this example.
103+
r[i+1+16] = r1 * 255.001
104+
g[i+1+16] = g1 * 255.001
105+
b[i+1+16] = b1 * 255.001
106+
end
107+
108+
-- Load default cmap0 colors into our custom set
109+
for i = 0, 15 do
110+
r[i+1], g[i+1], b[i+1] = pl.gcol0(i)
111+
end
112+
113+
-- Now set cmap0 all at once (faster, since fewer driver calls)
114+
pl.scmap0(r, g, b)
115+
116+
draw_windows(100, 16)
117+
118+
pl.eop()
119+
end
120+
121+
122+
----------------------------------------------------------------------------
123+
-- main
124+
--
125+
-- Demonstrates multipl.e windows and color map 0 palette, both default and
126+
-- user-modified.
127+
----------------------------------------------------------------------------
128+
129+
-- Parse and process command line arguments
130+
pl.parseopts(arg, pl.PL_PARSE_FULL)
131+
132+
-- Initialize pl.pl.ot
133+
pl.init()
134+
135+
-- Run demos
136+
demo1()
137+
demo2()
138+
139+
pl.plend()

examples/lua/x05.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
99
else
1010
require('plplotluac')
1111
end
12-
pl=plplotluac
1312

1413
--------------------------------------------------------------------------
1514
-- main
@@ -21,21 +20,21 @@ NPTS=2047
2120
data = {}
2221

2322
-- Parse and process command line arguments
24-
-- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
23+
pl.parseopts(arg, pl.PL_PARSE_FULL);
2524

2625
-- Initialize plplot
27-
pl.plinit()
26+
pl.init()
2827

2928
-- Fill up data points
3029
delta = 2.0*math.pi/NPTS
3130
for i=1, NPTS do
3231
data[i] = math.sin((i-1)*delta)
3332
end
3433

35-
pl.plcol0(1)
36-
pl.plhist(data, -1.1, 1.1, 44, 0)
37-
pl.plcol0(2)
38-
pl.pllab("#frValue", "#frFrequency",
34+
pl.col0(1)
35+
pl.hist(data, -1.1, 1.1, 44, 0)
36+
pl.col0(2)
37+
pl.lab("#frValue", "#frFrequency",
3938
"#frPLplot Example 5 - Probability function of Oscillator")
4039

4140
pl.plend()

examples/lua/x10.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
99
else
1010
require('plplotluac')
1111
end
12-
pl=plplotluac
1312

1413
----------------------------------------------------------------------------
1514
-- main
@@ -18,18 +17,18 @@ pl=plplotluac
1817
----------------------------------------------------------------------------
1918

2019
-- Parse and process command line arguments
21-
-- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
20+
pl.parseopts(arg, pl.PL_PARSE_FULL);
2221

2322
-- Initialize plplot
24-
pl.plinit()
23+
pl.init()
2524

26-
pl.pladv(0)
27-
pl.plvpor(0.0, 1.0, 0.0, 1.0)
28-
pl.plwind(0.0, 1.0, 0.0, 1.0)
29-
pl.plbox("bc", 0.0, 0, "bc", 0.0, 0)
25+
pl.adv(0)
26+
pl.vpor(0.0, 1.0, 0.0, 1.0)
27+
pl.wind(0.0, 1.0, 0.0, 1.0)
28+
pl.box("bc", 0.0, 0, "bc", 0.0, 0)
3029

31-
pl.plsvpa(50.0, 150.0, 50.0, 100.0)
32-
pl.plwind(0.0, 1.0, 0.0, 1.0)
33-
pl.plbox("bc", 0.0, 0, "bc", 0.0, 0)
34-
pl.plptex(0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,50,100)")
30+
pl.svpa(50.0, 150.0, 50.0, 100.0)
31+
pl.wind(0.0, 1.0, 0.0, 1.0)
32+
pl.box("bc", 0.0, 0, "bc", 0.0, 0)
33+
pl.ptex(0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,50,100)")
3534
pl.plend()

examples/lua/x12.lua

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
99
else
1010
require('plplotluac')
1111
end
12-
pl=plplotluac
1312

14-
function plfbox(x0, y0)
13+
function pl.fbox(x0, y0)
1514
x = {}
1615
y = {}
1716

@@ -23,10 +22,10 @@ function plfbox(x0, y0)
2322
y[3] = y0;
2423
x[4] = x0 + 1.;
2524
y[4] = 0.;
26-
pl.plfill(x, y);
27-
pl.plcol0(1);
28-
pl.pllsty(1);
29-
pl.plline(x, y);
25+
pl.fill(x, y);
26+
pl.col0(1);
27+
pl.lsty(1);
28+
pl.line(x, y);
3029
end
3130

3231
--------------------------------------------------------------------------
@@ -40,17 +39,17 @@ y0 = {}
4039

4140
-- Parse and process command line arguments
4241

43-
-- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
42+
pl.parseopts(arg, pl.PL_PARSE_FULL);
4443

4544
-- Initialize plplot
46-
pl.plinit()
45+
pl.init()
4746

48-
pl.pladv(0)
49-
pl.plvsta()
50-
pl.plwind(1980.0, 1990.0, 0.0, 35.0)
51-
pl.plbox("bc", 1.0, 0, "bcnv", 10.0, 0)
52-
pl.plcol0(2)
53-
pl.pllab("Year", "Widget Sales (millions)", "#frPLplot Example 12")
47+
pl.adv(0)
48+
pl.vsta()
49+
pl.wind(1980.0, 1990.0, 0.0, 35.0)
50+
pl.box("bc", 1.0, 0, "bcnv", 10.0, 0)
51+
pl.col0(2)
52+
pl.lab("Year", "Widget Sales (millions)", "#frPLplot Example 12")
5453

5554
y0[1] = 5
5655
y0[2] = 15
@@ -64,11 +63,11 @@ y0[9] = 12
6463
y0[10] = 3
6564

6665
for i=1, 10 do
67-
pl.plcol0(i);
68-
pl.plpsty(0);
69-
plfbox((1980. + i - 1), y0[i]);
70-
pl.plptex((1980. + i - .5), (y0[i] + 1.), 1.0, 0.0, .5, tostring(y0[i]));
71-
pl.plmtex("b", 1.0, (i * .1 - .05), 0.5, tostring(1980+i-1));
66+
pl.col0(i);
67+
pl.psty(0);
68+
pl.fbox((1980. + i - 1), y0[i]);
69+
pl.ptex((1980. + i - .5), (y0[i] + 1.), 1.0, 0.0, .5, tostring(y0[i]));
70+
pl.mtex("b", 1.0, (i * .1 - .05), 0.5, tostring(1980+i-1));
7271
end
7372

7473
pl.plend();

examples/lua/x13.lua

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
99
else
1010
require('plplotluac')
1111
end
12-
pl=plplotluac
1312

1413
text = { "Maurice", "Geoffrey", "Alan",
1514
"Rafael", "Vince" }
@@ -24,19 +23,19 @@ per = { 10, 32, 12, 30, 16 }
2423

2524
-- Parse and process command line arguments
2625

27-
-- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
26+
pl.parseopts(arg, pl.PL_PARSE_FULL);
2827

2928
-- Initialize plplot
3029

31-
pl.plinit()
30+
pl.init()
3231

33-
pl.pladv(0)
32+
pl.adv(0)
3433

3534
-- Ensure window has aspect ratio of one so circle is
3635
-- plotted as a circle.
37-
pl.plvasp(1)
38-
pl.plwind(0, 10, 0, 10)
39-
pl.plcol0(2)
36+
pl.vasp(1)
37+
pl.wind(0, 10, 0, 10)
38+
pl.col0(2)
4039

4140
-- n.b. all theta quantities scaled by 2*M_PI/500 to be integers to avoid
4241
--floating point logic problems.
@@ -56,11 +55,11 @@ for i = 1, 5 do
5655
y[j] = 5 + 3 * math.sin((2*math.pi/500)*theta)
5756
j = j + 1
5857
end
59-
pl.plcol0(i)
60-
pl.plpsty(math.mod((i + 2), 8) + 1)
61-
pl.plfill(x, y)
62-
pl.plcol0(1)
63-
pl.plline(x, y)
58+
pl.col0(i)
59+
pl.psty(math.mod((i + 2), 8) + 1)
60+
pl.fill(x, y)
61+
pl.col0(1)
62+
pl.line(x, y)
6463
just = (2*math.pi/500)*(theta0 + theta1)/2
6564
dx = .25 * math.cos(just)
6665
dy = .25 * math.sin(just)
@@ -70,13 +69,13 @@ for i = 1, 5 do
7069
just = 1
7170
end
7271

73-
pl.plptex((x[(j-1) / 2] + dx), (y[(j-1) / 2] + dy), 1.0, 0.0, just, text[i]);
72+
pl.ptex((x[(j-1) / 2] + dx), (y[(j-1) / 2] + dy), 1.0, 0.0, just, text[i]);
7473
theta0 = theta1 - dthet
7574
end
7675

77-
pl.plfont(2)
78-
pl.plschr(0, 1.3)
79-
pl.plptex(5, 9, 1, 0, 0.5, "Percentage of Sales")
76+
pl.font(2)
77+
pl.schr(0, 1.3)
78+
pl.ptex(5, 9, 1, 0, 0.5, "Percentage of Sales")
8079

8180
pl.plend()
8281

0 commit comments

Comments
 (0)