-
Notifications
You must be signed in to change notification settings - Fork 300
/
Colours.swift
868 lines (696 loc) · 22.1 KB
/
Colours.swift
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
//
// Colours.swift
// ColoursDemo
//
// Created by Ben Gordon on 12/27/14.
// Copyright (c) 2014 Ben Gordon. All rights reserved.
//
import Foundation
#if os(iOS) || os(tvOS)
import UIKit
public typealias Color = UIColor
#else
import AppKit
public typealias Color = NSColor
#endif
public extension Color {
// MARK: - Closure
typealias TransformBlock = (CGFloat) -> CGFloat
// MARK: - Enums
enum ColorScheme:Int {
case analagous = 0, monochromatic, triad, complementary
}
enum ColorFormulation:Int {
case rgba = 0, hsba, lab, cmyk
}
enum ColorDistance:Int {
case cie76 = 0, cie94, cie2000
}
enum ColorComparison:Int {
case darkness = 0, lightness, desaturated, saturated, red, green, blue
}
// MARK: - Color from Hex/RGBA/HSBA/CIE_LAB/CMYK
convenience init(hex: String) {
var rgbInt: UInt64 = 0
let newHex = hex.replacingOccurrences(of: "#", with: "")
let scanner = Scanner(string: newHex)
scanner.scanHexInt64(&rgbInt)
let r: CGFloat = CGFloat((rgbInt & 0xFF0000) >> 16)/255.0
let g: CGFloat = CGFloat((rgbInt & 0x00FF00) >> 8)/255.0
let b: CGFloat = CGFloat(rgbInt & 0x0000FF)/255.0
self.init(red: r, green: g, blue: b, alpha: 1.0)
}
convenience init(rgba: (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat)) {
self.init(red: rgba.r, green: rgba.g, blue: rgba.b, alpha: rgba.a)
}
convenience init(hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat)) {
self.init(hue: hsba.h, saturation: hsba.s, brightness: hsba.b, alpha: hsba.a)
}
convenience init(CIE_LAB: (l: CGFloat, a: CGFloat, b: CGFloat, alpha: CGFloat)) {
// Set Up
var Y = (CIE_LAB.l + 16.0)/116.0
var X = CIE_LAB.a/500 + Y
var Z = Y - CIE_LAB.b/200
// Transform XYZ
let deltaXYZ: TransformBlock = { k in
return (pow(k, 3.0) > 0.008856) ? pow(k, 3.0) : (k - 4/29.0)/7.787
}
X = deltaXYZ(X)*0.95047
Y = deltaXYZ(Y)*1.000
Z = deltaXYZ(Z)*1.08883
// Convert XYZ to RGB
let R = X*3.2406 + (Y * -1.5372) + (Z * -0.4986)
let G = (X * -0.9689) + Y*1.8758 + Z*0.0415
let B = X*0.0557 + (Y * -0.2040) + Z*1.0570
let deltaRGB: TransformBlock = { k in
return (k > 0.0031308) ? 1.055 * (pow(k, (1/2.4))) - 0.055 : k * 12.92
}
self.init(rgba: (deltaRGB(R), deltaRGB(G), deltaRGB(B), CIE_LAB.alpha))
}
convenience init(cmyk: (c: CGFloat, m: CGFloat, y: CGFloat, k: CGFloat)) {
let cmyTransform: TransformBlock = { x in
return x * (1 - cmyk.k) + cmyk.k
}
let C = cmyTransform(cmyk.c)
let M = cmyTransform(cmyk.m)
let Y = cmyTransform(cmyk.y)
self.init(rgba: (1 - C, 1 - M, 1 - Y, 1.0))
}
// MARK: - Color to Hex/RGBA/HSBA/CIE_LAB/CMYK
func hexString() -> String {
let rgbaT = rgba()
let r: Int = Int(rgbaT.r * 255)
let g: Int = Int(rgbaT.g * 255)
let b: Int = Int(rgbaT.b * 255)
let red = NSString(format: "%02x", r)
let green = NSString(format: "%02x", g)
let blue = NSString(format: "%02x", b)
return "#\(red)\(green)\(blue)"
}
func rgba() -> (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) {
let components = self.cgColor.components
let numberOfComponents = self.cgColor.numberOfComponents
switch numberOfComponents {
case 4:
return (components![0], components![1], components![2], components![3])
case 2:
return (components![0], components![0], components![0], components![1])
default:
// FIXME: Fallback to black
return (0, 0, 0, 1)
}
}
func hsba() -> (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) {
var h: CGFloat = 0
var s: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
if self.responds(to: #selector(UIColor.getHue(_:saturation:brightness:alpha:))) && self.cgColor.numberOfComponents == 4 {
self.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
}
return (h, s, b, a)
}
func CIE_LAB() -> (l: CGFloat, a: CGFloat, b: CGFloat, alpha: CGFloat) {
// Get XYZ
let xyzT = xyz()
let x = xyzT.x/95.047
let y = xyzT.y/100.000
let z = xyzT.z/108.883
// Transfrom XYZ to L*a*b
let deltaF: TransformBlock = { f in
if f > pow((6.0/29.0), 3.0) {
return pow(f, 1.0/3.0)
}
let expressionA: CGFloat = (1/3)
let expressionB: CGFloat = pow((29.0/6.0), 2.0)
let expressionC: CGFloat = 4/29.0
return expressionA * expressionB * f + expressionC
}
let X = deltaF(x)
let Y = deltaF(y)
let Z = deltaF(z)
let L = 116*Y - 16
let a = 500 * (X - Y)
let b = 200 * (Y - Z)
return (L, a, b, xyzT.alpha)
}
func xyz() -> (x: CGFloat, y: CGFloat, z: CGFloat, alpha: CGFloat) {
// Get RGBA values
let rgbaT = rgba()
// Transfrom values to XYZ
let deltaR: TransformBlock = { R in
return (R > 0.04045) ? pow((R + 0.055)/1.055, 2.40) : (R/12.92)
}
let R = deltaR(rgbaT.r)
let G = deltaR(rgbaT.g)
let B = deltaR(rgbaT.b)
let X = (R*41.24 + G*35.76 + B*18.05)
let Y = (R*21.26 + G*71.52 + B*7.22)
let Z = (R*1.93 + G*11.92 + B*95.05)
return (X, Y, Z, rgbaT.a)
}
func cmyk() -> (c: CGFloat, m: CGFloat, y: CGFloat, k: CGFloat) {
// Convert RGB to CMY
let rgbaT = rgba()
let C = 1 - rgbaT.r
let M = 1 - rgbaT.g
let Y = 1 - rgbaT.b
// Find K
let K = min(1, min(C, min(Y, M)))
if (K == 1) {
return (0, 0, 0, 1)
}
// Convert cmyk
let newCMYK: TransformBlock = { x in
return (x - K)/(1 - K)
}
return (newCMYK(C), newCMYK(M), newCMYK(Y), K)
}
// MARK: - Color Components
func red() -> CGFloat {
return rgba().r
}
func green() -> CGFloat {
return rgba().g
}
func blue() -> CGFloat {
return rgba().b
}
func alpha() -> CGFloat {
return rgba().a
}
func hue() -> CGFloat {
return hsba().h
}
func saturation() -> CGFloat {
return hsba().s
}
func brightness() -> CGFloat {
return hsba().b
}
func CIE_Lightness() -> CGFloat {
return CIE_LAB().l
}
func CIE_a() -> CGFloat {
return CIE_LAB().a
}
func CIE_b() -> CGFloat {
return CIE_LAB().b
}
func cyan() -> CGFloat {
return cmyk().c
}
func magenta() -> CGFloat {
return cmyk().m
}
func yellow() -> CGFloat {
return cmyk().y
}
func keyBlack() -> CGFloat {
return cmyk().k
}
// MARK: - Lighten/Darken Color
func lightenedColor(_ percentage: CGFloat) -> Color {
return modifiedColor(percentage + 1.0)
}
func darkenedColor(_ percentage: CGFloat) -> Color {
return modifiedColor(1.0 - percentage)
}
fileprivate func modifiedColor(_ percentage: CGFloat) -> Color {
let hsbaT = hsba()
return Color(hsba: (hsbaT.h, hsbaT.s, hsbaT.b * percentage, hsbaT.a))
}
// MARK: - Contrasting Color
func blackOrWhiteContrastingColor() -> Color {
let rgbaT = rgba()
let value = 1 - ((0.299 * rgbaT.r) + (0.587 * rgbaT.g) + (0.114 * rgbaT.b));
return value < 0.5 ? Color.black : Color.white
}
// MARK: - Complementary Color
func complementaryColor() -> Color {
let hsbaT = hsba()
let newH = Color.addDegree(180.0, staticDegree: hsbaT.h*360.0)
return Color(hsba: (newH, hsbaT.s, hsbaT.b, hsbaT.a))
}
// MARK: - Color Scheme
func colorScheme(_ type: ColorScheme) -> [Color] {
switch (type) {
case .analagous:
return Color.analgousColors(self.hsba())
case .monochromatic:
return Color.monochromaticColors(self.hsba())
case .triad:
return Color.triadColors(self.hsba())
default:
return Color.complementaryColors(self.hsba())
}
}
fileprivate class func analgousColors(_ hsbaT: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat)) -> [Color] {
return [Color(hsba: (self.addDegree(30, staticDegree: hsbaT.h*360)/360.0, hsbaT.s-0.05, hsbaT.b-0.1, hsbaT.a)),
Color(hsba: (self.addDegree(15, staticDegree: hsbaT.h*360)/360.0, hsbaT.s-0.05, hsbaT.b-0.05, hsbaT.a)),
Color(hsba: (self.addDegree(-15, staticDegree: hsbaT.h*360)/360.0, hsbaT.s-0.05, hsbaT.b-0.05, hsbaT.a)),
Color(hsba: (self.addDegree(-30, staticDegree: hsbaT.h*360)/360.0, hsbaT.s-0.05, hsbaT.b-0.1, hsbaT.a))]
}
fileprivate class func monochromaticColors(_ hsbaT: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat)) -> [Color] {
return [Color(hsba: (hsbaT.h, hsbaT.s/2, hsbaT.b/3, hsbaT.a)),
Color(hsba: (hsbaT.h, hsbaT.s, hsbaT.b/2, hsbaT.a)),
Color(hsba: (hsbaT.h, hsbaT.s/3, 2*hsbaT.b/3, hsbaT.a)),
Color(hsba: (hsbaT.h, hsbaT.s, 4*hsbaT.b/5, hsbaT.a))]
}
fileprivate class func triadColors(_ hsbaT: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat)) -> [Color] {
return [Color(hsba: (self.addDegree(120, staticDegree: hsbaT.h*360)/360.0, 2*hsbaT.s/3, hsbaT.b-0.05, hsbaT.a)),
Color(hsba: (self.addDegree(120, staticDegree: hsbaT.h*360)/360.0, hsbaT.s, hsbaT.b, hsbaT.a)),
Color(hsba: (self.addDegree(240, staticDegree: hsbaT.h*360)/360.0, hsbaT.s, hsbaT.b, hsbaT.a)),
Color(hsba: (self.addDegree(240, staticDegree: hsbaT.h*360)/360.0, 2*hsbaT.s/3, hsbaT.b-0.05, hsbaT.a))]
}
fileprivate class func complementaryColors(_ hsbaT: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat)) -> [Color] {
return [Color(hsba: (hsbaT.h, hsbaT.s, 4*hsbaT.b/5, hsbaT.a)),
Color(hsba: (hsbaT.h, 5*hsbaT.s/7, hsbaT.b, hsbaT.a)),
Color(hsba: (self.addDegree(180, staticDegree: hsbaT.h*360)/360.0, hsbaT.s, hsbaT.b, hsbaT.a)),
Color(hsba: (self.addDegree(180, staticDegree: hsbaT.h*360)/360.0, 5*hsbaT.s/7, hsbaT.b, hsbaT.a))]
}
// MARK: - Predefined Colors
// MARK: -
// MARK: System Colors
class func infoBlueColor() -> Color
{
return self.colorWith(47, G:112, B:225, A:1.0)
}
class func successColor() -> Color
{
return self.colorWith(83, G:215, B:106, A:1.0)
}
class func warningColor() -> Color
{
return self.colorWith(221, G:170, B:59, A:1.0)
}
class func dangerColor() -> Color
{
return self.colorWith(229, G:0, B:15, A:1.0)
}
// MARK: Whites
class func antiqueWhiteColor() -> Color
{
return self.colorWith(250, G:235, B:215, A:1.0)
}
class func oldLaceColor() -> Color
{
return self.colorWith(253, G:245, B:230, A:1.0)
}
class func ivoryColor() -> Color
{
return self.colorWith(255, G:255, B:240, A:1.0)
}
class func seashellColor() -> Color
{
return self.colorWith(255, G:245, B:238, A:1.0)
}
class func ghostWhiteColor() -> Color
{
return self.colorWith(248, G:248, B:255, A:1.0)
}
class func snowColor() -> Color
{
return self.colorWith(255, G:250, B:250, A:1.0)
}
class func linenColor() -> Color
{
return self.colorWith(250, G:240, B:230, A:1.0)
}
// MARK: Grays
class func black25PercentColor() -> Color
{
return Color(white:0.25, alpha:1.0)
}
class func black50PercentColor() -> Color
{
return Color(white:0.5, alpha:1.0)
}
class func black75PercentColor() -> Color
{
return Color(white:0.75, alpha:1.0)
}
class func warmGrayColor() -> Color
{
return self.colorWith(133, G:117, B:112, A:1.0)
}
class func coolGrayColor() -> Color
{
return self.colorWith(118, G:122, B:133, A:1.0)
}
class func charcoalColor() -> Color
{
return self.colorWith(34, G:34, B:34, A:1.0)
}
// MARK: Blues
class func tealColor() -> Color
{
return self.colorWith(28, G:160, B:170, A:1.0)
}
class func steelBlueColor() -> Color
{
return self.colorWith(103, G:153, B:170, A:1.0)
}
class func robinEggColor() -> Color
{
return self.colorWith(141, G:218, B:247, A:1.0)
}
class func pastelBlueColor() -> Color
{
return self.colorWith(99, G:161, B:247, A:1.0)
}
class func turquoiseColor() -> Color
{
return self.colorWith(112, G:219, B:219, A:1.0)
}
class func skyBlueColor() -> Color
{
return self.colorWith(0, G:178, B:238, A:1.0)
}
class func indigoColor() -> Color
{
return self.colorWith(13, G:79, B:139, A:1.0)
}
class func denimColor() -> Color
{
return self.colorWith(67, G:114, B:170, A:1.0)
}
class func blueberryColor() -> Color
{
return self.colorWith(89, G:113, B:173, A:1.0)
}
class func cornflowerColor() -> Color
{
return self.colorWith(100, G:149, B:237, A:1.0)
}
class func babyBlueColor() -> Color
{
return self.colorWith(190, G:220, B:230, A:1.0)
}
class func midnightBlueColor() -> Color
{
return self.colorWith(13, G:26, B:35, A:1.0)
}
class func fadedBlueColor() -> Color
{
return self.colorWith(23, G:137, B:155, A:1.0)
}
class func icebergColor() -> Color
{
return self.colorWith(200, G:213, B:219, A:1.0)
}
class func waveColor() -> Color
{
return self.colorWith(102, G:169, B:251, A:1.0)
}
// MARK: Greens
class func emeraldColor() -> Color
{
return self.colorWith(1, G:152, B:117, A:1.0)
}
class func grassColor() -> Color
{
return self.colorWith(99, G:214, B:74, A:1.0)
}
class func pastelGreenColor() -> Color
{
return self.colorWith(126, G:242, B:124, A:1.0)
}
class func seafoamColor() -> Color
{
return self.colorWith(77, G:226, B:140, A:1.0)
}
class func paleGreenColor() -> Color
{
return self.colorWith(176, G:226, B:172, A:1.0)
}
class func cactusGreenColor() -> Color
{
return self.colorWith(99, G:111, B:87, A:1.0)
}
class func chartreuseColor() -> Color
{
return self.colorWith(69, G:139, B:0, A:1.0)
}
class func hollyGreenColor() -> Color
{
return self.colorWith(32, G:87, B:14, A:1.0)
}
class func oliveColor() -> Color
{
return self.colorWith(91, G:114, B:34, A:1.0)
}
class func oliveDrabColor() -> Color
{
return self.colorWith(107, G:142, B:35, A:1.0)
}
class func moneyGreenColor() -> Color
{
return self.colorWith(134, G:198, B:124, A:1.0)
}
class func honeydewColor() -> Color
{
return self.colorWith(216, G:255, B:231, A:1.0)
}
class func limeColor() -> Color
{
return self.colorWith(56, G:237, B:56, A:1.0)
}
class func cardTableColor() -> Color
{
return self.colorWith(87, G:121, B:107, A:1.0)
}
// MARK: Reds
class func salmonColor() -> Color
{
return self.colorWith(233, G:87, B:95, A:1.0)
}
class func brickRedColor() -> Color
{
return self.colorWith(151, G:27, B:16, A:1.0)
}
class func easterPinkColor() -> Color
{
return self.colorWith(241, G:167, B:162, A:1.0)
}
class func grapefruitColor() -> Color
{
return self.colorWith(228, G:31, B:54, A:1.0)
}
class func pinkColor() -> Color
{
return self.colorWith(255, G:95, B:154, A:1.0)
}
class func indianRedColor() -> Color
{
return self.colorWith(205, G:92, B:92, A:1.0)
}
class func strawberryColor() -> Color
{
return self.colorWith(190, G:38, B:37, A:1.0)
}
class func coralColor() -> Color
{
return self.colorWith(240, G:128, B:128, A:1.0)
}
class func maroonColor() -> Color
{
return self.colorWith(80, G:4, B:28, A:1.0)
}
class func watermelonColor() -> Color
{
return self.colorWith(242, G:71, B:63, A:1.0)
}
class func tomatoColor() -> Color
{
return self.colorWith(255, G:99, B:71, A:1.0)
}
class func pinkLipstickColor() -> Color
{
return self.colorWith(255, G:105, B:180, A:1.0)
}
class func paleRoseColor() -> Color
{
return self.colorWith(255, G:228, B:225, A:1.0)
}
class func crimsonColor() -> Color
{
return self.colorWith(187, G:18, B:36, A:1.0)
}
// MARK: Purples
class func eggplantColor() -> Color
{
return self.colorWith(105, G:5, B:98, A:1.0)
}
class func pastelPurpleColor() -> Color
{
return self.colorWith(207, G:100, B:235, A:1.0)
}
class func palePurpleColor() -> Color
{
return self.colorWith(229, G:180, B:235, A:1.0)
}
class func coolPurpleColor() -> Color
{
return self.colorWith(140, G:93, B:228, A:1.0)
}
class func violetColor() -> Color
{
return self.colorWith(191, G:95, B:255, A:1.0)
}
class func plumColor() -> Color
{
return self.colorWith(139, G:102, B:139, A:1.0)
}
class func lavenderColor() -> Color
{
return self.colorWith(204, G:153, B:204, A:1.0)
}
class func raspberryColor() -> Color
{
return self.colorWith(135, G:38, B:87, A:1.0)
}
class func fuschiaColor() -> Color
{
return self.colorWith(255, G:20, B:147, A:1.0)
}
class func grapeColor() -> Color
{
return self.colorWith(54, G:11, B:88, A:1.0)
}
class func periwinkleColor() -> Color
{
return self.colorWith(135, G:159, B:237, A:1.0)
}
class func orchidColor() -> Color
{
return self.colorWith(218, G:112, B:214, A:1.0)
}
// MARK: Yellows
class func goldenrodColor() -> Color
{
return self.colorWith(215, G:170, B:51, A:1.0)
}
class func yellowGreenColor() -> Color
{
return self.colorWith(192, G:242, B:39, A:1.0)
}
class func bananaColor() -> Color
{
return self.colorWith(229, G:227, B:58, A:1.0)
}
class func mustardColor() -> Color
{
return self.colorWith(205, G:171, B:45, A:1.0)
}
class func buttermilkColor() -> Color
{
return self.colorWith(254, G:241, B:181, A:1.0)
}
class func goldColor() -> Color
{
return self.colorWith(139, G:117, B:18, A:1.0)
}
class func creamColor() -> Color
{
return self.colorWith(240, G:226, B:187, A:1.0)
}
class func lightCreamColor() -> Color
{
return self.colorWith(240, G:238, B:215, A:1.0)
}
class func wheatColor() -> Color
{
return self.colorWith(240, G:238, B:215, A:1.0)
}
class func beigeColor() -> Color
{
return self.colorWith(245, G:245, B:220, A:1.0)
}
// MARK: Oranges
class func peachColor() -> Color
{
return self.colorWith(242, G:187, B:97, A:1.0)
}
class func burntOrangeColor() -> Color
{
return self.colorWith(184, G:102, B:37, A:1.0)
}
class func pastelOrangeColor() -> Color
{
return self.colorWith(248, G:197, B:143, A:1.0)
}
class func cantaloupeColor() -> Color
{
return self.colorWith(250, G:154, B:79, A:1.0)
}
class func carrotColor() -> Color
{
return self.colorWith(237, G:145, B:33, A:1.0)
}
class func mandarinColor() -> Color
{
return self.colorWith(247, G:145, B:55, A:1.0)
}
// MARK: Browns
class func chiliPowderColor() -> Color
{
return self.colorWith(199, G:63, B:23, A:1.0)
}
class func burntSiennaColor() -> Color
{
return self.colorWith(138, G:54, B:15, A:1.0)
}
class func chocolateColor() -> Color
{
return self.colorWith(94, G:38, B:5, A:1.0)
}
class func coffeeColor() -> Color
{
return self.colorWith(141, G:60, B:15, A:1.0)
}
class func cinnamonColor() -> Color
{
return self.colorWith(123, G:63, B:9, A:1.0)
}
class func almondColor() -> Color
{
return self.colorWith(196, G:142, B:72, A:1.0)
}
class func eggshellColor() -> Color
{
return self.colorWith(252, G:230, B:201, A:1.0)
}
class func sandColor() -> Color
{
return self.colorWith(222, G:182, B:151, A:1.0)
}
class func mudColor() -> Color
{
return self.colorWith(70, G:45, B:29, A:1.0)
}
class func siennaColor() -> Color
{
return self.colorWith(160, G:82, B:45, A:1.0)
}
class func dustColor() -> Color
{
return self.colorWith(236, G:214, B:197, A:1.0)
}
// MARK: - Private Helpers
fileprivate class func colorWith(_ R: CGFloat, G: CGFloat, B: CGFloat, A: CGFloat) -> Color {
return Color(rgba: (R/255.0, G/255.0, B/255.0, A))
}
fileprivate class func addDegree(_ addDegree: CGFloat, staticDegree: CGFloat) -> CGFloat {
let s = staticDegree + addDegree;
if (s > 360) {
return s - 360;
}
else if (s < 0) {
return -1 * s;
}
else {
return s;
}
}
}