Skip to content

Commit e5ae45b

Browse files
committed
tweaking randommaskcolor
1 parent 1d06438 commit e5ae45b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/artist.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function sample(wv)
326326
end
327327
return i
328328
end
329-
function rand_argmin(a, tor=50)
329+
function rand_argmin(a, tor=10)
330330
th = minimum(a) * tor
331331
ind_weight = [(i, 1 / (ai + 1e-6)^2) for (i, ai) in enumerate(a) if ai <= th]
332332
i = sample(last.(ind_weight))
@@ -346,9 +346,9 @@ function randommaskcolor(colors)
346346
colors = [(c.h, c.s, c.l) for c in colors]
347347
rl = 77 # 256*0.3
348348
rl2 = 102 # 256*0.4
349-
l_slots = zeros(256 + 2rl2) .+ 0.01
349+
l_slots = zeros(256 + 2rl2) .+ 0.00625
350350
rh = 30
351-
h_slots = zeros(360) .+ 0.05
351+
h_slots = zeros(360) .+ 0.00625
352352
s2max = 0.6
353353
win_l = window(2rl + 1)
354354
win_l2 = window(2rl2 + 1)
@@ -391,7 +391,10 @@ function randommaskcolor(colors)
391391
w[51:end-51] .+= window(256 - 101, 7) # 中间调回避
392392
array_max!(@view(w[1:end÷2]), 3) # 高亮偏好
393393
l_slots .*= w
394-
l2 = rand_argmin(l_slots) / 255
394+
l2 = (rand_argmin(l_slots, 10) - 1) / 255
395+
# 10 > max(3, 1+7),不会截断概率,故高亮和中间调仅是偏好策略
396+
# 0.00625*8*10=0.5,截断最高能达到明度避让策略最高点(1.0)的一半,
397+
# 相对应地,保证明度差起码有sqrt(1-0.5/1.0)*(77/256)=0.21
395398
s2 = rand() * s2max
396399
"#" * hex(HSL(h2, s2, l2))
397400
end

0 commit comments

Comments
 (0)