Root/nanonote-files/example-files/data/Examples/lua-plplot-examples/x25.lua

1--[[ $Id: x25.lua 10668 2009-12-02 08:38:49Z airwin $
2
3    Filling and clipping polygons.
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.
25dofile("plplot_examples.lua")
26
27--------------------------------------------------------------------------
28-- main
29--
30-- Test program for filling polygons and proper clipping
31--------------------------------------------------------------------------
32
33xextreme = {}
34yextreme ={}
35x0 = {}
36y0 = {}
37
38-- Parse and process command line arguments
39pl.parseopts(arg, pl.PL_PARSE_FULL)
40
41-- Initialize plplot
42pl.ssub(3, 3)
43pl.init()
44
45xextreme = { { -120, 120 }, { -120, 120 }, { -120, 120 }, { -80, 80 }, { -220, -120 },
46             { -20, 20 }, { -20, 20 }, { -80, 80 }, { 20, 120 } }
47
48yextreme = { { -120, 120 }, { 20, 120 }, { -20, 120 }, { -20, 120 }, { -120, 120 },
49             { -120, 120 }, { -20, 20 }, { -80, 80 }, { -120, 120 } }
50             
51for k = 1, 2 do
52for j = 1, 4 do
53  if j==1 then
54    -- Polygon 1: a diamond
55    x0 = { 0, -100, 0, 100 }
56    y0 = { -100, 0, 100, 0}
57  end
58  if j==2 then
59    -- Polygon 1: a diamond - reverse direction
60    x0 = { 100, 0, -100, 0 }
61    y0 = { 0, 100, 0, -100}
62  end
63  if j==3 then
64    -- Polygon 2: a square with punctures
65    x0 = { -100, -100, 80, -100, -100, -80, 0, 80, 100, 100 }
66    y0 = { -100, -80, 0, 80, 100, 100, 80, 100, 100, -100}
67  end
68  if j==4 then
69    -- Polygon 2: a square with punctures - reversed direction
70    x0 = { 100, 100, 80, 0, -80, -100, -100, 80, -100, -100 }
71    y0 = { -100, 100, 100, 80, 100, 100, 80, 0, -80, -100}
72  end
73
74  for i = 1, 9 do
75    pl.adv(0)
76    pl.vsta()
77    pl.wind(xextreme[i][1], xextreme[i][2], yextreme[i][1], yextreme[i][2])
78
79    pl.col0(2)
80    pl.box("bc", 1, 0, "bcnv", 10, 0)
81    pl.col0(1)
82    pl.psty(0)
83    if k==1 then
84      pl.fill(x0, y0)
85    else
86      pl.gradient(x0, y0, 45.)
87    end
88    pl.col0(2)
89    pl.lsty(1)
90    pl.line(x0, y0)
91  end
92end
93end
94
95-- Don't forget to call plend() to finish off!
96pl.plend()
97

Archive Download this file



interactive