forked from bpostlethwaite/colormap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
69 lines (59 loc) · 2.04 KB
/
example.js
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
var cmap = require('.'),
img = document.body.appendChild(document.createElement('img')),
canvas = document.body.appendChild(document.createElement('canvas')),
c = canvas.getContext('2d'),
n = 48,
colormaps = [
'jet', 'hsv','hot','cool','spring','summer','autumn','winter','bone',
'copper','greys','YIGnBu','greens','YIOrRd','bluered','RdBu','picnic',
'rainbow','portland','blackbody','earth','electric',
'viridis', 'inferno', 'magma', 'plasma', 'warm', 'rainbow-soft',
'bathymetry', 'cdom', 'chlorophyll', 'density', 'freesurface-blue', 'freesurface-red', 'oxygen', 'par', 'phase', 'salinity', 'temperature', 'turbidity', 'velocity-blue', 'velocity-green',
'cubehelix'
];
img.width = 480;
img.onload = run;
img.src = './night.jpg'
function drawColorMaps (colormap, name, height) {
/*
* Build up the color ranges and add text
*/
for (var j = 0; j < n; j++) {
c.fillStyle = colormap[j]; // start ind at index 0
c.fillRect(j*10, height, 10, 40);
}
c.fillStyle = '#262626';
c.font = '16px Helvetica';
c.fillText( name, n*10 + 10, height + 26);
}
function run() {
var height, colormap;
c.canvas.height = colormaps.length * 40 + img.height;
c.canvas.width = 648;
for (var i = 0; i < colormaps.length; i++) {
height = i*40;
colormap = cmap({
colormap: colormaps[i],
nshades: n,
format: 'rgbaString'
});
drawColorMaps(colormap, colormaps[i], height);
}
/*
* Now lets try some alpha maps overtop an image!
*/
var ilast = i;
c.drawImage(img, 0, i*40, 480, 240);
// remove background img
img.parentElement.removeChild(img);
for (var i = 0; i < colormaps.length; i++) {
height = (ilast + i)*40;
colormap = cmap({
colormap: colormaps[i],
nshades: n,
format: 'rgbaString',
alpha: [0, 1]
});
drawColorMaps(colormap, colormaps[i] + ' with transparency', height);
}
}