[Plplot-cvs] SF.net SVN: plplot:[9363] trunk/examples/lua

 [Plplot-cvs] SF.net SVN: plplot:[9363] trunk/examples/lua From: - 2009-01-21 08:11:04 ```Revision: 9363 http://plplot.svn.sourceforge.net/plplot/?rev=9363&view=rev Author: smekal Date: 2009-01-21 08:10:58 +0000 (Wed, 21 Jan 2009) Log Message: ----------- Add lua examples 3 and 4. Added Paths: ----------- trunk/examples/lua/x03.lua trunk/examples/lua/x04.lua Added: trunk/examples/lua/x03.lua =================================================================== --- trunk/examples/lua/x03.lua (rev 0) +++ trunk/examples/lua/x03.lua 2009-01-21 08:10:58 UTC (rev 9363) @@ -0,0 +1,98 @@ +-- \$Id\$ + +-- Polar plot demo. + + +-- initialise Lua bindings to pl.pl.ot +if string.sub(_VERSION,1,7)=='Lua 5.0' then + lib=loadlib('./plplotluac.so','luaopen_plplotluac') or loadlib('plplotluac.dll','luaopen_plplotluac') + assert(lib)() +else + require('plplotluac') +end + + +---------------------------------------------------------------------------- +-- main +-- +-- Generates polar plot, with 1-1 scaling. +---------------------------------------------------------------------------- + +x0 = {} +y0 = {} +x = {} +y = {} + +dtr = math.pi/180 +for i = 1, 361 do + x0[i] = math.cos(dtr * (i-1)) + y0[i] = math.sin(dtr * (i-1)) +end + +-- Parse and process command line arguments + +pl.parseopts(arg, pl.PL_PARSE_FULL) + +-- Set orientation to landscape - note not all device drivers +-- support this, in particular most interactive drivers do not +pl.sori(1) + +-- Initialize plplot +pl.init() + +-- Set up viewport and window, but do not draw box +pl.env(-1.3, 1.3, -1.3, 1.3, 1, -2) +for i = 1, 10 do + for j = 1, 361 do + x[j] = 0.1 * i * x0[j] + y[j] = 0.1 * i * y0[j] + end + + -- Draw circles for polar grid + pl.line(x, y) +end + + +pl.col0(2) +for i=0, 11 do + theta = 30 * i + dx = math.cos(dtr * theta) + dy = math.sin(dtr * theta) + + -- Draw radial spokes for polar grid + + pl.join(0, 0, dx, dy) + + -- Write labels for angle + if theta < 9.99 then + offset = 0.45 + else + if theta < 99.9 then + offset = 0.30 + else + offset = 0.15 + end + end + + -- Slightly off zero to avoid floating point logic flips at 90 and 270 deg. + if dx >= -0.00001 then + pl.ptex(dx, dy, dx, dy, -offset, tostring(math.floor(theta))) + else + pl.ptex(dx, dy, -dx, -dy, 1.+offset, tostring(math.floor(theta))) + end +end + +-- Draw the graph +for i=1, 361 do + r = math.sin(dtr * (5 * i-1)) + x[i] = x0[i] * r + y[i] = y0[i] * r +end +pl.col0(3) +pl.line(x, y) + +pl.col0(4) +pl.mtex("t", 2, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh") + +-- Close the plot at end +pl.plend() Property changes on: trunk/examples/lua/x03.lua ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/examples/lua/x04.lua =================================================================== --- trunk/examples/lua/x04.lua (rev 0) +++ trunk/examples/lua/x04.lua 2009-01-21 08:10:58 UTC (rev 9363) @@ -0,0 +1,93 @@ +-- \$Id\$ + +-- Log plot demo. + + +-- initialise Lua bindings to pl.pl.ot +if string.sub(_VERSION,1,7)=='Lua 5.0' then + lib=loadlib('./plplotluac.so','luaopen_plplotluac') or loadlib('plplotluac.dll','luaopen_plplotluac') + assert(lib)() +else + require('plplotluac') +end + + +---------------------------------------------------------------------------- +-- plot1 +-- +-- Log-linear plot. +---------------------------------------------------------------------------- + +function plot1(type) + freql = {} + ampl = {} + phase = {} + + pl.adv(0) + + -- Set up data for log plot + f0 = 1 + for i=1, 101 do + freql[i] = -2 + (i-1) / 20 + freq = 10^freql[i] + ampl[i] = 20 * math.log10(1 / math.sqrt(1 + (freq / f0)^2)) + phase[i] = -(180 / math.pi) * math.atan(freq / f0) + end + + pl.vpor(0.15, 0.85, 0.1, 0.9) + pl.wind(-2, 3, -80, 0) + + -- Try different axis and labelling styles. + pl.col0(1) + if type == 0 then + pl.box("bclnst", 0, 0, "bnstv", 0, 0) + end + + if type == 1 then + pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0) + end + + -- Plot ampl vs freq + pl.col0(2) + pl.line(freql, ampl) + pl.col0(1) + pl.ptex(1.6, -30, 1, -20, 0.5, "-20 dB/decade") + + -- Put labels on + pl.col0(1) + pl.mtex("b", 3.2, 0.5, 0.5, "Frequency") + pl.mtex("t", 2, 0.5, 0.5, "Single Pole Low-Pass Filter") + pl.col0(2) + pl.mtex("l", 5, 0.5, 0.5, "Amplitude (dB)") + + -- For the gridless case, put phase vs freq on same plot + if type == 0 then + pl.col0(1) + pl.wind(-2, 3, -100, 0) + pl.box("", 0, 0, "cmstv", 30, 3) + pl.col0(3) + pl.line(freql, phase) + pl.col0(3) + pl.mtex("r", 5, 0.5, 0.5, "Phase shift (degrees)") + end +end + + +---------------------------------------------------------------------------- +-- main +-- +-- Illustration of logarithmic axes, and redefinition of window. +---------------------------------------------------------------------------- + +-- Parse and process command line arguments +pl.parseopts(arg, pl.PL_PARSE_FULL) + +-- Initialize plplot +pl.init() +pl.font(2) + +-- Make log plots using two different styles. +plot1(0) +plot1(1) + +pl.plend() Property changes on: trunk/examples/lua/x04.lua ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```