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

1--[[ $Id: x30.lua 10668 2009-12-02 08:38:49Z airwin $
2
3    Alpha color values demonstration.
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
27red = { 0, 255, 0, 0 }
28green = { 0, 0, 255, 0 }
29blue = { 0, 0, 0, 255 }
30alpha = { 1, 1, 1, 1 }
31
32px = { 0.1, 0.5, 0.5, 0.1 }
33py = { 0.1, 0.1, 0.5, 0.5 }
34
35pos = { 0, 1 }
36rcoord = { 1, 1 }
37gcoord = { 0, 0 }
38bcoord = { 0, 0 }
39acoord = { 0, 1 }
40rev = { 0, 0 }
41
42pl.parseopts (arg, pl.PL_PARSE_FULL);
43
44pl.init()
45pl.scmap0n(4)
46pl.scmap0a(red, green, blue, alpha)
47
48-- Page 1:
49--
50-- This is a series of red, green and blue rectangles overlaid
51-- on each other with gradually increasing transparency.
52
53-- Set up the window
54pl.adv(0)
55pl.vpor(0, 1, 0, 1)
56pl.wind(0, 1, 0, 1)
57pl.col0(0)
58pl.box("", 1, 0, "", 1, 0)
59
60-- Draw the boxes
61for i = 0, 8 do
62  icol = math.mod(i, 3) + 1
63
64  -- Get a color, change its transparency and
65  -- set it as the current color.
66  r, g, b, a = pl.gcol0a(icol)
67  pl.scol0a(icol, r, g, b, 1-i/9)
68  pl.col0(icol)
69
70  -- Draw the rectangle
71  pl.fill(px, py)
72
73  -- Shift the rectangles coordinates
74  for j = 1, 4 do
75    px[j] = px[j] + 0.5/9
76    py[j] = py[j] + 0.5/9
77  end
78end
79
80-- Page 2:
81
82-- This is a bunch of boxes colored red, green or blue with a single
83-- large (red) box of linearly varying transparency overlaid. The
84-- overlaid box is completely transparent at the bottom and completely
85-- opaque at the top.
86
87-- Set up the window
88pl.adv(0)
89pl.vpor(0.1, 0.9, 0.1, 0.9)
90pl.wind(0.0, 1.0, 0.0, 1.0)
91
92-- Draw the boxes. There are 25 of them drawn on a 5 x 5 grid.
93for i = 0, 4 do
94  -- Set box X position
95  px[1] = 0.05 + 0.2 * i
96  px[2] = px[1] + 0.1
97  px[3] = px[2]
98  px[4] = px[1]
99
100  -- We don't want the boxes to be transparent, so since we changed
101  -- the colors transparencies in the first example we have to change
102  -- the transparencies back to completely opaque.
103  icol = math.mod(i, 3) + 1
104  r, g, b, a = pl.gcol0a(icol)
105  pl.scol0a(icol, r, g, b, 1)
106  pl.col0(icol)
107  
108  for j = 0, 4 do
109    -- Set box y position and draw the box.
110    py[1] = 0.05 + 0.2 * j
111    py[2] = py[1]
112    py[3] = py[1] + 0.1
113    py[4] = py[3]
114    pl.fill(px, py)
115  end
116end
117
118-- Create the color map with 128 colors and use plscmap1la to initialize
119-- the color values with a linearly varying red transparency (or alpha)
120pl.scmap1n(128)
121pl.scmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev)
122
123-- Use that cmap1 to create a transparent red gradient for the whole
124-- window.
125px[1] = 0.
126px[2] = 1.
127px[3] = 1.
128px[4] = 0.
129
130py[1] = 0.
131py[2] = 0.
132py[3] = 1.
133py[4] = 1.
134
135pl.gradient(px, py, 90.)
136
137pl.plend()
138

Archive Download this file



interactive