-
Notifications
You must be signed in to change notification settings - Fork 1
/
PRTools.xlam.HTMLColors.bas
235 lines (223 loc) · 8.63 KB
/
PRTools.xlam.HTMLColors.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Attribute VB_Name = "HTMLColors"
Option Explicit
Private ColorRef As scripting.Dictionary
Private Inited As Boolean
Private Reds As scripting.Dictionary
Private Greens As scripting.Dictionary
Private Blues As scripting.Dictionary
Public Sub test(r As Integer, g As Integer, b As Integer)
Dim c As Range, COl As HtmlColor
Set c = Selection.Cells(1, 1)
c.Interior.Color = RGB(r, g, b)
c.Value = "RGB(" & r & ", " & g & ", " & b & ")"
Set c = Selection.Cells(1, 2)
Set COl = Rgb2Color(RGB(r, g, b))
c.Value = COl.ToString()
c.Interior.Color = RGB(COl.Red, COl.Green, COl.Blue)
End Sub
Public Sub ttest(rr As Integer, gg As Integer, bb As Integer, stp As Integer)
Dim r As Integer, g As Integer, b As Integer
For r = rr - 10 * stp To rr + 10 * stp Step stp
For g = gg - 10 * stp To gg + 10 * stp Step stp
For b = bb - 10 * stp To bb + 10 * stp Step stp
test r, g, b
Selection.Cells(2, 1).Select
Next
Next
Next
End Sub
Private Function Rgb2ColorRaw(ByVal RGB As Long) As HtmlColor
Set Rgb2ColorRaw = New HtmlColor
Rgb2ColorRaw.Red = RGB Mod 256
RGB = Int(RGB / 256)
Rgb2ColorRaw.Green = RGB Mod 256
RGB = Int(RGB / 256)
Rgb2ColorRaw.Blue = RGB Mod 256
End Function
Public Function GetRGB(ByVal ColorName As String) As Long
Dim COl As HtmlColor
Init
If ColorRef.Exists(ColorName) Then
Set COl = ColorRef(ColorName)
GetRGB = RGB(COl.Red, COl.Green, COl.Blue)
Else
GetRGB = RGB(128, 128, 128)
End If
End Function
Private Function Rgb2Color(ByVal RGB As Long) As HtmlColor
Dim Searched As HtmlColor, COl As Variant
Dim Closest As Long, Distance As Long
Init
Set Searched = Rgb2ColorRaw(RGB)
Closest = -1
For Each COl In ColorRef.Items
Distance = (COl.Red - Searched.Red) ^ 2 _
+ (COl.Green - Searched.Green) ^ 2 _
+ (COl.Blue - Searched.Blue) ^ 2
' Debug.Print Distance, Closest, Col.ToString(),
If Closest > Distance Or Closest < 0 Then
Closest = Distance
Set Rgb2Color = COl
' Debug.Print "Closest",
If Closest = 0 Then Exit Function ' found exact!
End If
' Debug.Print
Next COl
End Function
Public Function Rgb2ColorName(ByVal RGB As Long) As String
Rgb2ColorName = Rgb2Color(RGB).Name
End Function
Private Sub AddColor(ByVal Name As String, ByVal Red As Integer, ByVal Green As Integer, ByVal Blue As Integer)
Dim COl As HtmlColor
Set COl = New HtmlColor
COl.Name = Name
COl.Red = Red
COl.Green = Green
COl.Blue = Blue
ColorRef.Add Name, COl
End Sub
Private Sub Init()
If ColorRef Is Nothing Then
Set ColorRef = New scripting.Dictionary
AddColor "Pink", 255, 192, 203
AddColor "LightPink", 255, 182, 193
AddColor "HotPink", 255, 105, 180
AddColor "DeepPink", 255, 20, 147
AddColor "PaleVioletRed", 219, 112, 147
AddColor "MediumVioletRed", 199, 21, 133
AddColor "LightSalmon", 255, 160, 122
AddColor "Salmon", 250, 128, 114
AddColor "DarkSalmon", 233, 150, 122
AddColor "LightCoral", 240, 128, 128
AddColor "IndianRed", 205, 92, 92
AddColor "Crimson", 220, 20, 60
AddColor "FireBrick", 178, 34, 34
AddColor "DarkRed", 139, 0, 0
AddColor "Red", 255, 0, 0
AddColor "OrangeRed", 255, 69, 0
AddColor "Tomato", 255, 99, 71
AddColor "Coral", 255, 127, 80
AddColor "DarkOrange", 255, 140, 0
AddColor "Orange", 255, 165, 0
AddColor "Yellow", 255, 255, 0
AddColor "LightYellow", 255, 255, 224
AddColor "LemonChiffon", 255, 250, 205
AddColor "LightGoldenrodYellow", 250, 250, 210
AddColor "PapayaWhip", 255, 239, 213
AddColor "Moccasin", 255, 228, 181
AddColor "PeachPuff", 255, 218, 185
AddColor "PaleGoldenrod", 238, 232, 170
AddColor "Khaki", 240, 230, 140
AddColor "DarkKhaki", 189, 183, 107
AddColor "Gold", 255, 215, 0
AddColor "Cornsilk", 255, 248, 220
AddColor "BlanchedAlmond", 255, 235, 205
AddColor "Bisque", 255, 228, 196
AddColor "NavajoWhite", 255, 222, 173
AddColor "Wheat", 245, 222, 179
AddColor "BurlyWood", 222, 184, 135
AddColor "Tan", 210, 180, 140
AddColor "RosyBrown", 188, 143, 143
AddColor "SandyBrown", 244, 164, 96
AddColor "Goldenrod", 218, 165, 32
AddColor "DarkGoldenrod", 184, 134, 11
AddColor "Peru", 205, 133, 63
AddColor "Chocolate", 210, 105, 30
AddColor "SaddleBrown", 139, 69, 19
AddColor "Sienna", 160, 82, 45
AddColor "Brown", 165, 42, 42
AddColor "Maroon", 128, 0, 0
AddColor "DarkOliveGreen", 85, 107, 47
AddColor "Olive", 128, 128, 0
AddColor "OliveDrab", 107, 142, 35
AddColor "YellowGreen", 154, 205, 50
AddColor "LimeGreen", 50, 205, 50
AddColor "Lime", 0, 255, 0
AddColor "LawnGreen", 124, 252, 0
AddColor "Chartreuse", 127, 255, 0
AddColor "GreenYellow", 173, 255, 47
AddColor "SpringGreen", 0, 255, 127
AddColor "MediumSpringGreen", 0, 250, 154
AddColor "LightGreen", 144, 238, 144
AddColor "PaleGreen", 152, 251, 152
AddColor "DarkSeaGreen", 143, 188, 143
AddColor "MediumSeaGreen", 60, 179, 113
AddColor "SeaGreen", 46, 139, 87
AddColor "ForestGreen", 34, 139, 34
AddColor "Green", 0, 128, 0
AddColor "DarkGreen", 0, 100, 0
AddColor "MediumAquamarine", 102, 205, 170
AddColor "Aqua", 0, 255, 255
AddColor "Cyan", 0, 255, 255
AddColor "LightCyan", 224, 255, 255
AddColor "PaleTurquoise", 175, 238, 238
AddColor "Aquamarine", 127, 255, 212
AddColor "Turquoise", 64, 224, 208
AddColor "MediumTurquoise", 72, 209, 204
AddColor "DarkTurquoise", 0, 206, 209
AddColor "LightSeaGreen", 32, 178, 170
AddColor "CadetBlue", 95, 158, 160
AddColor "DarkCyan", 0, 139, 139
AddColor "Teal", 0, 128, 128
AddColor "LightSteelBlue", 176, 196, 222
AddColor "PowderBlue", 176, 224, 230
AddColor "LightBlue", 173, 216, 230
AddColor "SkyBlue", 135, 206, 235
AddColor "LightSkyBlue", 135, 206, 250
AddColor "DeepSkyBlue", 0, 191, 255
AddColor "DodgerBlue", 30, 144, 255
AddColor "CornflowerBlue", 100, 149, 237
AddColor "SteelBlue", 70, 130, 180
AddColor "RoyalBlue", 65, 105, 225
AddColor "Blue", 0, 0, 255
AddColor "MediumBlue", 0, 0, 205
AddColor "DarkBlue", 0, 0, 139
AddColor "Navy", 0, 0, 128
AddColor "MidnightBlue", 25, 25, 112
AddColor "Lavender", 230, 230, 250
AddColor "Thistle", 216, 191, 216
AddColor "Plum", 221, 160, 221
AddColor "Violet", 238, 130, 238
AddColor "Orchid", 218, 112, 214
AddColor "Fuchsia", 255, 0, 255
AddColor "Magenta", 255, 0, 255
AddColor "MediumOrchid", 186, 85, 211
AddColor "MediumPurple", 147, 112, 219
AddColor "BlueViolet", 138, 43, 226
AddColor "DarkViolet", 148, 0, 211
AddColor "DarkOrchid", 153, 50, 204
AddColor "DarkMagenta", 139, 0, 139
AddColor "Purple", 128, 0, 128
AddColor "Indigo", 75, 0, 130
AddColor "DarkSlateBlue", 72, 61, 139
AddColor "SlateBlue", 106, 90, 205
AddColor "MediumSlateBlue", 123, 104, 238
AddColor "White", 255, 255, 255
AddColor "Snow", 255, 250, 250
AddColor "Honeydew", 240, 255, 240
AddColor "MintCream", 245, 255, 250
AddColor "Azure", 240, 255, 255
AddColor "AliceBlue", 240, 248, 255
AddColor "GhostWhite", 248, 248, 255
AddColor "WhiteSmoke", 245, 245, 245
AddColor "Seashell", 255, 245, 238
AddColor "Beige", 245, 245, 220
AddColor "OldLace", 253, 245, 230
AddColor "FloralWhite", 255, 250, 240
AddColor "Ivory", 255, 255, 240
AddColor "AntiqueWhite", 250, 235, 215
AddColor "Linen", 250, 240, 230
AddColor "LavenderBlush", 255, 240, 245
AddColor "MistyRose", 255, 228, 225
AddColor "Gainsboro", 220, 220, 220
AddColor "LightGrey", 211, 211, 211
AddColor "Silver", 192, 192, 192
AddColor "DarkGray", 169, 169, 169
AddColor "Gray", 128, 128, 128
AddColor "DimGray", 105, 105, 105
AddColor "LightSlateGray", 119, 136, 153
AddColor "SlateGray", 112, 128, 144
AddColor "DarkSlateGray", 47, 79, 79
AddColor "Black", 0, 0, 0
End If
End Sub