#!/usr/bin/python
if __name__ == "__main__":
    import sys
    colormap_js = sys.argv[1]
    with open(colormap_js, "wt") as ff:
        import matplotlib.pyplot
        import matplotlib.cm
        import numpy as np

        ff.write("JS9p_Colormaps = {\n")
        for name in matplotlib.pyplot.colormaps():
            cmap = matplotlib.cm.get_cmap(name)
            values = cmap(np.linspace(0., 1., 256))
            ff.write('  {}: [\n        '.format(name))
            ff.write(',\n        '.join(['[{},{},{}]'.format(*x) for x in cmap(np.linspace(0, 1, 256))]))
            ff.write('  ],\n')
        ff.write('}\n')
