More playing around with color, parse.com, scriptDb and Google Apps Script

API for comparing colors

I continue to find the topic of comparing colors a fascinating one. As an experiment to see if I could create a REST API serving up JSON and JSONP from a Google Apps Script content service app, I wanted to see if I could create something that, given a color code, would find the nearest ‘n’ matching colors in some defined color scheme, such as pantone, dulux, htm colors and so on.

Just for fun, I also implemented the color database in both parse.com and scriptb.

A VBA consumer

Now all that is working, I needed to create something to act as a client. I have already implemented color matching natively in both VBA and Google Apps Script, but now I needed to create something that would delegate the database management and color matchs to a GAS web app and just query and display the results.

First off, here is the VBA version. Here’s the first 5 closest matching colors to some random hex codes from the pantone fashion and home library. I think the algorithm does a pretty good job – and all the processing is delegated off to the GAS modules described here.

For simplicity, Im using the rest/excel library to manage all the jSon stuff and web interaction details. That means that the final client procedure is rather trivial as below.

Public Sub testColorSchemerClosest()
    Dim scheme As String, joc As cJobject
    Dim job As cJobject, jt As cJobject, n As Long
    scheme = InputBox("Which scheme (htm,pms,pfh or dulux)?")

    n = 0
    With restQuery("colorschemer", "colorschemer", , _
            "target", , , , False, , , , , , , , , _
            "&provider=parse&closest=5&scheme=" & scheme)
        For Each job In .jObjects
            n = n + 1
            For Each joc In job.child("c").children
                With .dset.headingRow.where.Offset(n, joc.childIndex).Resize(1, 1)
                    .Interior.Color = joc.child("properties.rgb").value
                    Set jt = joc.child("colortable.label")
                    ' would only exist if this was from a scheme
                    If (jt Is Nothing) Then
                        .value = joc.child("colortable.hex").value
                    Else
                        .value = jt.value
                    End If
                    .Font.Color = joc.child("properties.textColor").value
                End With
            Next joc
        Next job
        ' modify heading
        .dset.headingRow.headings(2).where.value = "Matching this against scheme " & scheme
        .teardown
    End With

End Sub

 

Performance

The only problem is that it is pretty slow. See here for a look at GAS performance. with a focus on lots of math. Using Parse.com or scriptdb as the underlying database is not a big factor. I’ll publish some comparison stats on that later.

More color schemes

I’m looking for more color schemes. If you would like to contribute a color scheme, all i need is the link to a Google Document with the scheme in it, like the colortable tab in this spreadsheet.

You can download the VBA code and libraries mentioned here in the cDataSet.xlsm workbook – the colorschemer tab, from Excel liberation.

For more stuff like this, see from VBA to Google Apps Script, and for more detail on this post and how to use this as a REST API see colorschemer api

About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.