|
| 1 | +-- $Id: $ |
| 2 | + |
| 3 | +-- Multipl.e window and color map 0 demo. |
| 4 | + |
| 5 | +-- initialise Lua bindings to pl.pl.ot |
| 6 | +if string.sub(_VERSION,1,7)=='Lua 5.0' then |
| 7 | + lib=loadlib('./plplotluac.so','luaopen_plplotluac') or loadlib('plplotluac.dll','luaopen_plplotluac') |
| 8 | + assert(lib)() |
| 9 | +else |
| 10 | + require('plplotluac') |
| 11 | +end |
| 12 | + |
| 13 | + |
| 14 | +---------------------------------------------------------------------------- |
| 15 | +-- draw_windows |
| 16 | +-- |
| 17 | +-- Draws a set of numbered boxes with colors according to cmap0 entry. |
| 18 | +---------------------------------------------------------------------------- |
| 19 | + |
| 20 | +function draw_windows(nw, cmap0_offset) |
| 21 | + pl.schr(0, 3.5) |
| 22 | + pl.font(4) |
| 23 | + |
| 24 | + for i = 0, nw-1 do |
| 25 | + pl.col0(i+cmap0_offset) |
| 26 | + pl.adv(0) |
| 27 | + vmin = 0.1 |
| 28 | + vmax = 0.9 |
| 29 | + for j = 0, 2 do |
| 30 | + pl.wid(j + 1) |
| 31 | + pl.vpor(vmin, vmax, vmin, vmax) |
| 32 | + pl.wind(0, 1, 0, 1) |
| 33 | + pl.box("bc", 0, 0, "bc", 0, 0) |
| 34 | + vmin = vmin + 0.1 |
| 35 | + vmax = vmax - 0.1 |
| 36 | + end |
| 37 | + pl.wid(1) |
| 38 | + pl.ptex(0.5, 0.5, 1, 0, 0.5, tostring(i)) |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | + |
| 43 | +---------------------------------------------------------------------------- |
| 44 | +-- demo1 |
| 45 | +-- |
| 46 | +-- Demonstrates multipl.e windows and default color map 0 palette. |
| 47 | +---------------------------------------------------------------------------- |
| 48 | + |
| 49 | +function demo1() |
| 50 | + pl.bop() |
| 51 | + |
| 52 | + -- Divide screen into 16 regions |
| 53 | + pl.ssub(4, 4) |
| 54 | + |
| 55 | + draw_windows(16, 0) |
| 56 | + |
| 57 | + pl.eop() |
| 58 | +end |
| 59 | + |
| 60 | + |
| 61 | +---------------------------------------------------------------------------- |
| 62 | +-- demo2 |
| 63 | +-- |
| 64 | +-- Demonstrates multipl.e windows, user-modified color map 0 palette, and |
| 65 | +-- HLS -> RGB translation. |
| 66 | +---------------------------------------------------------------------------- |
| 67 | + |
| 68 | +function demo2() |
| 69 | + -- Set up cmap0 |
| 70 | + -- Use 100 custom colors in addition to base 16 |
| 71 | + r = {} |
| 72 | + g = {} |
| 73 | + b = {} |
| 74 | + |
| 75 | + -- Min & max lightness values |
| 76 | + lmin = 0.15 |
| 77 | + lmax = 0.85 |
| 78 | + |
| 79 | + pl.bop() |
| 80 | + |
| 81 | + -- Divide screen into 100 regions |
| 82 | + |
| 83 | + pl.ssub(10, 10) |
| 84 | + |
| 85 | + for i = 0, 99 do |
| 86 | + -- Bounds on HLS, from pl.hlsrgb() commentary -- |
| 87 | + -- hue [0., 360.] degrees |
| 88 | + -- lightness [0., 1.] magnitude |
| 89 | + -- saturation [0., 1.] magnitude |
| 90 | + |
| 91 | + -- Vary hue uniformly from left to right |
| 92 | + h = (360/10) * math.mod(i, 10) |
| 93 | + |
| 94 | + -- Vary lightness uniformly from top to bottom, between min & max |
| 95 | + l = lmin + (lmax - lmin) * math.floor(i/10)/9 |
| 96 | + |
| 97 | + -- Use max saturation |
| 98 | + s = 1 |
| 99 | + |
| 100 | + r1, g1, b1 = pl.hlsrgb(h, l, s) |
| 101 | + |
| 102 | + -- Use 255.001 to avoid close truncation decisions in this example. |
| 103 | + r[i+1+16] = r1 * 255.001 |
| 104 | + g[i+1+16] = g1 * 255.001 |
| 105 | + b[i+1+16] = b1 * 255.001 |
| 106 | + end |
| 107 | + |
| 108 | + -- Load default cmap0 colors into our custom set |
| 109 | + for i = 0, 15 do |
| 110 | + r[i+1], g[i+1], b[i+1] = pl.gcol0(i) |
| 111 | + end |
| 112 | + |
| 113 | + -- Now set cmap0 all at once (faster, since fewer driver calls) |
| 114 | + pl.scmap0(r, g, b) |
| 115 | + |
| 116 | + draw_windows(100, 16) |
| 117 | + |
| 118 | + pl.eop() |
| 119 | +end |
| 120 | + |
| 121 | + |
| 122 | +---------------------------------------------------------------------------- |
| 123 | +-- main |
| 124 | +-- |
| 125 | +-- Demonstrates multipl.e windows and color map 0 palette, both default and |
| 126 | +-- user-modified. |
| 127 | +---------------------------------------------------------------------------- |
| 128 | + |
| 129 | +-- Parse and process command line arguments |
| 130 | +pl.parseopts(arg, pl.PL_PARSE_FULL) |
| 131 | + |
| 132 | +-- Initialize pl.pl.ot |
| 133 | +pl.init() |
| 134 | + |
| 135 | +-- Run demos |
| 136 | +demo1() |
| 137 | +demo2() |
| 138 | + |
| 139 | +pl.plend() |
0 commit comments