-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
executable file
·158 lines (130 loc) · 7.21 KB
/
init.lua
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
#!/usr/bin/env th
local MADpalettes = require 'palettes'
local col = require 'async.repl'.colorize
function h1(text) print(col._black(text)) end
function h2(text) print(col.red(text)) end
function h3(text) print(col._cyan(text)) end
local MADcolors = {
munsell = {}
}
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ RDM color ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function MADcolors.rdm(arrayPalette)
local arrayPalette = arrayPalette or MADpalettes.coolhex
local array = arrayPalette
for i = 1, #array-1 do
local j = torch.random(i,#array)
array[i], array[j] = array[j], array[i]
end
-- print('Palette = ')
return array[1]
end
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ HSLA ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function MADpalettes.hsla(h,s,l,a)
local a = a or 1;
return 'hsla(' .. h .. ',' .. s .. '%,' .. l .. '%,' .. a .. ')'
end
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ MUNSELL - code ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function MADcolors.munsell.byCode(opt)
---- PALETTE
local codes = MADpalettes.munsell.codes
local RDMcode = codes[torch.random(1,#codes)]
local setPalette = MADpalettes.munsell.bycode
---- OPTIONS
opt = opt or {}
local code = opt.code or RDMcode
local step = opt.step or 4
local value = opt.value or 9
local chroma = opt.value or 50
---- GET
local setHue = setPalette[code]
local setStep = setHue[4]
local setValue = setStep[9]
local nChroma = #setValue
local chromaIndex = math.ceil((chroma/100) * nChroma)
local color = setValue[chromaIndex]
---- PRINT
h1([[
------------------------
MADcolors.munsell.byCode ({
Value =]].. step ..[[, (1-9)
Chroma =]].. code ..[[, (R-YR-Y-GY-G-BG-B-PB-P-RP)
degree =]].. value ..[[, (1-40)
rLeft =]].. chroma ..[[, (1-100)
})
index Chroma = ]]..chromaIndex..[[/]]..nChroma..[[
hex = ]]..color
)
---- RETURN
return color
end
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ MUNSELL - circular ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function MADcolors.circular(opt)
opt = opt or {}
local n = 40
local value = opt.value or torch.random(1,9)
local chroma = opt.chroma or torch.random(1,99)
local degree = opt.degree or torch.random(1,40)
local goLeft = opt.goLeft or torch.random(1,20)
local goRight = opt.goRight or torch.random(1,20)
----hue
local idx = degree
if goRight~=0 then idx = idx + goRight end
if goLeft~=0 then idx = idx - goLeft end
----list -> circle
if idx > n then idx = idx - n end
if idx < 0 then idx = n - idx end
----light row
value = 10 - value
local valueRow = MADpalettes.munsell.flat[idx][value]
----color
local nChroma = #valueRow
local chromaIndex = math.ceil((chroma/100)*nChroma)
local color = valueRow[chromaIndex]
h1([[
------------------
MADcolors.circular ({
Value =]].. value ..[[, (1-9)
Chroma =]].. chroma ..[[, (1-100)
degree =]].. degree ..[[, (1-40)
rLeft =]].. goLeft ..[[, (1-20)
rRight =]].. goRight ..[[, (1-20)
})
COLOR = ]]..color..[[
]]
)
---- RETURN
return color
end
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ HEX to RGB ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function MADcolors.hex2rgb(hexString)
_,_,R,G,B = hexString:find('.(..)(..)(..)')
R = tonumber('0x'..R)/255
G = tonumber('0x'..G)/255
B = tonumber('0x'..B)/255
end
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
--┃ ┃
--┃ RETURN ┃
--┃ ┃
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
return MADcolors