Code Monkey home page Code Monkey logo

color-names's Introduction

Color Names

These files are generated using a script which parses the list of colors on Wikipedia, here:

http://en.wikipedia.org/wiki/List_of_colors

The script used is (poorly) written in Python and depends heavily on the input format as was copied and pasted from Wikipedia using Firefox into a plain text file. The script is named format-colors and can be found in the same directory as the data files. Run it at your own discretion.

There's a GNU Make file called makefile that just re-generates the data files when the input file is updated or the script is changed. You probably don't need this file at all.

There are various output formats, explained below.

Note: some of the information in the output files is redundant, ex. the identifier name can be found from the regular name and the RGB integer triplet is provided also by the hex HTML RGB triplet. The reason is I needed this in a specific format for a project. It should be trivial to remove this information if it is redundant for you.

Note: If you're using these files for something automated/scripted, please put them on your own server so you don't pound mine.

C Code

For use in programs in the C programming language. It contains an enum like:

typedef enum Color {
  ...
  COLOR_RED,
  ...
};

And then an array of ColorInfo structures where the COLOR_ enumerators index into the array. It looks like:

ColorInfo color_data[COLOR_NAMES_MAX] = {
  ...
  { "Red", "#f00", { 255, 0, 0 } },
  ...
};

So if you wanted to look up the colour red, you'd do something like this:

const ColorInfo *clrinf = &color_data[COLOR_RED];
printf("Color Name: %s\n", clrinf->name);
printf("Color Hex: %s\n", clrinf->hex);
printf("Color RGB: (%d, %d, %d)\n",
  clrinf->rgb.r, clrinf->rgb.g, clrinf->rgb.b);

Look at the code for more details.

Conf

Similar to Windows .ini files or GKeyFiles (GLIB). For example:

...
[red]
name=Red
hex=#f00
rgb=255;0;0
...

CSV

Comma separated values for example to import into a spreadsheet utility. Looks like:

...
red,"Red",#f00,255,0,0
...

HTML

The HTML format is meant to be viewed in your browser as a "catalog" of the colors. It closely resembes the Wikipedia colour list page.

Use the "View Source" feature in your browser to examine the format.

JSON

JavaScript Object Notation, looks like a JS or Python data structure, for example:

{
  ...
  "red": {
    "name": "Red",
    "hex": "#f00",
    "rgb": [255, 0, 0]
  }
  ...
}

S-Expressions

S-Expression, which might be useful for Lisp or other languages, for example:

(
  ...
  (red 'Red' '#f00' (255 0 0))
  ...
)

XML

Good ol' XML format, for example:

<colors>
  ...
  <color id="red" hex="#f00" red="255" green="0" blue="0">Red</color>
  ...
</colors>

color-names's People

Contributors

codebrainz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.