1!   Alpha color values demonstration
2!
3!   Copyright (C) 2008 Hazen Babcock
4!   Copyright (C) 2008 Andrew Ross
5!   Copyright (C) 2008-2016 Alan W. Irwin
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
11!   published by the Free Software Foundation; either version 2 of the
12!   License, or (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
20!   License 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!     N.B. the pl_test_flt parameter used in this code is only
24!     provided by the plplot module to allow convenient developer
25!     testing of either kind(1.0) or kind(1.0d0) floating-point
26!     precision regardless of the floating-point precision of the
27!     PLplot C libraries.  We do not guarantee the value of this test
28!     parameter so it should not be used by users, and instead user
29!     code should replace the pl_test_flt parameter by whatever
30!     kind(1.0) or kind(1.0d0) precision is most convenient for them.
31!     For further details on floating-point precision issues please
32!     consult README_precision in this directory.
33!
34
35program x30f
36    use plplot
37
38    implicit none
39
40    integer, dimension(4) ::  red, green, blue
41    real(kind=pl_test_flt), dimension (4) :: alpha, px, py
42    real(kind=pl_test_flt), dimension (2) :: pos, rcoord, gcoord, bcoord, acoord
43    logical, dimension(1) :: rev
44
45    data red   / 0, 255, 0, 0 /
46    data green / 0, 0, 255, 0 /
47    data blue  / 0, 0, 0, 255 /
48    data alpha / 1.0_pl_test_flt, 1.0_pl_test_flt, 1.0_pl_test_flt, 1.0_pl_test_flt /
49    data px / 0.1_pl_test_flt, 0.5_pl_test_flt, 0.5_pl_test_flt, 0.1_pl_test_flt /
50    data py / 0.1_pl_test_flt, 0.1_pl_test_flt, 0.5_pl_test_flt, 0.5_pl_test_flt /
51    data pos / 0.0_pl_test_flt, 1.0_pl_test_flt /
52    data rcoord / 1.0_pl_test_flt, 1.0_pl_test_flt /
53    data gcoord / 0.0_pl_test_flt, 0.0_pl_test_flt /
54    data bcoord / 0.0_pl_test_flt, 0.0_pl_test_flt /
55    data acoord / 0.0_pl_test_flt, 1.0_pl_test_flt /
56    data rev / .false. /
57
58    integer i, j
59    integer icol, r, g, b
60    integer :: plparseopts_rc
61    real(kind=pl_test_flt) :: a
62
63    plparseopts_rc = plparseopts(PL_PARSE_FULL)
64    if(plparseopts_rc .ne. 0) stop "plparseopts error"
65
66    call plinit()
67
68    call plscmap0n(4)
69
70    call plscmap0a (red, green, blue, alpha)
71
72    !
73    ! Page 1:
74    !
75    ! This is a series of red, green and blue rectangles overlaid
76    ! on each other with gradually increasing transparency.
77    !
78
79    ! Set up the window
80    call pladv (0)
81    call plvpor (0.0_pl_test_flt, 1.0_pl_test_flt, 0.0_pl_test_flt, 1.0_pl_test_flt)
82    call plwind (0.0_pl_test_flt, 1.0_pl_test_flt, 0.0_pl_test_flt, 1.0_pl_test_flt)
83    call plcol0 (0)
84    call plbox ("", 1.0_pl_test_flt, 0, "", 1.0_pl_test_flt, 0)
85
86    ! Draw the boxes
87    do i = 1,9
88        icol = mod(i-1,3) + 1
89
90        ! Get a color, change its transparency and
91        ! set it as the current color.
92        call plgcol0a (icol, r, g, b, a)
93        call plscol0a (icol, r, g, b, 1.0_pl_test_flt - real(i-1,kind=pl_test_flt)/9.0_pl_test_flt)
94        call plcol0 (icol)
95
96        ! Draw the rectangle
97        call plfill (px, py)
98
99        ! Shift the rectangles coordinates
100        do j = 1,4
101            px(j) = px(j) + 0.5_pl_test_flt/9.0_pl_test_flt
102            py(j) = py(j) + 0.5_pl_test_flt/9.0_pl_test_flt
103        enddo
104    enddo
105    !
106    ! Page 2:
107    !
108    ! This is a bunch of boxes colored red, green or blue with a single
109    ! large (red) box of linearly varying transparency overlaid. The
110    ! overlaid box is completely transparent at the bottom and completely
111    ! opaque at the top.
112    !
113
114    ! Set up the window
115    call pladv(0)
116    call plvpor(0.1_pl_test_flt, 0.9_pl_test_flt, 0.1_pl_test_flt, 0.9_pl_test_flt)
117    call plwind(0.0_pl_test_flt, 1.0_pl_test_flt, 0.0_pl_test_flt, 1.0_pl_test_flt)
118
119    ! Draw the boxes. There are 25 of them drawn on a 5 x 5 grid.
120    do i = 1,5
121        ! Set box X position
122        px(1) = 0.05_pl_test_flt + 0.2_pl_test_flt * real(i-1,kind=pl_test_flt)
123        px(2) = px(1) + 0.1_pl_test_flt
124        px(3) = px(2)
125        px(4) = px(1)
126
127        ! We don't want the boxes to be transparent, so since we changed
128        ! the colors transparencies in the first example we have to change
129        ! the transparencies back to completely opaque.
130        icol = mod(i-1,3) + 1
131        call plgcol0a (icol, r, g, b, a)
132        call plscol0a (icol, r, g, b, 1.0_pl_test_flt)
133        call plcol0 (icol)
134        do j = 1, 5
135            ! Set box y position and draw the box.
136            py(1) = 0.05_pl_test_flt + 0.2_pl_test_flt * real(j-1,kind=pl_test_flt)
137            py(2) = py(1)
138            py(3) = py(1) + 0.1_pl_test_flt
139            py(4) = py(3)
140            call plfill(px, py)
141        enddo
142    enddo
143
144    ! Create the color map with 128 colors and call plscmap1la to initialize
145    ! the color values with a linearly varying red transparency (or alpha)
146    call plscmap1n(128)
147    call plscmap1la(.true., pos, rcoord, gcoord, bcoord, acoord, rev)
148
149    ! Use that cmap1 to create a transparent red gradient for the whole
150    ! window.
151    px(1) = 0._pl_test_flt
152    px(2) = 1._pl_test_flt
153    px(3) = 1._pl_test_flt
154    px(4) = 0._pl_test_flt
155
156    py(1) = 0._pl_test_flt
157    py(2) = 0._pl_test_flt
158    py(3) = 1._pl_test_flt
159    py(4) = 1._pl_test_flt
160
161    call plgradient( px, py, 90._pl_test_flt )
162    call plend()
163
164end program x30f
165
166