1# Copyright (C) 2008 Hazen Babcock 2# Copyright (C) 2008 Andrew Ross 3# Copyright (C) 2008-2016 Alan W. Irwin 4 5# Alpha color values demonstration. 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 Library General 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# 23from numpy import * 24 25red = array([ 0, 255, 0, 0]) 26green = array([ 0, 0, 255, 0]) 27blue = array([ 0, 0, 0, 255]) 28alpha = array([1.0, 1.0, 1.0, 1.0]) 29 30pos = array([0.0, 1.0]) 31rcoord = array([1.0, 1.0]) 32gcoord = array([0.0, 0.0]) 33bcoord = array([0.0, 0.0]) 34acoord = array([0.0, 1.0]) 35rev = array([0, 0]) 36 37def main(w): 38 39 px = array([0.1, 0.5, 0.5, 0.1]) 40 py = array([0.1, 0.1, 0.5, 0.5]) 41 42 43 w.plscmap0n (4) 44 w.plscmap0a (red, green, blue, alpha) 45 46 # 47 # Page 1: 48 # 49 # This is a series of red, green and blue rectangles overlaid 50 # on each other with gradually increasing transparency. 51 52 53 # Set up the window 54 w.pladv (0) 55 w.plvpor (0.0, 1.0, 0.0, 1.0) 56 w.plwind (0.0, 1.0, 0.0, 1.0) 57 w.plcol0 (0) 58 w.plbox ("", 1.0, 0, "", 1.0, 0) 59 60 # Draw the boxes 61 for i in range(9): 62 icol = i%3 + 1 63 64 # Get a color, change its transparency and 65 # set it as the current color. 66 rgba = w.plgcol0a (icol) 67 w.plscol0a (icol, rgba[0], rgba[1], rgba[2], 1.0 - float(i)/9.0) 68 w.plcol0 (icol) 69 70 # Draw the rectangle 71 w.plfill (px, py) 72 73 # Shift the rectangles coordinates 74 px += 0.5/9.0 75 py += 0.5/9.0 76 77 # 78 # Page 2: 79 # 80 # This is a bunch of boxes colored red, green or blue with a single 81 # large (red) box of linearly varying transparency overlaid. The 82 # overlaid box is completely transparent at the bottom and completely 83 # opaque at the top. 84 85 86 # Set up the window 87 w.pladv(0) 88 w.plvpor(0.1, 0.9, 0.1, 0.9) 89 w.plwind(0.0, 1.0, 0.0, 1.0) 90 91 # Draw the boxes. There are 25 of them drawn on a 5 x 5 grid. 92 for i in range(5): 93 # Set box X position 94 px[0] = 0.05 + 0.2 * i 95 px[1] = px[0] + 0.1 96 px[2] = px[1] 97 px[3] = px[0] 98 99 # We don't want the boxes to be transparent, so since we changed 100 # the colors transparencies in the first example we have to change 101 # the transparencies back to completely opaque. 102 icol = i%3 + 1 103 rgba = w.plgcol0a (icol) 104 w.plscol0a (icol, rgba[0], rgba[1], rgba[2], 1.0) 105 w.plcol0 (icol) 106 for j in range(5): 107 # Set box y position and draw the box. 108 py[0] = 0.05 + 0.2 * j 109 py[1] = py[0] 110 py[2] = py[0] + 0.1 111 py[3] = py[2] 112 w.plfill(px, py) 113 114 # Create the color map with 128 colors and use w.plscmap1la to initialize 115 # the color values with a linearly varying red transparency (or alpha) 116 w.plscmap1n(128) 117 w.plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev) 118 119 # Use that cmap1 to create a transparent red gradient for the whole 120 # window. 121 px[0] = 0. 122 px[1] = 1. 123 px[2] = 1. 124 px[3] = 0. 125 126 py[0] = 0. 127 py[1] = 0. 128 py[2] = 1. 129 py[3] = 1. 130 131 w.plgradient(px, py, 90.) 132 133 # Restore defaults 134 # cmap0 default color palette. 135 w.plspal0("cmap0_default.pal") 136 # cmap1 default color palette. 137 w.plspal1("cmap1_default.pal", 1) 138 139 # Must be done independently because otherwise this changes output files 140 # and destroys agreement with C examples. 141 #w.plcol0(1) 142