OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 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. |
| 25 | dofile("plplot_examples.lua") |
| 26 | |
| 27 | red = { 0, 255, 0, 0 } |
| 28 | green = { 0, 0, 255, 0 } |
| 29 | blue = { 0, 0, 0, 255 } |
| 30 | alpha = { 1, 1, 1, 1 } |
| 31 | |
| 32 | px = { 0.1, 0.5, 0.5, 0.1 } |
| 33 | py = { 0.1, 0.1, 0.5, 0.5 } |
| 34 | |
| 35 | pos = { 0, 1 } |
| 36 | rcoord = { 1, 1 } |
| 37 | gcoord = { 0, 0 } |
| 38 | bcoord = { 0, 0 } |
| 39 | acoord = { 0, 1 } |
| 40 | rev = { 0, 0 } |
| 41 | |
| 42 | pl.parseopts (arg, pl.PL_PARSE_FULL); |
| 43 | |
| 44 | pl.init() |
| 45 | pl.scmap0n(4) |
| 46 | pl.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 |
| 54 | pl.adv(0) |
| 55 | pl.vpor(0, 1, 0, 1) |
| 56 | pl.wind(0, 1, 0, 1) |
| 57 | pl.col0(0) |
| 58 | pl.box("", 1, 0, "", 1, 0) |
| 59 | |
| 60 | -- Draw the boxes |
| 61 | for 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 |
| 78 | end |
| 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 |
| 88 | pl.adv(0) |
| 89 | pl.vpor(0.1, 0.9, 0.1, 0.9) |
| 90 | pl.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. |
| 93 | for 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 |
| 116 | end |
| 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) |
| 120 | pl.scmap1n(128) |
| 121 | pl.scmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev) |
| 122 | |
| 123 | -- Use that cmap1 to create a transparent red gradient for the whole |
| 124 | -- window. |
| 125 | px[1] = 0. |
| 126 | px[2] = 1. |
| 127 | px[3] = 1. |
| 128 | px[4] = 0. |
| 129 | |
| 130 | py[1] = 0. |
| 131 | py[2] = 0. |
| 132 | py[3] = 1. |
| 133 | py[4] = 1. |
| 134 | |
| 135 | pl.gradient(px, py, 90.) |
| 136 | |
| 137 | pl.plend() |
| 138 |
