diff options
Diffstat (limited to 'Master/texmf-dist/doc/metapost/metapost-colorbrewer')
-rw-r--r-- | Master/texmf-dist/doc/metapost/metapost-colorbrewer/README.md | 49 | ||||
-rw-r--r-- | Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.mp | 45 | ||||
-rw-r--r-- | Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.pdf | bin | 0 -> 21531 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.png | bin | 0 -> 229223 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/metapost/metapost-colorbrewer/make_mp_colorbrewer.py | 148 |
5 files changed, 242 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/metapost/metapost-colorbrewer/README.md b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/README.md new file mode 100644 index 00000000000..973b68d6335 --- /dev/null +++ b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/README.md @@ -0,0 +1,49 @@ +# metapost-colorbrewer + +An implementation of the colour palettes from http://colorbrewer2.org for Metapost + +The Colorbrewer palettes are copyright (c) Cynthia Brewer, Mark Harrower and The Pennsylvania State University. + +This implementation that makes them available for Metapost is copyright (c) 2018 Toby Thurston. + +Toby Thurston -- 18 Sept 2018 + +## Provides + +- A Python script that reads "cb.csv" from https://github.com/axismaps/colorbrewer/ + and creates a Metapost include-file that includes all the Colorbrewer definitions as + Metapost colors (cmyk or rgb, as you please) + +- colorbrewer-cmyk.mp +- colorbrewer-rgb.mp +- colorbrewer-sampler.mp + +![Colorbrewer Sampler](colorbrewer-sampler.png) + +## Usage + +(Assumes you are on osx, adapt as needed for windows, or linux). + +- git clone http://github.com/thruston/metapost-colorbrewer +- mkdir -p ~/Library/texmf/metapost +- cp metapost-colorbrewer/colorbrewer-cmyk.mp ~/Library/texmf/metapost +- cp metapost-colorbrewer/colorbrewer-rgb.mp ~/Library/texmf/metapost + +and then look at metapost-colorbrewer/colorbrewer-sampler.mp for an example of +how to use them. Once they are in your local texmf tree you just need to include +them with "include colorbrewer-rgb" or "include colorbrewer-cmyk" + +## Licence + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. diff --git a/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.mp b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.mp new file mode 100644 index 00000000000..25789c8d99d --- /dev/null +++ b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.mp @@ -0,0 +1,45 @@ +prologues := 3; +outputtemplate := "%j.eps"; + +input colorbrewer-cmyk + +beginfig(1); + defaultfont := "phvr8r"; + x = 0; y = 0; bx = 8; by = -13; path box; box = unitsquare shifted -(1/2,1/2) xscaled bx yscaled by; + forsuffixes gamut = + Reds, Oranges, Greens, Blues, Purples, Greys, + Skip, + OrRd, YlOrRd, YlOrBr, YlGn, BuGn, PuBuGn, YlGnBu, GnBu, PuBu, RdPu, PuRd, BuPu, + Skip, + PRGn, PiYG, BrBG, PuOr, RdGy, RdBu, RdYlBu, RdYlGn, Spectral, + Skip, + Accent, DarkTwo, PastelTwo, SetTwo, + PastelOne, SetOne, SetThree, Paired: + + for i=3 upto 12: + if known gamut[i][1]: + label.lft(decimal i & ":", (x,y)); + if i=3: + label.lft(str gamut, (x-15,y)); + fi + fi + for j = 1 upto i: + if known gamut[i][j]: + fill box shifted (x+j*bx, y) withcolor gamut[i][j]; + fi + endfor + x := x + i*bx + 32; + endfor + y := y + by * 17/13; + x := 0; + endfor + label.rt("Single hue, sequential",(560,-42)); + label.rt("Multi-hue, sequential", (560,-212)); + label.rt("Assortments", (560,-552)); + label.rt("Diverging", (780,-402)); + path b; b = unitsquare shifted -(1/2,1/2) yscaled 55 xscaled 233 shifted (720, -120); + fill b withcolor Paired[4][1]; draw b withcolor Paired[4][2]; + label.top("Colorbrewer for Metapost" infont "phvb8r" scaled 1.414, center b); + label.bot("http://colorbrewer2.org", center b shifted 2 down); +endfig; +end. diff --git a/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.pdf b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.pdf Binary files differnew file mode 100644 index 00000000000..bd7e1697ec4 --- /dev/null +++ b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.pdf diff --git a/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.png b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.png Binary files differnew file mode 100644 index 00000000000..ce6994740b7 --- /dev/null +++ b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/colorbrewer-sampler.png diff --git a/Master/texmf-dist/doc/metapost/metapost-colorbrewer/make_mp_colorbrewer.py b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/make_mp_colorbrewer.py new file mode 100644 index 00000000000..86b304c2b6d --- /dev/null +++ b/Master/texmf-dist/doc/metapost/metapost-colorbrewer/make_mp_colorbrewer.py @@ -0,0 +1,148 @@ +#! /usr/bin/env python3 +from __future__ import print_function, division + +import argparse +import csv +import os.path +import re +import textwrap + +def get_rid_of_numbers(ss): + ss = ss.replace('1', 'One') + ss = ss.replace('2', 'Two') + ss = ss.replace('3', 'Three') + ss = ss.replace('4', 'Four') + ss = ss.replace('5', 'Five') + ss = ss.replace('6', 'Six') + ss = ss.replace('7', 'Seven') + ss = ss.replace('8', 'Eight') + ss = ss.replace('9', 'Nine') + return ss + +def get_cmyk_values(): + csv_file_name = os.path.join(args.colorbrewer, 'cb.csv') + with open(csv_file_name) as csv_file: + cynthia = csv.DictReader(csv_file) + + # ColorName,NumOfColors,Type,CritVal,ColorNum,ColorLetter,C,M,Y,K,SchemeType + colors = list() + ranges = list() + + for row in cynthia: + + if row['ColorName']: + this_range = get_rid_of_numbers(row['ColorName']) + if this_range not in ranges: + ranges.append(this_range) + + if row['NumOfColors']: + this_size = row['NumOfColors'] + + colors.append('{}[{}][{}] = 1/100 ({},{},{},{});'.format( + this_range, this_size, row['ColorNum'], row['C'], row['M'], row['Y'], row['K']) + ) + + return colors, ranges + +def is_int(n): + "Is this a dagger?" + try: + a = int(n) + except: + return False + return True + +def get_rgb_values(): + js_file_name = os.path.join(args.colorbrewer, 'colorbrewer_schemes.js') + + colors = list() + ranges = list() + with open(js_file_name) as js: + for line in js: + m = re.match(r'^([A-Za-z0-9]+):\s*({.*})\s*,?$', line) + if m is None: + continue + this_range = get_rid_of_numbers(m.group(1)) + ranges.append(this_range) + details = eval(m.group(2)) + + for k in details: + if is_int(k): + for i, v in enumerate(details[k]): + if v.startswith('rgb('): + colors.append('{}[{}][{}] = 1/256 {};'.format(this_range, k, i+1, v[3:])) + + return colors, ranges + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-c", "--colorbrewer", + help="Directory for local copy of the Axel Maps Colorbrewer project") + parser.add_argument("-r", "--rgb", action="store_true", help="Create RGB colors, not CMYK") + + args = parser.parse_args() + + if args.rgb: + colors, ranges = get_rgb_values() + else: + colors, ranges = get_cmyk_values() + + print('''% This package includes color specifications and designs +% developed by Cynthia Brewer (http://colorbrewer.org/). +% Metapost version adapted from cb.csv by Toby Thurston. +% Please see license at http://colorbrewer.org/export/LICENSE.txt + +% This package defines all the colours from colorbrewer.org +% Visit the site to get an idea what you can do with them +% Each colour set is defined as a MP variable with two suffixes +% The first suffix defines the number of colours in the set, +% the second one defines the index of this colour in the set +% starting at 1, so this loop shows you all the shades of red +% in the six colour "Reds" set. +% +% for i=1 upto 6: +% fill unitsquare scaled 1cm shifted (i*cm,0) withcolor Reds[6][i]; +% endfor +% +% Six of the qualititative colour sets have numbers in their names at colorbrewer.org +% MP doesn't allow this, so they are renamed here as follows: +% +% Dark2 is called DarkTwo +% Pastel1 is called PastelOne +% Pastel2 is called PastelTwo +% Set1 is called SetOne +% Set2 is called SetTwo +% Set3 is called SetThree +% +% No sequence has fewer than three colours. +% All of the sequences are defined for upto eight colours. +% The sequential sequences are defined for 3 to 9 colours each. +% The divergent sequences are defined for 3 to 11 colours each. +% A few of the qualitative sequences have upto 12 colours. +% +% In general try not to use too many colours in one chart. +% The sequences were designed for cartography and may not suit all applications. + +message "metapost-colorbrewer - Copyright (C) 2018 Toby Thurston. This program comes with ABSOLUTELY NO WARRANTY. " & +"This is free software, and you are welcome to redistribute it under certain conditions; read the LICENCE file for details. " & +"The colorbrewer colours are copyright (C) Cynthia Brewer, Mark Harrower and The Pennsylvania State University. " & +"See http://colorbrewer2.org"; + + ''') + + + if args.rgb: + out = "color " + else: + out = "cmykcolor " + + out = out + ', '.join('{}[][]'.format(x) for x in sorted(ranges)) + ';' + + rapper = textwrap.TextWrapper(subsequent_indent = ' ', width = 72) + print('\n'.join(rapper.wrap(out))) + + print("") + + for c in sorted(colors): + print(c) |