From: <hez...@us...> - 2010-01-31 20:07:09
|
Revision: 10788 http://plplot.svn.sourceforge.net/plplot/?rev=10788&view=rev Author: hezekiahcarty Date: 2010-01-31 20:07:03 +0000 (Sun, 31 Jan 2010) Log Message: ----------- Add plgradient support to OCaml examples Modified Paths: -------------- trunk/examples/ocaml/x25.ml trunk/examples/ocaml/x30.ml Modified: trunk/examples/ocaml/x25.ml =================================================================== --- trunk/examples/ocaml/x25.ml 2010-01-31 20:05:55 UTC (rev 10787) +++ trunk/examples/ocaml/x25.ml 2010-01-31 20:07:03 UTC (rev 10788) @@ -1,5 +1,27 @@ (* $Id$ Filling and clipping polygons. + + Copyright (C) 2008, 2010 Hezekiah M. Carty + + + This file is part of PLplot. + + PLplot is free software; you can redistribute it and/or modify + it under the terms of the GNU General Library Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PLplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with PLplot; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + This example will only really be interesting when used with devices that + support or alpha (or transparency) values, such as the cairo device family. *) open Plplot @@ -43,44 +65,51 @@ |] in - for j = 0 to 3 do - let x, y = - match j with - 0 -> - (* Polygon 1: a diamond *) - [|0.0; -100.0; 0.0; 100.0|], - [|-100.0; 0.0; 100.0; 0.0|] - | 1 -> - (* Polygon 1: a diamond - reverse direction *) - [|100.0; 0.0; -100.0; 0.0;|], - [|0.0; 100.0; 0.0; -100.0|] - | 2 -> - (* Polygon 2: a square with punctures *) - [|-100.0; -100.0; 80.0; -100.0; -100.0; - -80.0; 0.0; 80.0; 100.0; 100.0|], - [|-100.0; -80.0; 0.0; 80.0; 100.0; - 100.0; 80.0; 100.0; 100.0; -100.0|] - | 3 -> - (* Polygon 2: a square with punctures - reversed direction *) - [|100.0; 100.0; 80.0; 0.0; -80.0; - -100.0; -100.0; 80.0; -100.0; -100.0|], - [|-100.0; 100.0; 100.0; 80.0; 100.0; - 100.0; 80.0; 0.0; -80.0; -100.0|] - | _ -> raise (Failure "only 4 shapes are available") - in + for k = 0 to 1 do + for j = 0 to 3 do + let x, y = + match j with + 0 -> + (* Polygon 1: a diamond *) + [|0.0; -100.0; 0.0; 100.0|], + [|-100.0; 0.0; 100.0; 0.0|] + | 1 -> + (* Polygon 1: a diamond - reverse direction *) + [|100.0; 0.0; -100.0; 0.0;|], + [|0.0; 100.0; 0.0; -100.0|] + | 2 -> + (* Polygon 2: a square with punctures *) + [|-100.0; -100.0; 80.0; -100.0; -100.0; + -80.0; 0.0; 80.0; 100.0; 100.0|], + [|-100.0; -80.0; 0.0; 80.0; 100.0; + 100.0; 80.0; 100.0; 100.0; -100.0|] + | 3 -> + (* Polygon 2: a square with punctures - reversed direction *) + [|100.0; 100.0; 80.0; 0.0; -80.0; + -100.0; -100.0; 80.0; -100.0; -100.0|], + [|-100.0; 100.0; 100.0; 80.0; 100.0; + 100.0; 80.0; 0.0; -80.0; -100.0|] + | _ -> raise (Failure "only 4 shapes are available") + in - for i = 0 to 8 do - pladv 0; - plvsta (); - plwind xextreme.(i).(0) xextreme.(i).(1) yextreme.(i).(0) yextreme.(i).(1); - plcol0 2; - plbox "bc" 1.0 0 "bcnv" 10.0 0; - plcol0 1; - plpsty 0; - plfill x y; - plcol0 2; - pllsty 1; - plline x y; + for i = 0 to 8 do + pladv 0; + plvsta (); + plwind xextreme.(i).(0) xextreme.(i).(1) yextreme.(i).(0) yextreme.(i).(1); + plcol0 2; + plbox "bc" 1.0 0 "bcnv" 10.0 0; + plcol0 1; + plpsty 0; + if k = 0 then ( + plfill x y + ) + else ( + plgradient x y 45.0 + ); + plcol0 2; + pllsty 1; + plline x y; + done done done; Modified: trunk/examples/ocaml/x30.ml =================================================================== --- trunk/examples/ocaml/x30.ml 2010-01-31 20:05:55 UTC (rev 10787) +++ trunk/examples/ocaml/x30.ml 2010-01-31 20:07:03 UTC (rev 10788) @@ -2,7 +2,7 @@ Alpha color values demonstration. Copyright (C) 2008 Hazen Babcock - Copyright (C) 2008 Hezekiah M. Carty + Copyright (C) 2008, 2010 Hezekiah M. Carty This file is part of PLplot. @@ -114,31 +114,16 @@ done done; - (* The overlaid box is drawn using plshades with a color map that is - the same color but has a linearly varying transparency. *) + let px = [|0.0; 1.0; 1.0; 0.0|] in + let py = [|0.0; 0.0; 1.0; 1.0|] in (* Create the color map with 128 colors and use plscmap1la to initialize the color values with a linear varying transparency (or alpha) *) plscmap1n 128; plscmap1la true pos rcoord gcoord bcoord acoord (Some rev); - (* Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will - used for the shade plot. plshades will use linear interpolation to - calculate the z values of all the intermediate points in this array. *) - let z = - [| - [|0.0; 1.0|]; - [|0.0; 1.0|]; - |] - in + plgradient px py 90.0; - (* Set the color levels array. These levels are also between 0.0 and 1.0 *) - let clevel = Array.init 101 (fun i -> 0.01 *. float_of_int i) in - - (* Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate - ranges such that it fills the entire plotting area. *) - plshades z 0.0 1.0 0.0 1.0 clevel 0 (-1) 2 true; - plend (); () This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |