Skip to content

Commit 8832a7b

Browse files
committed
more random angles and colors
1 parent 778360e commit 8832a7b

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "WordCloud"
22
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
33
authors = ["guoyongzhi <guo-yong-zhi@outlook.com>"]
4-
version = "0.10.3"
4+
version = "0.10.4"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

src/artist.jl

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ Schemes_colorbrewer = filter(s -> (occursin("Accent", String(s))
3939
|| occursin("Pastel", String(s))
4040
|| occursin("Set", String(s))
4141
|| occursin("Spectral", String(s))
42-
|| occursin("BuPu", String(s))
43-
|| occursin("PuOr", String(s))
44-
|| occursin("RdPu", String(s))
4542
), Schemes_colorbrewer)
4643
Schemes_seaborn = filter(s -> occursin("seaborn", colorschemes[s].category), collect(keys(colorschemes)))
4744
Schemes_tableau = filter(s -> occursin("tableau", colorschemes[s].category), collect(keys(colorschemes)))
4845
Schemes_cvd = filter(s -> occursin("cvd", colorschemes[s].category), collect(keys(colorschemes)))
49-
Schemes = [Schemes_colorbrewer..., Schemes_seaborn..., Schemes_tableau..., Schemes_cvd...]
46+
Schemes_gnuplot = filter(s -> occursin("gnuplot", colorschemes[s].category), collect(keys(colorschemes)))
47+
Schemes_MetBrewer = filter(s -> occursin("MetBrewer", colorschemes[s].category), collect(keys(colorschemes)))
48+
Schemes_general = [:bluegreenyellow, :cmyk, :darkrainbow, :deepsea, :dracula, :fall, :rainbow]
49+
Schemes = [Schemes_colorbrewer; Schemes_seaborn; Schemes_tableau; Schemes_cvd; Schemes_gnuplot; Schemes_MetBrewer; Schemes_general]
5050

5151
function displayschemes()
5252
for scheme in Schemes
@@ -59,9 +59,16 @@ function randomscheme()
5959
if rand() < 0.95
6060
scheme = rand(Schemes)
6161
c = Render.colorschemes[scheme].colors
62-
colors = randsubseq(c, rand())
63-
isempty(colors) && (colors = c)
64-
println("color scheme: ", repr(scheme), ", length: ", length(colors))
62+
colors = c
63+
if length(colors) < 64
64+
colors = randsubseq(colors, rand())
65+
isempty(colors) && (colors = c)
66+
else
67+
colors = colors[range(minmax(rand(begin:end), rand(begin:end))...; step=1)]
68+
length(colors) < length(c)÷10 && (colors = c)
69+
end
70+
rand() > 0.5 && (colors = tuple(colors...))
71+
println("color scheme: ", repr(scheme), ", random size: ", length(colors))
6572
else
6673
colors = rand((0, 1, 0, 1, 0, 1, rand(), (rand(), rand())))
6774
@show colors
@@ -169,9 +176,24 @@ function randomstar(w, h; npoints=:rand, starratio=:rand, orientation=:rand, kee
169176
return shape(star, w, h; npoints=npoints, starratio=starratio, orientation=orientation, kargs...)
170177
end
171178
function randomangles()
172-
a = rand((-1, 1)) .* rand((0, (0, 90), (0, 90, 45), (0, 90, 45, -45), (0, 45, -45), (45, -45), -90:90, 0:90))
173-
println("angles = ", a)
174-
a
179+
θ = rand((30, 45, 60))
180+
st = rand((5, 10, 15))
181+
angles = rand((0, (0, 90), (0, 45, 90), (0, 45, 90, -45), -90:90, -90:st:90,
182+
-5:5, (0, θ, -θ), (θ, -θ), -θ, -θ:st:θ))
183+
if length(angles) > 1 && rand() > 0.5
184+
0 in angles && maximum(abs, angles)>10 && (angles = angles .- first(angles))
185+
if angles isa Tuple
186+
angles = collect(angles)
187+
println("angles = ", angles)
188+
else
189+
println("angles = collect($angles)")
190+
angles = collect(angles)
191+
end
192+
else
193+
rand() > 0.7 && (angles = -1 .* angles)
194+
println("angles = ", angles)
195+
end
196+
angles
175197
end
176198
function randommaskcolor(colors)
177199
colors = parsecolor.(unique(colors))
@@ -232,7 +254,7 @@ function randomfonts()
232254
fonts = rand(AvailableFonts)
233255
else
234256
fonts = rand(AvailableFonts, 2 + floor(Int, 2randexp()))
235-
fonts = Tuple(fonts)
257+
rand() > 0.5 && (fonts = tuple(fonts...))
236258
end
237259
@show fonts
238260
fonts

src/strategy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0.
135135
while true
136136
step = step + 1
137137
if step > maxiter
138-
@warn "`findscale!` reach the `maxiter`. The `density` may be inaccurate. This may be caused by too small background, too many words or too big `minfontsize`."
138+
@warn "The `findscale!` has performed `maxiter`($maxiter) iterations. The set `density` is not reached. This may be caused by too small background, too big `minfontsize` or unsuitable number of words."
139139
break
140140
end
141141
# cal tg1

src/wc-method.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function printcollisions(wc)
258258
get_text(i) = i > 1 ? wc.words[i - 1] : "#MASK#"
259259
collwords = [(get_text(i), get_text(j)) for (i, j) in colllist]
260260
if length(colllist) > 0
261-
@warn "Have $(length(colllist)) collisions. Try setting a larger `nepoch` and `retry`, or lower `density` in `wordcloud` to fix that"
261+
@warn "Have $(length(colllist)) collisions. Try setting a larger `nepoch` and `retry`, or lower `density` and `spacing` in `wordcloud` to fix it."
262262
println("$collwords")
263263
end
264264
end

0 commit comments

Comments
 (0)