12
red : AnyNumber | ColorValue = ColorValue.off,
13
green : AnyNumber | ColorValue = ColorValue.off,
14
blue : AnyNumber | ColorValue = ColorValue.off
16
488
@red = ColorValue.new red
17
488
@green = ColorValue.new green
18
488
@blue = ColorValue.new blue
21
# Accepts a string like "#RRGGBB", returns a new Color. Raises an exception
22
# if the string is not in that format.
23
def self.from_s(string : String) : Color
24
4
unless string[0] == '#'
25
1
raise ArgumentError.new(
26
"invalid character in color string at position 0: #{string[0]}"
30
red: ColorValue.new(string[1..2]),
31
green: ColorValue.new(string[3..4]),
32
blue: ColorValue.new(string[5..6])
40
# A `Color` with `@red` set to the given value and the other colors off.
41
def self.red(intensity : AnyNumber | ColorValue = ColorValue.full)
42
2
self.new red: ColorValue.new intensity
45
# A `Color` with `@blue` set to the given value and the other colors off.
46
def self.blue(intensity : AnyNumber | ColorValue = ColorValue.full)
47
2
self.new blue: ColorValue.new intensity
50
# A `Color` with `@green` set to the given value and the other colors off.
51
def self.green(intensity : AnyNumber | ColorValue = ColorValue.full)
52
2
self.new green: ColorValue.new intensity
65
# A `Color` with all values set to the maximum.
67
2
self.grey ColorValue.max
70
# A `Color` where each primary color's value is equal.
71
def self.grey(intensity : AnyNumber | ColorValue = ColorValue.new(0x88))
72
4
intensity = ColorValue.new intensity
73
4
self.new(red: intensity, blue: intensity, green: intensity)
77
def self.gray(intensity : AnyNumber | ColorValue = ColorValue.new(0x88))
81
# Return the given text as a colorized value for display in terminals.
82
def colorize(text : String)
84
Colorize::ColorRGB.new(
92
# Return the standard `#XXXXXX` hexadecimal representation of this `Color`
94
3
"#" + @red.to_s + @green.to_s + @blue.to_s
102
1
builder.string to_s
105
def self.new(pull parser : JSON::PullParser)
106
1
self.from_s parser.read_string