-
Notifications
You must be signed in to change notification settings - Fork 64
/
Color.txt
114 lines (95 loc) · 3.69 KB
/
Color.txt
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
*vital/Color.txt* RGB/HSL/terminal code conversion library
Maintainer: tyru <tyru.exe@gmail.com>
==============================================================================
CONTENTS *Vital.Color-contents*
INTRODUCTION |Vital.Color-introduction|
INTERFACE |Vital.Color-interface|
FUNCTIONS |Vital.Color-functions|
TODO |Vital.Color-todo|
==============================================================================
INTRODUCTION *Vital.Color-introduction*
*Vital.Color* is a color conversion library between RGB/HSL/terminal code.
==============================================================================
INTERFACE *Vital.Color-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Color-functions*
parse({str}) *Vital.Color.parse()*
Parses various color text formats and creates |Vital.Color-Color-object|.
Supported format is:
* Hex RGB format
* e.g. `#FFF`
* e.g. `#000000`
* CSS RGB format
* e.g. `rgb(255,255,255)`
* e.g. `rgb(100%,0%,0%)`
* CSS HSL format
* e.g. `hsl(0,50%,100%)`
* `%` is mandatory
* Color name
* See $VIMRUNTIME/rgb.txt for color names
>
let c1 = s:Color.parse('#012')
let c2 = s:Color.parse('#c0ffee')
let c3 = s:Color.parse('rgb(100,100,100)')
let c3 = s:Color.parse('rgb(0%,100%,100%)')
let c4 = s:Color.parse('hsl(0,50%,100%)')
let c5 = s:Color.parse('ForestGreen')
<
rgb({red}, {green}, {blue}) *Vital.Color.rgb()*
Creates |Vital.Color-Color-object| with given parameters.
The value ranges of {red}, {green}, {blue} are 0-255.
>
echo s:Color.rgb(0x00, 0x11, 0x22).as_rgb_hex() == '#001122'
echo s:Color.rgb(0x00, 0x11, 0x22).as_rgb_str() == 'rgb(0,17,34)'
echo s:Color.rgb(0x00, 0x11, 0x22).as_rgb() == [0.0, 17.0, 34.0]
<
hsl({hue}, {saturation}, {lightness}) *Vital.Color.hsl()*
Creates |Vital.Color-Color-object| with given parameters.
The value ranges are:
{hue} = 0-360
{saturation} = 0-100
{lightness} = 0-100
>
echo s:Color.hsl(0, 50, 100).as_hsl_str() == 'hsl(0,50%,100%)'
echo s:Color.hsl(0, 50, 100).as_hsl() == [0.0, 50.0, 100.0]
<
xterm({code}) *Vital.Color.xterm()*
Creates |Vital.Color-Color-object| with given parameters.
The value range of {code} is 0-255.
This converts color name to RGB values internally (so `.as_rgb()`,
`.as_rgb_str()`, `.as_rgb_hex()` doesn't lose the precision).
>
echo s:Color.xterm(0).as_rgb_hex() == '#000000'
echo s:Color.xterm(15).as_rgb_hex() == '#FFFFFF'
<
==============================================================================
COLOR OBJECT *Vital.Color-Color-object*
*Vital.Color-Color.eq()*
Color.eq({color})
Returns |TRUE| if this object is equal to {color}.
Returns |FALSE| otherwise.
*Vital.Color-Color.distance()*
Color.distance({color})
Returns the distance of 3D vector (r, g, b).
*Vital.Color-Color.as_rgb()*
Color.as_rgb()
Returns `[r, g, b]` value. r, g, b are |Float| values.
*Vital.Color-Color.as_rgb_str()*
Color.as_rgb_str()
Returns a string like `rgb({r},{g},{b})`. r, g, b are |Float| values.
*Vital.Color-Color.as_rgb_hex()*
Color.as_rgb_hex()
Returns a string like `#{r}{g}{b}` (e.g. `#000000`, always 7 digits).
*Vital.Color-Color.as_hsl()*
Color.as_hsl()
Returns `[h, s, l]` value. h, s, l are |Float| values.
*Vital.Color-Color.as_hsl_str()*
Color.as_hsl_str()
Returns a string like `hsl({h},{s}%,{l}%)`.
h, s, l are |Float| values.
==============================================================================
TODO *Vital.Color-todo*
- Add more terminal codes like Color.xterm()
- Convert color object to the (exact|nearest) terminal code
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl:noet