-
Notifications
You must be signed in to change notification settings - Fork 1
/
colormap.html
412 lines (394 loc) · 14.6 KB
/
colormap.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Color Height Mapping 6
</title>
<meta charset="utf-8">
<style type="text/css">
body {
margin : 0 1cm 0 1cm;
font-family: Courier, sans-serif;
}
table, tr, td {
margin: 0;
text-align: center;
}
</style>
</head>
<body>
<h1 align="center">
Color Height Mapping
</h1>
<p>
After looking at <a target="_blank"
href="https://github.com/jaanga/cookbook/tree/gh-pages/un-flatland/unicam">cookbook/un-flatland/unicam</a>
I started to think about a suitable height map color scheme. I know some prefer a grayscale,
and that is ok, but I wanted to explore colors. I wanted a way I could use a math algorithm
on an elevation value, and set a color. Yes, it could be a table look-up with ranges, but
here I generated a 17 x 16 grid of colors, where I go from 0x00ff00, increasing the red
component and reducing the green, to 0xff0000, then one extra 17th line where the red is
reduced. This give me 272 colors to use, although the last at least 4 are too close to
black, so say 268 colors or so, all in the red/green range.
</p>
<script type="text/javascript">
function tohex(num,len) {
var str = num.toString(16);
while (str.length < len) {
str = '0'+str;
}
return str;
}
function tohexcolor(num) {
return tohex(num,6);
}
function add_unicam() {
var unicam = new Array(
new Array(20,0,0,">= 6000"),
new Array(32,0,0,"5000 - 6000"),
new Array(44,0,0,"4500 - 5000"),
new Array(56,0,0,"4000 - 4500"),
new Array(68,0,0,"3500 - 4000"),
new Array(80,0,0,"3000 - 3500"),
new Array(92,0,0,"2500 - 3000"),
new Array(104,0,0,"2000 - 2500"),
new Array(116,0,0,"1900 - 2000"),
new Array(128,0,0,"1800 - 1900"),
new Array(140,0,0,"1700 - 1800"),
new Array(152,0,0,"1600 - 1700"),
new Array(164,0,0,"1500 - 1600"),
new Array(176,0,0,"1400 - 1500"),
new Array(188,0,0,"1300 - 1400"),
new Array(200,0,0,"1200 - 1300"),
new Array(210,8,3,"1100 - 1200"),
new Array(218,24,9,"1000 - 1100"),
new Array(226,40,15,"950 - 1000"),
new Array(234,56,21,"900 - 950"),
new Array(242,72,27,"850 - 900"),
new Array(250,88,33,"800 - 850"),
new Array(255,104,39,"750 - 800"),
new Array(255,120,45,"700 - 750"),
new Array(255,136,51,"650 - 700"),
new Array(255,152,57,"600 - 650"),
new Array(255,168,63,"550 - 600"),
new Array(255,184,69,"500 - 550"),
new Array(255,200,75,"450 - 500"),
new Array(255,216,81,"400 - 450"),
new Array(255,232,87,"350 - 400"),
new Array(255,242,0,"300 - 350"),
new Array(255,248,93,"250 - 300"),
new Array(255,255,99,"200 - 250"),
new Array(197,243,0,"180 - 200"),
new Array(139,222,0,"160 - 180"),
new Array(0,220,0,"140 - 160"),
new Array(100,228,0,"120 - 140"),
new Array(0,242,0,"100 - 120"),
new Array(35,255,20,"90 - 100"),
new Array(96,255,20,"80 - 90"),
new Array(134,255,20,"70 - 80"),
new Array(157,255,20,"60 - 70"),
new Array(177,255,20,"50 - 60"),
new Array(200,255,20,"40 - 50"),
new Array(200,255,106,"30 - 40"),
new Array(200,255,154,"20 - 30"),
new Array(200,255,192,"10 - 20"),
new Array(200,255,237,"5 - 10"),
new Array(227,255,255,"0 - 5"),
new Array(210,255,255,"0 - -200"),
new Array(193,255,255,"-200 - -400"),
new Array(0,0,128,"-400 - -9999")
);
var max = unicam.length;
var add_rgb = 0; // maybe better without adding the rgb value
var i,a,r,g,b,clr,color,txt,i2,sty;
var wrap = 3;
var cnt = 0;
var html = '<div align="center">';
html += "<table align='center' border='0' cellspacing='2' cellpadding='2'>";
html += "<caption>UniCam - Solid Earth Reseach Group<\/caption>";
html += '<thead>';
html += "<tr>";
while (cnt < wrap) {
html += '<th>#<\/th>';
html += '<th>Elevation<\/th>';
if (add_rgb) {
html += '<th>R<\/th>';
html += '<th>G<\/th>';
html += '<th>B<\/th>';
}
html += '<th>Hex<\/th>';
cnt++;
}
html += "<\/tr>";
html += '<\/thead>';
cnt = 0;
for (i = 0; i < max; i++) {
i2 = i + 1;
a = unicam[i];
r = a[0];
g = a[1];
b = a[2];
txt = a[3];
clr = (r * 0x10000) + (g * 0x100) + b;
color = tohexcolor(clr);
if (cnt == 0) {
html += "<tr>";
}
if ((i < 20) || ((i + 1) == max)) {
sty = 'align="center" style=background-color:#'+color+';color:white;';
} else {
sty = 'align="center" style=background-color:#'+color+';';
}
html += '<td '+sty+'>'+i2+'<\/td>';
html += '<td '+sty+'>'+txt+'<\/td>';
if (add_rgb) {
html += '<td '+sty+'>'+r+'<\/td>';
html += '<td '+sty+'>'+g+'<\/td>';
html += '<td '+sty+'>'+b+'<\/td>';
}
html += '<td '+sty+'>'+color+'<\/td>';
cnt++;
if (cnt == wrap) {
html += "<\/tr>";
cnt = 0;
}
}
if (cnt) {
while (cnt < wrap) {
html += '<td> <\/td>';
html += '<td> <\/td>';
if (add_rgb) {
html += '<td> <\/td>';
html += '<td> <\/td>';
html += '<td> <\/td>';
}
html += '<td> <\/td>';
cnt++;
}
html += "<\/tr>";
}
html += '<\/table>';
html += '<\/div>';
document.write(html);
}
function init() {
var i, j, clr2;
var clr = 0x00ff00;
var color, html;
html = '<div align="center">';
html += "<table align='center' border='0' cellspacing='1' cellpadding='0'>";
html += "<caption>Height Gradients<\/caption>";
for (i = 0; i < 16; i++) {
html += "<tr>";
color = tohexcolor(clr)
html += "<td>"+color+"<\/td>";
html += "<td> <\/td>";
clr2 = clr + 0x100 - 0x10000;
for (j = 0; j < 16; j++) {
clr2 -= 0x100; // reduce green
clr2 += 0x10000; // add red
color = tohexcolor(clr2);
html += "<td style=background-color:#"+color+";>"+color+"<\/td>";
//clr2 += 0x02;
}
color = tohexcolor(clr2);
html += "<td> <\/td>";
html += "<td>"+color+"<\/td>";
html += "<\/tr>";
clr += 0x100000; // add red
clr -= 0x1000;
}
// one more row, reducing the red
clr = 0xff0000;
html += "<tr>";
color = tohexcolor(clr)
html += "<td>"+color+"<\/td>";
html += "<td> <\/td>";
clr2 = clr + 0x100000;
for (j = 0; j < 16; j++) {
clr2 -= 0x100000; // add red
color = tohexcolor(clr2);
html += "<td style=background-color:#"+color+";color:white;>"+color+"<\/td>";
//clr2 += 0x02;
}
color = tohexcolor(clr2);
html += "<td> <\/td>";
html += "<td>"+color+"<\/td>";
html += "<\/tr>";
html += "<\/table>";
html += "<\/div>";
document.write(html);
html = "<p>And a smaller blue range for the sea, and below mean sea level.<\/p>";
html += '<div align="center">';
html += "<table align='center' border='0' cellspacing='1' cellpadding='0'>";
html += "<caption>Sea Color<\/caption>";
clr = 0xff;
//for (i = 0; i < 16; i++) {
html += "<tr>";
color = tohexcolor(clr)
html += "<td>"+color+"<\/td>";
html += "<td> <\/td>";
clr2 = clr - 0x1000;
for (j = 0; j < 16; j++) {
clr2 += 0x1000; // add green
color = tohexcolor(clr2);
html += "<td style=background-color:#"+color+";>"+color+"<\/td>";
}
html += "<td> <\/td>";
html += "<td>"+color+"<\/td>";
html += "<\/tr>";
//}
html += "<\/table>";
html += '<\/div>';
document.write(html);
// another scheme
html = '<p>Then I started to search the web a bit for other ideas. '+
'Here are color samples from <a target="_blank" href="http://colorbrewer2.org/">http://colorbrewer2.org/<\/a><\/p>';
html += '<div align="center">';
html += "<table align='center' border='0' cellspacing='4' cellpadding='0'>";
html += "<tr>";
html += "<td>fff7ec<\/td>";
html += "<td> <\/td>";
html += "<td style=background-color:#fff7ec;>fff7ec<\/td>";
html += "<td style=background-color:#fee8c8;>fee8c8<\/td>";
html += "<td style=background-color:#fdd49e;>fdd49e<\/td>";
html += "<td style=background-color:#fdbb84;>fdbb84<\/td>";
html += "<td style=background-color:#fc8d59;>fc8d59<\/td>";
html += "<td style=background-color:#ef6548;>ef6548<\/td>";
html += "<td style=background-color:#d7301f;>d7301f<\/td>";
html += "<td style=background-color:#b30000;>b30000<\/td>";
html += "<td style=background-color:#7f0000;>7f0000<\/td>";
html += "<td> <\/td>";
html += "<td>7f0000<\/td>";
html += "<\/tr>";
html += "<\/table>";
html += '<\/div>';
html += "<p>Or the browns<\/p>";
var colors = new Array( 0xffffe5, 0xfff7bc, 0xfee391, 0xfec44f, 0xfe9929, 0xec7014, 0xcc4c02, 0x993404, 0x662506 );
var max = colors.length;
html += '<div align="center">';
html += "<table align='center' border='0' cellspacing='4' cellpadding='0'>";
html += "<tr>";
clr = colors[0];
color = tohexcolor(clr);
html += "<td>"+color+"<\/td>";
html += "<td> <\/td>";
for (i = 0; i < max; i++) {
clr = colors[i];
color = tohexcolor(clr);
html += "<td style=background-color:#"+color+";>"+color+"<\/td>";
}
html += "<td> <\/td>";
clr = colors[max-1];
color = tohexcolor(clr);
html += "<td>"+color+"<\/td>";
html += "<\/tr>";
html += "<\/table>";
html += '<\/div>';
document.write(html);
html = "<p>Then taken from my <a target=\"_blank\" href=\"https://gitorious.org/fgtools/atlas-g/\">fork<\/a> "+
"of flightgear Atlas/Map default palette, which seems to lack any 'linear' quality,"+
" but then Altas 'concentrates' on coloring land use classes, and only when a 'feature' "+
"is 'undefined', this elevation color will be used...<\/p>";
var atlas_palette = new Array(
new Array(0.647, 0.729, 0.647, "E_-250" ),
new Array(0.859, 0.906, 0.804, "E_0" ),
new Array(0.753, 0.831, 0.682, "E_250" ),
new Array(0.949, 0.933, 0.757, "E_500" ),
new Array(0.941, 0.871, 0.608, "E_1000" ),
new Array(0.878, 0.725, 0.486, "E_2500" ),
new Array(0.816, 0.616, 0.443, "E_5000" ),
new Array(0.776, 0.529, 0.341, "E_7500" ),
new Array(0.750, 0.725, 0.600, "E_10000" ),
new Array(0.824, 0.863, 0.824, "E_20000" )
);
max = atlas_palette.length;
var rgb, r, g, b, elev;
html += '<div align="center">';
html += "<table align='center' border='0' cellspacing='4' cellpadding='0'>";
html += "<tr>";
for (i = 0; i < max; i++) {
rgb = atlas_palette[i];
elev = rgb[3];
html += "<td>"+elev+"<\/td>";
}
html += "<\/tr>";
html += "<tr>";
for (i = 0; i < max; i++) {
rgb = atlas_palette[i];
r = 255 * rgb[0];
g = 255 * rgb[1];
b = 255 * rgb[2];
clr = r * 0x10000;
clr += g * 0x100;
clr += b;
color = tohexcolor(clr);
clr2 = parseInt(color,16);
color = tohexcolor(clr2);
html += "<td style=background-color:#"+color+";>"+color+"<\/td>";
}
html += "<\/tr>";
html += "<\/table>";
html += '<\/div>';
document.write(html);
html = '<p>And concerning the current cookbook unicam png generation, a table idea from '+
'<a target="_blank" href="http://www.serg.unicam.it/Gtopohelp.html">'+
'Universita degli Studi di Camerino<\/a>, which looks quite interesting '+
'in that it is a table look-up with elevation ranges.<\/p>';
document.write(html);
add_unicam();
}
init();
</script>
<p>
Further web searching led me to MANY interesting images, like this one <a target="_blank"
href="http://serc.carleton.edu/images/eslabs/corals/ocean_depth_colorscale.jpg">http://serc.carleton.edu/images/eslabs/corals/ocean_depth_colorscale.jpg</a>
which triggers the idea that maybe the scale should not be so strictly 'linear', but more
'exponential' due the the fact that the majority of the world is less that about 5,000
meters... and here <a target="_blank"
href="http://www.theodora.com/maps/new/world_maps_2.html">http://www.theodora.com/maps/new/world_maps_2.html</a>,
and just so many others... Seemingly each with their 'own' color mapping scheme...
</p>
<p>
20131227: I have now 'played' with the neat table from unicam. Coded a quick DEM30 C++ loader,
and loaded the 33 GTOPO30 DEM files, all except ANTARCPS, which is a little different. And
wrote each out to a BMP file of the same width, height as the DEM. Looks nice... But nothing is
cast in stone, and can be changed with a few strokes of the pen ;=))
</p>
<p>
Actually they are not 'really' DEM files, in that their format is more like that of a HGT file.
They have no A and B records, but are a simple set of 16-bit integers, in Motorola format, row
by row, with no file header, but do have a separatate .HDR file which gives them their
credentials. It was 'fun' sorting through LOTS of very 'faulty' documentaion to be able to
output a good image. A sample of E020N40 is shown below - click image to load full size... to
me it is absolute magic at full size!
</p>
<div align="center">
<p align="center">
<a target="_blank"
href="images/E020N40.DEM.png"><img src="images/E020N40.DEM.png"
width="480"
height="600"
alt="E020N40 DEM as BMP, then converted (by im) to PNG"></a>
</p>
</div>
<p>
The next bit of 'fun' will be to try to 'reduce' the width, height of the output by averaging
in some way the color height map I build... feels interesting... but off for a big lunch
tomorrow so will not get much computer time.
</p>
<p>
<a target="_blank"
href="http://tidy.sourceforge.net/"><img border="0"
src="images/checked_by_tidy.gif"
alt="checked by tidy"
width="32"
height="32"></a> <a href="http://validator.w3.org/check?uri=referer"
target="_blank"><img src="images/valid-html401.gif"
alt="Valid HTML 4.01 Transitional"
width="88"
height="31"></a>
</p>
<!-- 20131225 - added page - experiments in generating a color height mapping scale -->
</body>
</html>