Code for Using W3C Colors by Name in Rule Files

How about some Fourth of July color? I got bored, so I made a set of rules covering most of the 140 W3C (Worldwide Web Consortium) color names and their associated hex values.  View the color palate on the W3C web site.

I use colors a lot when I’m writing code to temporarily highlight some pieces of geometry to ensure code is being applied in the right places.  I’ve gotten a little tired of writing color rules and/or hex values in functions like color(“#ff0000”) every time I need them. I’m also tired of seeing red, green, blue and other colors with easy to remember hex values. Now all I have to is write something like color(xx.SteelBlue) and remember some favorite color names from the list.

All of the ROYGBV color names are there including Black, Brown, Gray/Grey, Silver and Gold (as you would find on electrical components — remember your resistor color codes?) as well as Cyan, Magenta and Yellow from the world of printing. There are some tasty ones like Salmon (#FA8072); tasty ones that don’t work like (bummer) MintCream (#F5FFFA); there are some totally useless ones like Gainsboro (?? — a light gray); there are even some scary ones like Navajo White (#FFDEAD). I’ve removed some of the more subtle colors that don’t work in CityEngine’s color range, which is not an issue. For this reason, some colors may be a bit redundant or indistinguishable.

Well, whatever, coloring just got a whole lot easier and a bit more interesting. I can always cut down the list.

/**
* File: TestColor.cga
* Created: 1 Jul 2018 02:09:59 GMT
* Author: Jeff Herzer | jeffcity.io
* Draw a shape and apply this rule file and the Start Rule "Lot" to it, then generate.
*/

version "2017.1"
import xx : "colorChartName.cga"

@Start
Lot -->
extrude(5)
color(xx.SteelBlue)
/**
* File: colorChartName.cga
* Created: 4 Jul 2018 05:24:07 GMT
* Author: Jeff Herzer | jeffcity.io
* Notes: Generate colors from the W3C color chart by name 
* Source: https://www.w3schools.com/colors/colors_names.asp
* INSTRUCTIONS: 
* 1. To call this file from another cga document, add the following line of code:
*    import xx : "colorChartName.cga"
*    Use a correct folder/file location; the "xx" prefix can be any allowed name)
* 2. Use any color in a rule by calling it with the xx prefix and using the W3C color name
*    color(xx.Red)
*/
version "2017.1"

@Hidden 
attr Aqua = ("#00FFFF")
@Hidden 
attr Aquamarine = ("#7FFFD4")
@Hidden 
attr Bisque = ("#FFE4C4")
@Hidden 
attr Black = ("#000000")
@Hidden 
attr Blue = ("#0000FF")
@Hidden 
attr BlueViolet = ("#8A2BE2")
@Hidden 
attr Brown = ("#A52A2A")
@Hidden 
attr BurlyWood = ("#DEB887")
@Hidden 
attr CadetBlue = ("#5F9EA0")
@Hidden 
attr Chartreuse = ("#7FFF00")
@Hidden 
attr Chocolate = ("#D2691E")
@Hidden 
attr Coral = ("#FF7F50")
@Hidden 
attr CornflowerBlue = ("#6495ED")
@Hidden 
attr Cornsilk = ("#FFF8DC")
@Hidden 
attr Crimson = ("#DC143C")
@Hidden 
attr Cyan = ("#00FFFF")
@Hidden 
attr DarkBlue = ("#00008B")
@Hidden 
attr DarkCyan = ("#008B8B")
@Hidden 
attr DarkGoldenRod = ("#B8860B")
@Hidden 
attr DarkGray = ("#A9A9A9")
@Hidden 
attr DarkGrey = ("#A9A9A9")
@Hidden 
attr DarkGreen = ("#006400")
@Hidden 
attr DarkKhaki = ("#BDB76B")
@Hidden 
attr DarkMagenta = ("#8B008B")
@Hidden 
attr DarkOliveGreen = ("#556B2F")
@Hidden 
attr DarkOrange = ("#FF8C00")
@Hidden 
attr DarkOrchid = ("#9932CC")
@Hidden 
attr DarkRed = ("#8B0000")
@Hidden 
attr DarkSeaGreen = ("#8FBC8F")
@Hidden 
attr DarkSlateBlue = ("#483D8B")
@Hidden 
attr DarkSlateGray = ("#2F4F4F")
@Hidden 
attr DarkSlateGrey = ("#2F4F4F")
@Hidden 
attr DarkTurquoise = ("#00CED1")
@Hidden 
attr DarkViolet = ("#9400D3")
@Hidden
attr DeepPink = ("#FF1493")
@Hidden
attr DeepSkyBlue = ("#00BFFF")
@Hidden 
attr DimGray = ("#696969")
@Hidden 
attr DimGrey = ("#696969")
@Hidden 
attr DodgerBlue = ("#1E90FF")
@Hidden 
attr FireBrick = ("#B22222")
@Hidden 
attr ForestGreen = ("#228B22")
@Hidden 
attr Fuchsia = ("#FF00FF")
@Hidden 
attr Gold = ("#FFD700")
@Hidden 
attr GoldenRod = ("#DAA520")
@Hidden 
attr Gray = ("#808080")
@Hidden 
attr Grey = ("#808080")
@Hidden 
attr Green = ("#008000")
@Hidden 
attr GreenYellow = ("#ADFF2F")
@Hidden 
attr HotPink = ("#FF69B4")
@Hidden 
attr IndianRed = ("#CD5C5C")
@Hidden 
attr Indigo = ("#4B0082")
@Hidden 
attr Khaki = ("#F0E68C")
@Hidden 
attr LawnGreen = ("#7CFC00")
@Hidden 
attr LemonChiffon = ("#FFFACD")
@Hidden 
attr LightBlue = ("#ADD8E6")
@Hidden 
attr LightCoral = ("#F08080")
@Hidden 
attr LightGray = ("#D3D3D3")
@Hidden 
attr LightGrey = ("#D3D3D3")
@Hidden 
attr LightGreen = ("#90EE90")
@Hidden 
attr LightPink = ("#FFB6C1")
@Hidden 
attr LightSalmon = ("#FFA07A")
@Hidden 
attr LightSeaGreen = ("#20B2AA")
@Hidden 
attr LightSkyBlue = ("#87CEFA")
@Hidden 
attr LightSlateGray = ("#778899")
@Hidden 
attr LightSlateGrey = ("#778899")
@Hidden 
attr LightSteelBlue = ("#B0C4DE")
@Hidden 
attr Lime = ("#00FF00")
@Hidden 
attr LimeGreen = ("#32CD32")
@Hidden 
attr Magenta = ("#FF00FF")
@Hidden 
attr Maroon = ("#800000")
@Hidden 
attr MediumAquaMarine = ("#66CDAA")
@Hidden 
attr MediumBlue = ("#0000CD")
@Hidden 
attr MediumOrchid = ("#BA55D3")
@Hidden 
attr MediumPurple = ("#9370DB")
@Hidden 
attr MediumSeaGreen = ("#3CB371")
@Hidden 
attr MediumSlateBlue = ("#7B68EE")
@Hidden 
attr MediumSpringGreen = ("#00FA9A")
@Hidden 
attr MediumTurquoise = ("#48D1CC")
@Hidden 
attr MediumVioletRed = ("#C71585")
@Hidden 
attr MidnightBlue = ("#191970")
@Hidden 
attr Moccasin = ("#FFE4B5")
@Hidden 
attr NavajoWhite = ("#FFDEAD")
@Hidden 
attr Navy = ("#000080")
@Hidden 
attr Olive = ("#808000")
@Hidden 
attr OliveDrab = ("#6B8E23")
@Hidden 
attr Orange = ("#FFA500")
@Hidden 
attr OrangeRed = ("#FF4500")
@Hidden 
attr Orchid = ("#DA70D6")
@Hidden 
attr PaleGoldenRod = ("#EEE8AA")
@Hidden 
attr PaleGreen = ("#98FB98")
@Hidden 
attr PaleTurquoise = ("#AFEEEE")
@Hidden 
attr PaleVioletRed = ("#DB7093")
@Hidden 
attr Peru = ("#CD853F")
@Hidden 
attr Pink = ("#FFC0CB")
@Hidden 
attr Plum = ("#DDA0DD")
@Hidden 
attr PowderBlue = ("#B0E0E6")
@Hidden 
attr Purple = ("#800080")
@Hidden 
attr RebeccaPurple = ("#663399")
@Hidden 
attr Red = ("#FF0000")
@Hidden 
attr RosyBrown = ("#BC8F8F")
@Hidden 
attr RoyalBlue = ("#4169E1")
@Hidden 
attr SaddleBrown = ("#8B4513")
@Hidden 
attr Salmon = ("#FA8072")
@Hidden 
attr SandyBrown = ("#F4A460")
@Hidden 
attr SeaGreen = ("#2E8B57")
@Hidden 
attr Sienna = ("#A0522D")
@Hidden 
attr Silver = ("#C0C0C0")
@Hidden 
attr SkyBlue = ("#87CEEB")
@Hidden 
attr SlateBlue = ("#6A5ACD")
@Hidden 
attr SlateGray = ("#708090")
@Hidden 
attr SlateGrey = ("#708090")
@Hidden 
attr SpringGreen = ("#00FF7F")
@Hidden 
attr SteelBlue = ("#4682B4")
@Hidden 
attr Tan = ("#D2B48C")
@Hidden 
attr Teal = ("#008080")
@Hidden 
attr Thistle = ("#D8BFD8")
@Hidden 
attr Tomato = ("#FF6347")
@Hidden 
attr Turquoise = ("#40E0D0")
@Hidden 
attr Violet = ("#EE82EE")
@Hidden 
attr Wheat = ("#F5DEB3")
@Hidden 
attr White = ("#FFFFFF")
@Hidden 
attr Yellow = ("#FFFF00")
@Hidden 
attr YellowGreen = ("#9ACD32"))

Leave a Reply

Your email address will not be published. Required fields are marked *