Skip to content

Commit d4aedd1

Browse files
committed
fix keeparea
1 parent 39508ca commit d4aedd1

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/artist.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ function randomscheme()
6161
c = Render.colorschemes[scheme].colors
6262
colors = randsubseq(c, rand())
6363
colors = isempty(colors) ? c : colors
64-
@show (scheme, length(colors))
64+
println("color scheme: ", repr(scheme), ", length: ", length(colors))
6565
else
6666
colors = rand((0, 1, 0, 1, 0, 1, (0, 1), rand(), (rand(), rand())))
6767
@show colors
6868
end
6969
(colors...,)
7070
end
7171
function randommask(sz::Number=800; kargs...)
72-
s = sz * sz * (0.9 + 0.2rand())
72+
s = sz * sz
7373
ratio = (0.5 + rand() / 2)
7474
ratio = ratio > 0.9 ? 1.0 : ratio
7575
h = round(Int, sqrt(s * ratio))
@@ -79,8 +79,7 @@ end
7979
function randommask(sz; kargs...)
8080
randommask(sz...; kargs...)
8181
end
82-
function randommask(w, h, args...; maskshape=:rand, keeparea=:auto, kargs...)
83-
keeparea = keeparea == :auto ? maskshape == :rand : keeparea
82+
function randommask(w, h, args...; maskshape=:rand, kargs...)
8483
ran = Dict(box => 0.2, squircle => 0.7, ellipse => 1, :rand => rand())[maskshape]
8584
if ran <= 0.2
8685
return randombox(w, h, args...; kargs...)
@@ -113,6 +112,7 @@ function randomsquircle(w, h; rt=:rand, keeparea=false, kargs...)
113112
rt = 1 + 1.5rand()
114113
end
115114
end
115+
rt = round(rt, digits=3)
116116
end
117117
sc = keeparea ? sqrt(w*h/squircle_area(w, h, rt=rt)) : 1
118118
w = round(Int, w*sc); h = round(Int, h*sc)
@@ -159,7 +159,10 @@ function randommaskcolor(colors)
159159
th1 = clamp(th2 - 0.15, 0, 1)
160160
default = 0.0
161161
end
162-
maskcolor = rand((default, (rand(th1:0.001:th2), rand(th1:0.001:th2), rand(th1:0.001:th2))))
162+
maskcolor = rand((default,
163+
(round(rand(th1:0.001:th2), digits=3),
164+
round(rand(th1:0.001:th2), digits=3),
165+
round(rand(th1:0.001:th2), digits=3))))
163166
# @show maskcolor
164167
return maskcolor
165168
catch e
@@ -172,7 +175,11 @@ function randomlinecolor(colors)
172175
if rand() < 0.8
173176
linecolor = rand((colors[1], colors[1], rand(colors)))
174177
else
175-
linecolor = (rand(), rand(), rand(), min(1., 0.5 + rand() / 2))
178+
linecolor = (
179+
round(rand(), digits=3),
180+
round(rand(), digits=3),
181+
round(rand(), digits=3),
182+
min(1., round(0.5 + rand()/2, digits=3)))
176183
end
177184
linecolor
178185
end

src/wc-class.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Positional arguments are used to specify words and weights, and can be in differ
3535
* mask = loadmask("res/heart.jpg", color="red", ratio=2) #see doc of `loadmask`
3636
* mask = shape(ellipse, 800, 600, color="white", backgroundcolor=(0,0,0,0)) #see doc of `shape`
3737
* maskshape: `box`, `ellipse`, or `squircle`. See `shape`. Take effect only when the `mask` argument is not given.
38-
* masksize: Can be a tuple `(width, height)`, tuple `(width, height, cornerradius)` (for `box` only) or just a single number as hint.
38+
* masksize: Can be a tuple `(width, height)`, tuple `(width, height, cornerradius)` (for `box` only) or just a single number as a side length hint.
3939
* backgroundsize: See `shape`. Take effect only when the `mask` argument is not given.
4040
* maskcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original (keep it unchanged), :auto (auto recolor the mask).
4141
* backgroundcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original, :maskcolor, :auto (random choose between :original and :maskcolor)
@@ -78,9 +78,9 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
7878
if maskoccupying == 0
7979
error("Have you set the right `transparent`? e.g. `transparent=mask[1,1]`")
8080
end
81-
usablesize = round(Int, maskoccupying)
81+
contentsize = round(Int, maskoccupying)
8282
avgsize = round(Int, sqrt(maskoccupying / length(words)))
83-
println("mask size: $(size(mask, 1))×$(size(mask, 2)), usable area: $(usablesize)² ($(avgsize)²/word)")
83+
println("mask size: $(size(mask, 1))×$(size(mask, 2)), content area: $(contentsize)² ($(avgsize)²/word)")
8484

8585
@assert maskoccupying > 0
8686
if minfontsize == :auto
@@ -132,8 +132,11 @@ function getstylescheme(words, weights; colors=:auto, angles=:auto, mask=:auto,
132132
maskcolor = backgroundcolor
133133
end
134134
end
135+
if keepmaskarea in DEFAULTSYMBOLS
136+
keepmaskarea = masksize in DEFAULTSYMBOLS
137+
end
135138
weights = weights ./ (sum(weights) / length(weights)) #权重为平均值的单词为中等大小的单词。weights不平方,即按条目平均,而不是按面积平均
136-
masksize = masksize in DEFAULTSYMBOLS ? 12 * sum(length.(words) .* weights .^ 2) : masksize #中等大小的单词其每个字母占据16 pixel*16 pixel
139+
masksize = masksize in DEFAULTSYMBOLS ? 12 * sum(length.(words) .* weights .^ 2) : masksize #中等大小的单词其每个字母占据12 pixel*12 pixel
137140
if backgroundcolor in DEFAULTSYMBOLS
138141
backgroundcolor = maskcolor0 in DEFAULTSYMBOLS ? rand(((1, 1, 1, 0), :maskcolor)) : (1, 1, 1, 0)
139142
end

src/wc-method.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function placewords!(wc::WC; style=:uniform, rt=:auto, centerlargestword=:auto,
7676
&& wc.weights[2] / wc.weights[1] < 0.5
7777
&& prod(kernelsize(wc.qtrees[2])) / prod(kernelsize(wc.qtrees[1])) < 0.5))
7878
if centerlargestword
79-
println("Center the largest word $(repr(getwords(wc, 1)))")
79+
println("center the largest word $(repr(getwords(wc, 1)))")
8080
end
8181
end
8282
arg = ()

0 commit comments

Comments
 (0)