OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ $Id: x02.lua 9414 2009-01-29 22:48:54Z airwin $ |
| 2 | |
| 3 | Multiple window and color map 0 demo. |
| 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 | ---------------------------------------------------------------------------- |
| 28 | -- draw_windows |
| 29 | -- |
| 30 | -- Draws a set of numbered boxes with colors according to cmap0 entry. |
| 31 | ---------------------------------------------------------------------------- |
| 32 | |
| 33 | function draw_windows(nw, cmap0_offset) |
| 34 | pl.schr(0, 3.5) |
| 35 | pl.font(4) |
| 36 | |
| 37 | for i = 0, nw-1 do |
| 38 | pl.col0(i+cmap0_offset) |
| 39 | pl.adv(0) |
| 40 | vmin = 0.1 |
| 41 | vmax = 0.9 |
| 42 | for j = 0, 2 do |
| 43 | pl.wid(j + 1) |
| 44 | pl.vpor(vmin, vmax, vmin, vmax) |
| 45 | pl.wind(0, 1, 0, 1) |
| 46 | pl.box("bc", 0, 0, "bc", 0, 0) |
| 47 | vmin = vmin + 0.1 |
| 48 | vmax = vmax - 0.1 |
| 49 | end |
| 50 | pl.wid(1) |
| 51 | pl.ptex(0.5, 0.5, 1, 0, 0.5, tostring(i)) |
| 52 | end |
| 53 | end |
| 54 | |
| 55 | |
| 56 | ---------------------------------------------------------------------------- |
| 57 | -- demo1 |
| 58 | -- |
| 59 | -- Demonstrates multipl.e windows and default color map 0 palette. |
| 60 | ---------------------------------------------------------------------------- |
| 61 | |
| 62 | function demo1() |
| 63 | pl.bop() |
| 64 | |
| 65 | -- Divide screen into 16 regions |
| 66 | pl.ssub(4, 4) |
| 67 | |
| 68 | draw_windows(16, 0) |
| 69 | |
| 70 | pl.eop() |
| 71 | end |
| 72 | |
| 73 | |
| 74 | ---------------------------------------------------------------------------- |
| 75 | -- demo2 |
| 76 | -- |
| 77 | -- Demonstrates multipl.e windows, user-modified color map 0 palette, and |
| 78 | -- HLS -> RGB translation. |
| 79 | ---------------------------------------------------------------------------- |
| 80 | |
| 81 | function demo2() |
| 82 | -- Set up cmap0 |
| 83 | -- Use 100 custom colors in addition to base 16 |
| 84 | r = {} |
| 85 | g = {} |
| 86 | b = {} |
| 87 | |
| 88 | -- Min & max lightness values |
| 89 | lmin = 0.15 |
| 90 | lmax = 0.85 |
| 91 | |
| 92 | pl.bop() |
| 93 | |
| 94 | -- Divide screen into 100 regions |
| 95 | |
| 96 | pl.ssub(10, 10) |
| 97 | |
| 98 | for i = 0, 99 do |
| 99 | -- Bounds on HLS, from pl.hlsrgb() commentary -- |
| 100 | -- hue [0., 360.] degrees |
| 101 | -- lightness [0., 1.] magnitude |
| 102 | -- saturation [0., 1.] magnitude |
| 103 | |
| 104 | -- Vary hue uniformly from left to right |
| 105 | h = (360/10) * math.mod(i, 10) |
| 106 | |
| 107 | -- Vary lightness uniformly from top to bottom, between min & max |
| 108 | l = lmin + (lmax - lmin) * math.floor(i/10)/9 |
| 109 | |
| 110 | -- Use max saturation |
| 111 | s = 1 |
| 112 | |
| 113 | r1, g1, b1 = pl.hlsrgb(h, l, s) |
| 114 | |
| 115 | -- Use 255.001 to avoid close truncation decisions in this example. |
| 116 | r[i+1+16] = r1 * 255.001 |
| 117 | g[i+1+16] = g1 * 255.001 |
| 118 | b[i+1+16] = b1 * 255.001 |
| 119 | end |
| 120 | |
| 121 | -- Load default cmap0 colors into our custom set |
| 122 | for i = 0, 15 do |
| 123 | r[i+1], g[i+1], b[i+1] = pl.gcol0(i) |
| 124 | end |
| 125 | |
| 126 | -- Now set cmap0 all at once (faster, since fewer driver calls) |
| 127 | pl.scmap0(r, g, b) |
| 128 | |
| 129 | draw_windows(100, 16) |
| 130 | |
| 131 | pl.eop() |
| 132 | end |
| 133 | |
| 134 | |
| 135 | ---------------------------------------------------------------------------- |
| 136 | -- main |
| 137 | -- |
| 138 | -- Demonstrates multipl.e windows and color map 0 palette, both default and |
| 139 | -- user-modified. |
| 140 | ---------------------------------------------------------------------------- |
| 141 | |
| 142 | -- Parse and process command line arguments |
| 143 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
| 144 | |
| 145 | -- Initialize pl.pl.ot |
| 146 | pl.init() |
| 147 | |
| 148 | -- Run demos |
| 149 | demo1() |
| 150 | demo2() |
| 151 | |
| 152 | pl.plend() |
| 153 |
