20
20
import UIKit
21
21
import CoreGraphics
22
22
23
- /// A C4Color object whose RGB value is 0, 0, 0 and whose alpha value is 1.0.
24
- public let black = C4Color ( red: 0.0 , green: 0.0 , blue: 0.0 , alpha: 1.0 )
25
- /// A C4Color object whose RGB value is 0.33, 0.33, 0.33 and whose alpha value is 1.0.
26
- public let darkGray = C4Color ( red: 1.0 / 3.0 , green: 1.0 / 3.0 , blue: 1.0 / 3.0 , alpha: 1.0 )
27
- /// A C4Color object whose RGB value is 0.66, 0.66, 0.66 and whose alpha value is 1.0.
28
- public let lightGray = C4Color ( red: 2.0 / 3.0 , green: 2.0 / 3.0 , blue: 2.0 / 3.0 , alpha: 1.0 )
29
- /// A C4Color object whose RGB value is 1.0, 1.0, 1.0 and whose alpha value is 1.0.
30
- public let white = C4Color ( red: 1.0 , green: 1.0 , blue: 1.0 , alpha: 1.0 )
31
- /// A C4Color object whose RGB value is 0.5, 0.5, 0.5 and whose alpha value is 1.0.
32
- public let gray = C4Color ( red: 0.5 , green: 0.5 , blue: 0.5 , alpha: 1.0 )
33
- /// A C4Color object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
34
- public let red = C4Color ( red: 1.0 , green: 0.0 , blue: 0.0 , alpha: 1.0 )
35
- /// A C4Color object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
36
- public let green = C4Color ( red: 0.0 , green: 1.0 , blue: 0.0 , alpha: 1.0 )
37
- /// A C4Color object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
38
- public let blue = C4Color ( red: 0.0 , green: 0.0 , blue: 1.0 , alpha: 1.0 )
39
- /// A C4Color object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
40
- public let cyan = C4Color ( red: 0.0 , green: 1.0 , blue: 1.0 , alpha: 1.0 )
41
- /// A C4Color object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
42
- public let yellow = C4Color ( red: 1.0 , green: 1.0 , blue: 0.0 , alpha: 1.0 )
43
- /// A C4Color object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
44
- public let magenta = C4Color ( red: 1.0 , green: 0.0 , blue: 1.0 , alpha: 1.0 )
45
- /// A C4Color object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
46
- public let orange = C4Color ( red: 1.0 , green: 0.5 , blue: 0.0 , alpha: 1.0 )
47
- /// A C4Color object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
48
- public let purple = C4Color ( red: 0.5 , green: 0.0 , blue: 0.5 , alpha: 1.0 )
49
- /// A C4Color object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
50
- public let brown = C4Color ( red: 0.6 , green: 0.4 , blue: 0.2 , alpha: 1.0 )
51
- /// A C4Color object whose RGB value is 0.0, 0.0, 0.0 and whose alpha value is 0.0.
52
- public let clear = C4Color ( red: 0.0 , green: 0.0 , blue: 0.0 , alpha: 0.0 )
23
+ /// A Color object whose RGB value is 0, 0, 0 and whose alpha value is 1.0.
24
+ public let black = Color ( red: 0.0 , green: 0.0 , blue: 0.0 , alpha: 1.0 )
25
+ /// A Color object whose RGB value is 0.33, 0.33, 0.33 and whose alpha value is 1.0.
26
+ public let darkGray = Color ( red: 1.0 / 3.0 , green: 1.0 / 3.0 , blue: 1.0 / 3.0 , alpha: 1.0 )
27
+ /// A Color object whose RGB value is 0.66, 0.66, 0.66 and whose alpha value is 1.0.
28
+ public let lightGray = Color ( red: 2.0 / 3.0 , green: 2.0 / 3.0 , blue: 2.0 / 3.0 , alpha: 1.0 )
29
+ /// A Color object whose RGB value is 1.0, 1.0, 1.0 and whose alpha value is 1.0.
30
+ public let white = Color ( red: 1.0 , green: 1.0 , blue: 1.0 , alpha: 1.0 )
31
+ /// A Color object whose RGB value is 0.5, 0.5, 0.5 and whose alpha value is 1.0.
32
+ public let gray = Color ( red: 0.5 , green: 0.5 , blue: 0.5 , alpha: 1.0 )
33
+ /// A Color object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
34
+ public let red = Color ( red: 1.0 , green: 0.0 , blue: 0.0 , alpha: 1.0 )
35
+ /// A Color object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
36
+ public let green = Color ( red: 0.0 , green: 1.0 , blue: 0.0 , alpha: 1.0 )
37
+ /// A Color object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
38
+ public let blue = Color ( red: 0.0 , green: 0.0 , blue: 1.0 , alpha: 1.0 )
39
+ /// A Color object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
40
+ public let cyan = Color ( red: 0.0 , green: 1.0 , blue: 1.0 , alpha: 1.0 )
41
+ /// A Color object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
42
+ public let yellow = Color ( red: 1.0 , green: 1.0 , blue: 0.0 , alpha: 1.0 )
43
+ /// A Color object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
44
+ public let magenta = Color ( red: 1.0 , green: 0.0 , blue: 1.0 , alpha: 1.0 )
45
+ /// A Color object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
46
+ public let orange = Color ( red: 1.0 , green: 0.5 , blue: 0.0 , alpha: 1.0 )
47
+ /// A Color object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
48
+ public let purple = Color ( red: 0.5 , green: 0.0 , blue: 0.5 , alpha: 1.0 )
49
+ /// A Color object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
50
+ public let brown = Color ( red: 0.6 , green: 0.4 , blue: 0.2 , alpha: 1.0 )
51
+ /// A Color object whose RGB value is 0.0, 0.0, 0.0 and whose alpha value is 0.0.
52
+ public let clear = Color ( red: 0.0 , green: 0.0 , blue: 0.0 , alpha: 0.0 )
53
53
54
- ///A C4Color object whose RGB value is 1.0, 0.0, 0.475 and whose alpha value is 1.0.
55
- public let C4Pink = C4Color ( red: 1.0 , green: 0.0 , blue: 0.475 , alpha: 1.0 )
56
- ///A C4Color object whose RGB value is 0.098, 0.271, 1.0 and whose alpha value is 1.0.
57
- public let C4Blue = C4Color ( red: 0.098 , green: 0.271 , blue: 1.0 , alpha: 1.0 )
58
- ///A C4Color object whose RGB value is 0.0, 0.0, 0.541 and whose alpha value is 1.0.
59
- public let C4Purple = C4Color ( red: 0.0 , green: 0.0 , blue: 0.541 , alpha: 1.0 )
60
- ///A C4Color object whose RGB value is 0.98, 0.98, 0.98 and whose alpha value is 1.0.
61
- public let C4Grey = C4Color ( red: 0.98 , green: 0.98 , blue: 0.98 , alpha: 1.0 )
54
+ ///A Color object whose RGB value is 1.0, 0.0, 0.475 and whose alpha value is 1.0.
55
+ public let C4Pink = Color ( red: 1.0 , green: 0.0 , blue: 0.475 , alpha: 1.0 )
56
+ ///A Color object whose RGB value is 0.098, 0.271, 1.0 and whose alpha value is 1.0.
57
+ public let C4Blue = Color ( red: 0.098 , green: 0.271 , blue: 1.0 , alpha: 1.0 )
58
+ ///A Color object whose RGB value is 0.0, 0.0, 0.541 and whose alpha value is 1.0.
59
+ public let C4Purple = Color ( red: 0.0 , green: 0.0 , blue: 0.541 , alpha: 1.0 )
60
+ ///A Color object whose RGB value is 0.98, 0.98, 0.98 and whose alpha value is 1.0.
61
+ public let C4Grey = Color ( red: 0.98 , green: 0.98 , blue: 0.98 , alpha: 1.0 )
62
62
63
- /// This document describes the C4Color object which represents color and sometimes opacity (alpha value). You can use C4Color
64
- /// objects to store color data, and pass them between various C4 objects such as C4Shape, C4Image , etc.
63
+ /// This document describes the Color object which represents color and sometimes opacity (alpha value). You can use Color
64
+ /// objects to store color data, and pass them between various C4 objects such as Shape, Image , etc.
65
65
///
66
- /// C4Color internally wraps a CGColorSpaceRef called colorSpace, as well as a CGColorRef. From these two objects C4Color is able to
67
- /// properly maintain color data and convert it to / from other color objects such as UIColor, CIColor, C4Color , etc.
68
- public class C4Color {
66
+ /// Color internally wraps a CGColorSpaceRef called colorSpace, as well as a CGColorRef. From these two objects Color is able to
67
+ /// properly maintain color data and convert it to / from other color objects such as UIColor, CIColor, Color , etc.
68
+ public class Color {
69
69
internal var colorSpace : CGColorSpaceRef
70
70
internal var internalColor : CGColorRef
71
71
72
72
/// Initializes and returns a new color object. Defaults to black with 0 opacity (i.e. clear).
73
73
/// ````
74
- /// let c = C4Color ()
74
+ /// let c = Color ()
75
75
/// ````
76
76
public init ( ) {
77
77
colorSpace = CGColorSpaceCreateDeviceRGB ( ) !
78
78
internalColor = CGColorCreate ( colorSpace, [ 0 , 0 , 0 , 0 ] ) !
79
79
}
80
80
81
- /// Initializes and returns a new C4Color object based on specified color values.
81
+ /// Initializes and returns a new Color object based on specified color values.
82
82
/// ````
83
- /// let c = C4Color (red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
83
+ /// let c = Color (red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
84
84
/// ````
85
85
/// - parameter red: The red value for the new color [0.0 ... 1.0]
86
86
/// - parameter green: The green value for the new color [0.0 ... 1.0]
@@ -91,37 +91,37 @@ public class C4Color {
91
91
internalColor = CGColorCreate ( colorSpace, [ CGFloat ( red) , CGFloat ( green) , CGFloat ( blue) , CGFloat ( alpha) ] ) !
92
92
}
93
93
94
- /// Initializes and returns a new C4Color object based on a provided CGColor object.
94
+ /// Initializes and returns a new Color object based on a provided CGColor object.
95
95
/// ````
96
- /// let c = C4Color (UIColor.redColor().CGColor)
96
+ /// let c = Color (UIColor.redColor().CGColor)
97
97
/// ````
98
- /// - parameter color: A CGColor object that will be used to create a new C4Color .
98
+ /// - parameter color: A CGColor object that will be used to create a new Color .
99
99
public init ( _ color: CGColorRef ) {
100
100
colorSpace = CGColorSpaceCreateDeviceRGB ( ) !
101
101
internalColor = color
102
102
}
103
103
104
- /// Initializes and returns a new C4Color object based on a provided UIColor object.
104
+ /// Initializes and returns a new Color object based on a provided UIColor object.
105
105
/// ````
106
- /// let c = C4Color (UIColor.redColor())
106
+ /// let c = Color (UIColor.redColor())
107
107
/// ````
108
- /// - parameter color: A UIColor object whose components will be extrated to create a new C4Color .
108
+ /// - parameter color: A UIColor object whose components will be extrated to create a new Color .
109
109
public convenience init ( _ color: UIColor ) {
110
110
self . init ( color. CGColor)
111
111
}
112
112
113
- /// Initializes and returns a new C4Color object made up of a repeating pattern based on a specified C4Image .
113
+ /// Initializes and returns a new Color object made up of a repeating pattern based on a specified Image .
114
114
/// ````
115
- /// let p = C4Color ("pattern")
115
+ /// let p = Color ("pattern")
116
116
/// ````
117
117
/// - parameter pattern: a String, the name of an image to use as a pattern.
118
118
public convenience init ( _ pattern: String ) {
119
119
self . init ( UIColor ( patternImage: UIImage ( named: pattern) !) )
120
120
}
121
121
122
- /// Initializes and returns a new C4Color object based on specified color values.
122
+ /// Initializes and returns a new Color object based on specified color values.
123
123
/// ````
124
- /// let c = C4Color (red: 255, green: 0, blue: 0, alpha: 255)
124
+ /// let c = Color (red: 255, green: 0, blue: 0, alpha: 255)
125
125
/// ````
126
126
/// - parameter red: The red value for the new color [0 ... 255]
127
127
/// - parameter green: The green value for the new color [0 ... 255]
@@ -131,10 +131,10 @@ public class C4Color {
131
131
self . init ( red: Double ( red) / 255.0 , green: Double ( green) / 255.0 , blue: Double ( blue) / 255.0 , alpha: alpha)
132
132
}
133
133
134
- /// Initializes and returns a new C4Color object based on a specified hex value.
134
+ /// Initializes and returns a new Color object based on a specified hex value.
135
135
/// Remember to precede with `0x` and include the alpha component at the end (i.e. 7th + 8th characters)
136
136
/// ````
137
- /// let c = C4Color (0xFF0000FF)
137
+ /// let c = Color (0xFF0000FF)
138
138
/// ````
139
139
/// - parameter hexValue: A color value expressed in hexadecimal.
140
140
public convenience init ( _ hexValue: UInt32 ) {
@@ -170,7 +170,7 @@ public class C4Color {
170
170
171
171
/// The value of the red component of the current color, [0.0 ... 1.0]
172
172
/// ````
173
- /// let c = C4Color ()
173
+ /// let c = Color ()
174
174
/// let redVal = c.red
175
175
/// ````
176
176
/// - returns: Double value in the range [0.0 ... 1.0]
@@ -185,7 +185,7 @@ public class C4Color {
185
185
186
186
/// The value of the green component of the current color
187
187
/// ````
188
- /// let c = C4Color ()
188
+ /// let c = Color ()
189
189
/// let greenVal = c.green
190
190
/// ````
191
191
/// - returns: Double value in the range [0.0 ... 1.0]
@@ -200,7 +200,7 @@ public class C4Color {
200
200
201
201
/// The value of the blue component of the current color
202
202
/// ````
203
- /// let c = C4Color ()
203
+ /// let c = Color ()
204
204
/// let blueVal = c.blue
205
205
/// ````
206
206
/// - returns: Double value in the range [0.0 ... 1.0]
@@ -215,7 +215,7 @@ public class C4Color {
215
215
216
216
/// The value of the alpha component of the current color.
217
217
/// ````
218
- /// let c = C4Color ()
218
+ /// let c = Color ()
219
219
/// let alphaVal = c.alpha
220
220
/// ````
221
221
/// - returns: Double value in the range [0.0 ... 1.0]
@@ -230,7 +230,7 @@ public class C4Color {
230
230
231
231
/// A CGColor representation of the current color.
232
232
/// ````
233
- /// let c = C4Color ()
233
+ /// let c = Color ()
234
234
/// let cg = c.CGColor
235
235
/// ````
236
236
/// - returns: CGColorRef object that matches the color's `internalColor` property
@@ -246,25 +246,25 @@ public class C4Color {
246
246
/// ````
247
247
/// - parameter alpha: The opacity value of the new UIColor object.
248
248
/// - returns: A new color with a modified alpha component.
249
- public func colorWithAlpha( alpha: Double ) -> C4Color {
250
- return C4Color ( red: red, green: green, blue: blue, alpha: alpha)
249
+ public func colorWithAlpha( alpha: Double ) -> Color {
250
+ return Color ( red: red, green: green, blue: blue, alpha: alpha)
251
251
}
252
252
}
253
253
254
254
// MARK: - Casting to UIColor and CIColor
255
255
256
256
public extension UIColor {
257
- /// Initializes a UIColor object from a C4Color object.
257
+ /// Initializes a UIColor object from a Color object.
258
258
/// - parameter color: The C4 color object.
259
- public convenience init ? ( _ color: C4Color ) {
259
+ public convenience init ? ( _ color: Color ) {
260
260
self . init ( CGColor: color. CGColor)
261
261
}
262
262
}
263
263
264
264
public extension CIColor {
265
- /// Initializes a CIColor object from a C4Color object.
265
+ /// Initializes a CIColor object from a Color object.
266
266
/// - parameter color: The C4 color object.
267
- public convenience init ( _ color: C4Color ) {
267
+ public convenience init ( _ color: Color ) {
268
268
self . init ( CGColor: color. CGColor)
269
269
}
270
270
}
0 commit comments