For all your color needs!

From Remeis-Wiki
Jump to navigation Jump to search

This is a simple script to create two PDFs showing the defined colors in the isisscripts. Some of them are created via generator functions and allow a great deal of customization. You really should consult the help.

Color-palettes-isisscripts.png

Color-maps-isisscripts.png

require("tikz");

%% Plot all palettes with tikz
define tikz_color_test (filename)
{
  variable C = {}; % these are just collectors for nicer alignment
  variable V = {};

  variable n,j=0;
  % loop through all maps and palettes
  foreach n ([png_get_colormap_names(), get_color_palette_names()])
  {
    % this is the color interface access: We request a palette with name 'n'
    % and 10 colors. In case it is a static palette we only get the total
    % number of colors, the repeat qualifier ensures we get an array of
    % length 10, with repeated colors.
    variable pal = get_color_palette(n, qualifier("n", 10); repeat);
    % all returned palettes are generated with the default parameter settings
    % many can be customized for your needs! You really should check the
    % help entries.

    if (j == 30)
    {
      list_append(C, tikz_new_vbox_compound(__push_list(V)));
      V = {};
      j = 0;
    }

    variable H = {};
    variable i;
    _for i (0,qualifier("n", 10)-1)
    {
      % Put the colors in boxes together
      list_append(H, tikz_new_rectangle(0,0,1,1; fillcolor=sprintf("#%06x", pal[i])));
    }

    % label it
    list_append(V, tikz_new_hbox_compound(tikz_new_text(0,0,strreplace(n,"_","\\_"); anchor="south east"),
					  __push_list(H)));
    j++;
  }

  % to capture the remaining palettes
  if (length(V)>0)
    list_append(C, tikz_new_vbox_compound(__push_list(V)));

  % put everything together
  tikz_new_hbox_compound(__push_list(C), 4).render(filename);
}

define tikz_map_test (filename)
{
  variable V = {}; % collectors again
  variable H = {};
  variable n, map, i = 0;

  % and again loop over maps and palettes
  foreach n ([png_get_colormap_names(), get_color_palette_names()])
  {
    if (i == 30)
    {
      list_append(H, tikz_new_vbox_compound(__push_list(V)));
      V = {};
      i = 0;
    }

    % get a color map, this is different from 'png_get_colormap' as it allows
    % also a palette name (just a (small) number of colors) and interpolates between
    % them. Also has parameters, see the help.
    map = get_color_map(n);

    % to make it simple just plot some pictures
    variable p = tikz_plot_new(10, 1);
    p.axis(; off);
    p.plot_png(_reshape([0:255], [1, 256]); cmap=map, depth=200);
    p.plot([0,0,1,1,0], [0,1,1,0,0]; width=2, color="black", world0);
    list_append(V, tikz_new_hbox_compound(tikz_new_text(0,0,strreplace(n,"_", "\\_"); anchor="south east"),
					  p; interleave));
    i++;
  }
  if (length(V)>0)
    list_append(H, tikz_new_vbox_compound(__push_list(V)));

  % and puth everything together
  tikz_new_hbox_compound(__push_list(H), 4).render(filename);
}

% run both!
tikz_color_test("palettes.pdf");
tikz_map_test("maps.pdf");
% and enjoy your creation :)

exit();