1(*
2       Drawing mode setting and getting example.
3
4  Copyright (C) 2011  Hezekiah M. Carty
5
6  This file is part of PLplot.
7
8  PLplot is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Library General Public License as published
10  by the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PLplot is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU Library General Public License for more details.
17
18  You should have received a copy of the GNU Library General Public License
19  along with PLplot; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*)
22
23open Plplot
24
25(* Drawing modes to demonstrate *)
26let drawing_modes = [|
27  PL_DRAWMODE_DEFAULT;
28  PL_DRAWMODE_REPLACE;
29  PL_DRAWMODE_XOR;
30|]
31
32let drawing_mode_names = [|
33  "Default drawing mode";
34  "Replace destination with source";
35  "XOR drawing";
36|]
37
38let initialize_colors () =
39  plscol0 0 255 255 255;
40  plscol0 1 0 0 0;
41  plscol0 2 255 0 0;
42  plscol0a 3 0 0 255 0.3;
43  ()
44
45let draw_page mode title =
46  (* A triangle for the background *)
47  let xs = [|0.0; 1.0; 0.0|] in
48  let ys = [|0.0; 1.0; 1.0|] in
49
50  (* A circle for the foreground *)
51  let over_x = 0.5 in
52  let over_y = 0.5 in
53  let over_r = 0.4 in
54
55  plcol0 1;
56
57  (* Setup a plot window *)
58  plenv 0.0 1.0 0.0 1.0 1 0;
59
60  (* Show which mode we're using *)
61  pllab "" "" title;
62
63  (* Draw a background triangle using the default drawing mode *)
64  plcol0 2;
65  plsdrawmode PL_DRAWMODE_DEFAULT;
66  plfill xs ys;
67
68  (* Draw a circle in the given drawing mode *)
69  plcol0 3;
70  plsdrawmode mode;
71  plarc over_x over_y over_r over_r 0.0 360.0 0.0 true;
72  ()
73
74(*--------------------------------------------------------------------------
75  main
76  --------------------------------------------------------------------------*)
77
78let main =
79  (* PLplot initialization *)
80
81  (* Parse and process command line arguments *)
82  plparseopts Sys.argv [PL_PARSE_FULL];
83
84  (* Initialize PLplot *)
85  plinit ();
86
87  (* Check for drawing mode support *)
88  let mode = plgdrawmode () in
89
90  if mode = PL_DRAWMODE_UNKNOWN then begin
91    print_endline "WARNING: This driver does not support drawing mode getting/setting";
92  end
93  else begin
94    (* Setup colors *)
95    initialize_colors ();
96
97    (* Draw one page per drawing mode *)
98    Array.iteri (fun i mode -> draw_page mode drawing_mode_names.(i))
99      drawing_modes;
100  end;
101
102  (* Clean up *)
103  plend ();
104  ()
105
106