1
by Joachim Erfle
initial commit |
1 |
-- $Id: xthick02a.adb 11680 2011-03-27 17:57:51Z airwin $
|
2 |
||
3 |
-- Multiple window and color map 0 demo.
|
|
4 |
||
5 |
-- Copyright (C) 2007 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 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 |
||
23 |
with
|
|
24 |
Ada.Numerics, |
|
25 |
Ada.Numerics.Long_Elementary_Functions, |
|
26 |
Ada.Strings, |
|
27 |
Ada.Strings.Fixed, |
|
28 |
PLplot_Auxiliary, |
|
29 |
PLplot; |
|
30 |
||
31 |
use
|
|
32 |
Ada.Numerics, |
|
33 |
Ada.Numerics.Long_Elementary_Functions, |
|
34 |
Ada.Strings, |
|
35 |
Ada.Strings.Fixed, |
|
36 |
PLplot_Auxiliary, |
|
37 |
PLplot; |
|
38 |
||
39 |
||
40 |
||
41 |
------------------------------------------------------------------------------
|
|
42 |
-- Demonstrates multiple windows and color map 0 palette, both default and
|
|
43 |
-- user-modified.
|
|
44 |
------------------------------------------------------------------------------
|
|
45 |
||
46 |
procedure xthick02a is |
|
47 |
--------------------------------------------------------------------------
|
|
48 |
-- draw_windows
|
|
49 |
-- Draws a set of numbered boxes with colors according to cmap0 entry.
|
|
50 |
--------------------------------------------------------------------------
|
|
51 |
||
52 |
procedure draw_windows(nw, cmap0_offset : Integer) is |
|
53 |
vmin, vmax : Long_Float; |
|
54 |
||
55 |
begin
|
|
56 |
Set_Character_Height(0.0, 3.5); |
|
57 |
Set_Font_Style(Script_Font); |
|
58 |
||
59 |
for i in 0..(nw-1) loop |
|
60 |
Set_Pen_Color(i+cmap0_offset); |
|
61 |
Advance_To_Subpage(Next_Subpage); |
|
62 |
vmin := 0.1; |
|
63 |
vmax := 0.9; |
|
64 |
for j in 0..2 loop |
|
65 |
Set_Pen_Width(j + 1); |
|
66 |
Set_Viewport_Normalized(vmin, vmax, vmin, vmax); |
|
67 |
Set_Viewport_World(0.0, 1.0, 0.0, 1.0); |
|
68 |
Box_Around_Viewport("bc", 0.0, 0, "bc", 0.0, 0); |
|
69 |
vmin := vmin + 0.1; |
|
70 |
vmax := vmax - 0.1; |
|
71 |
end loop; |
|
72 |
Set_Pen_Width(1); |
|
73 |
Write_Text_World(0.5, 0.5, 1.0, 0.0, 0.5, Trim(Integer'image(i), Left)); |
|
74 |
end loop; |
|
75 |
end draw_windows; |
|
76 |
||
77 |
--------------------------------------------------------------------------
|
|
78 |
-- demo1
|
|
79 |
-- Demonstrates multiple windows and default color map 0 palette.
|
|
80 |
--------------------------------------------------------------------------
|
|
81 |
||
82 |
procedure demo1 is |
|
83 |
begin
|
|
84 |
Begin_New_Page; |
|
85 |
||
86 |
-- Divide screen into 16 regions
|
|
87 |
Set_Number_Of_Subpages(4, 4); |
|
88 |
draw_windows(16, 0); |
|
89 |
Eject_Current_Page; |
|
90 |
end demo1; |
|
91 |
||
92 |
--------------------------------------------------------------------------
|
|
93 |
-- demo2
|
|
94 |
-- Demonstrates multiple windows, user-modified color map 0 palette, and
|
|
95 |
-- HLS -> RGB translation.
|
|
96 |
--------------------------------------------------------------------------
|
|
97 |
||
98 |
procedure demo2 is |
|
99 |
-- Set up cmap0
|
|
100 |
-- Use 100 custom colors in addition to base 16
|
|
101 |
r, g, b: Integer_Array_1D(0..115); |
|
102 |
||
103 |
-- Min & max lightness values
|
|
104 |
lmin : Long_Float := 0.15; |
|
105 |
lmax : Long_Float := 0.85; |
|
106 |
h, l, s : Long_Float; |
|
107 |
r1, g1, b1 : Long_Float; |
|
108 |
begin
|
|
109 |
Begin_New_Page; |
|
110 |
||
111 |
-- Divide screen into 100 regions.
|
|
112 |
Set_Number_Of_Subpages(10, 10); |
|
113 |
||
114 |
for i in 0..99 loop |
|
115 |
||
116 |
-- Bounds on HLS, from Set_Color_HLSrgb() commentary
|
|
117 |
-- hue [0., 360.] degrees
|
|
118 |
-- lightness [0., 1.] magnitude
|
|
119 |
-- saturation [0., 1.] magnitude
|
|
120 |
||
121 |
-- Vary hue uniformly from left to right
|
|
122 |
h := (360.0 / 10.0 ) * Long_Float( i mod 10 ); |
|
123 |
||
124 |
-- Vary lightness uniformly from top to bottom, between min & max.
|
|
125 |
l := lmin + (lmax - lmin) * Long_Float(i / 10) / 9.0; |
|
126 |
||
127 |
-- Use max saturation.
|
|
128 |
s := 1.0; |
|
129 |
||
130 |
HLS_To_RGB(h, l, s, r1, g1, b1); |
|
131 |
||
132 |
-- Ada rounds to nearest integer. We want to truncate
|
|
133 |
-- approximately like C to match that example. -0.5 produces
|
|
134 |
-- at least one -1 result (rather than zero) so we subtract
|
|
135 |
-- something with a slightly smaller absolute value.
|
|
136 |
r(i+16) := Integer((r1 * 255.001) - 0.499999999999999); |
|
137 |
g(i+16) := Integer((g1 * 255.001) - 0.499999999999999); |
|
138 |
b(i+16) := Integer((b1 * 255.001) - 0.499999999999999); |
|
139 |
end loop; |
|
140 |
||
141 |
-- Load default cmap0 colors into our custom set.
|
|
142 |
for i in 0..15 loop |
|
143 |
Get_Color_RGB(i, r(i), g(i), b(i)); |
|
144 |
end loop; |
|
145 |
||
146 |
-- Now set cmap0 all at once (faster, since fewer driver calls).
|
|
147 |
Set_Color_Map_0(r, g, b); |
|
148 |
||
149 |
draw_windows(100, 16); |
|
150 |
||
151 |
Eject_Current_Page; |
|
152 |
end demo2; |
|
153 |
||
154 |
begin
|
|
155 |
-- Parse and process command line arguments.
|
|
156 |
Parse_Command_Line_Arguments(Parse_Full); |
|
157 |
||
158 |
-- Initialize plplot.
|
|
159 |
Initialize_PLplot; |
|
160 |
||
161 |
-- Run demos.
|
|
162 |
demo1; |
|
163 |
demo2; |
|
164 |
||
165 |
-- Don't forget to call End_PLplot to finish off!
|
|
166 |
End_PLplot; |
|
167 |
||
168 |
end xthick02a; |