Colorschemer API

Now that the data from Query parse.com from GAS,  and Query scriptDB from GAS is populated in both parse.com and scriptDb, and we have the capability to Query parse.com from GAS and Query scriptDB from GAS, we can now pull all this together into an API. 

The objective here is to be able to access color scheme data from theses scriptdb or parse.com databases.

Here's what we need the API to do 

API parameters

Selecting

  • key="somekey". Some unique key such as "dulux-artiste" specific to a color within a color scheme
  • scheme="somescheme". The color scheme name such as "htm", or "dulux"
  • label="somelabel". The label or name of the color such as "magic"
  • code="somecode". The code of the color within its scheme such as the Pantone scheme 18-3211 TCX.
  • rgb=rgbcode. The decimal rgb code of a color to analyze
  • hex="htmlhexcode". The hex code of the color to analyze

Provider

  • provider="parse or scriptdb". Whether to look up parse.com or scriptdb

Closest color analysis

  • closest=n. Return the n closest matches to the color specified by key=, hex= or rgb=.

Palette generation (still work in progress)

  • palette=n. Return a palette of n colors as selected by key=, hex= or rgb=.
  • model="hsl or lch". The color model to use to calculate the palette.
  • type = "hue or saturation or lightness". The type of palette to return.

Controlling

  • limit=n. Maximum number of colors to return. default 0 means all.
  • callback="function" Will return jsonP rather than jSon

Examples

  • getting color properties
?key=htm-teal. A single color with the given key and it's properties
?scheme=pfh&provider=parse&limit=100. Multiple colors belonging to the pfh scheme, with input coming from parse.com. First 100 records.
?rgb=1234. Get the properties of the color with rgb value 1234
?hex=#ff67e09. Get the properties of the color with the hex value of #ff67e09
  • finding 'n' color matches
?scheme=pms&key=dulux-crushed raspberry&closest=5.  Return the properties of the 5 closest colors in the pantone matching scheme to the given dulux name color
?scheme=htm&hex=ff0000&closest=1&provider=scriptdb. Return the properties of the closest color to #ff0000 in the htm scheme, looking up scriptdb.
  • creating palettes
?key=htm-teal. A single color with the given key and it's properties.
?scheme=pfh&callback=xyz. Multiple colors - all members of current scheme returned as jsonp

URL

Here is the url for the GAS version.

https://script.google.com/macros/s/AKfycbzSdgK85uGHdQ9m076QkPV0B9a2kkgh7JHDmV8kzRgtkriSIwTn/exec

You can also find the script here
https://script.google.com/d/1Kc8WS6DXhPlodBrUNMviBtBAQfSCn9FYUeMHKKehDeWbY5jSSLtYeFa4/edit?usp=sharing

example
https://script.google.com/macros/s/AKfycbzSdgK85uGHdQ9m076QkPV0B9a2kkgh7JHDmV8kzRgtkriSIwTn/exec?key=dulux-crushed%20raspberry&source=parse

The results

Here is a typical response.

{
    "p": {
        "queryString": "key=pms-80",
        "parameter": {
            "key": "pms-80",
            "action": "get",
            "access": "key",
            "cache": "yes",
            "useCache": true,
            "limit": "0",
            "provider": "scriptdb",
            "type": "hue",
            "closest": 5,
            "palette": 5,
            "model": "lch"
        },
        "contextPath": "",
        "parameters": {
            "key": [
                "pms-80"
            ]
        },
        "contentLength": -1
    },
    "c": [
        {
            "colortable": {
                "siloId": "colorschemes",
                "timeStamp": 1366206628396,
                "scheme": "pms",
                "hex": "#F4ED7C",
                "label": "80",
                "code": "80",
                "key": "pms-80",
                "userStamp": "bruce@mcpher.com"
            },
            "properties": {
                "rgb": 8187380,
                "red": 244,
                "green": 237,
                "blue": 124,
                "htmlHex": "#f4ed7c",
                "luminance": 0.8165397818342681,
                "textColor": 0,
                "contrastRatio": 17.330795636685362,
                "black": 0.04313725490196074,
                "cyan": 0,
                "magenta": 0.02868852459016395,
                "yellow": 0.4918032786885246,
                "hue": 56.5,
                "saturation": 84.50704225352116,
                "lightness": 72.15686274509804,
                "value": 0.9568627450980393,
                "x": 71.23050397167239,
                "y": 81.25670623753643,
                "z": 30.998646909329864,
                "LStar": 92.24580152561062,
                "aStar": -12.412905790015527,
                "bStar": 55.060488100841724,
                "cStar": 56.44233854168991,
                "hStar": 102.70444528421152
            }
        }
    ]
}

For more about parse.com, see Parse.com
For help and more information join our forum,follow the blog or follow me on twitter .


Comments