Skip to content

Commit

Permalink
more random angles and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Mar 20, 2022
1 parent 778360e commit 8832a7b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WordCloud"
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
authors = ["guoyongzhi <[email protected]>"]
version = "0.10.3"
version = "0.10.4"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
44 changes: 33 additions & 11 deletions src/artist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ Schemes_colorbrewer = filter(s -> (occursin("Accent", String(s))
|| occursin("Pastel", String(s))
|| occursin("Set", String(s))
|| occursin("Spectral", String(s))
|| occursin("BuPu", String(s))
|| occursin("PuOr", String(s))
|| occursin("RdPu", String(s))
), Schemes_colorbrewer)
Schemes_seaborn = filter(s -> occursin("seaborn", colorschemes[s].category), collect(keys(colorschemes)))
Schemes_tableau = filter(s -> occursin("tableau", colorschemes[s].category), collect(keys(colorschemes)))
Schemes_cvd = filter(s -> occursin("cvd", colorschemes[s].category), collect(keys(colorschemes)))
Schemes = [Schemes_colorbrewer..., Schemes_seaborn..., Schemes_tableau..., Schemes_cvd...]
Schemes_gnuplot = filter(s -> occursin("gnuplot", colorschemes[s].category), collect(keys(colorschemes)))
Schemes_MetBrewer = filter(s -> occursin("MetBrewer", colorschemes[s].category), collect(keys(colorschemes)))
Schemes_general = [:bluegreenyellow, :cmyk, :darkrainbow, :deepsea, :dracula, :fall, :rainbow]
Schemes = [Schemes_colorbrewer; Schemes_seaborn; Schemes_tableau; Schemes_cvd; Schemes_gnuplot; Schemes_MetBrewer; Schemes_general]

function displayschemes()
for scheme in Schemes
Expand All @@ -59,9 +59,16 @@ function randomscheme()
if rand() < 0.95
scheme = rand(Schemes)
c = Render.colorschemes[scheme].colors
colors = randsubseq(c, rand())
isempty(colors) && (colors = c)
println("color scheme: ", repr(scheme), ", length: ", length(colors))
colors = c
if length(colors) < 64
colors = randsubseq(colors, rand())
isempty(colors) && (colors = c)
else
colors = colors[range(minmax(rand(begin:end), rand(begin:end))...; step=1)]
length(colors) < length(c)÷10 && (colors = c)
end
rand() > 0.5 && (colors = tuple(colors...))
println("color scheme: ", repr(scheme), ", random size: ", length(colors))
else
colors = rand((0, 1, 0, 1, 0, 1, rand(), (rand(), rand())))
@show colors
Expand Down Expand Up @@ -169,9 +176,24 @@ function randomstar(w, h; npoints=:rand, starratio=:rand, orientation=:rand, kee
return shape(star, w, h; npoints=npoints, starratio=starratio, orientation=orientation, kargs...)
end
function randomangles()
a = rand((-1, 1)) .* rand((0, (0, 90), (0, 90, 45), (0, 90, 45, -45), (0, 45, -45), (45, -45), -90:90, 0:90))
println("angles = ", a)
a
θ = rand((30, 45, 60))
st = rand((5, 10, 15))
angles = rand((0, (0, 90), (0, 45, 90), (0, 45, 90, -45), -90:90, -90:st:90,
-5:5, (0, θ, -θ), (θ, -θ), -θ, -θ:st:θ))
if length(angles) > 1 && rand() > 0.5
0 in angles && maximum(abs, angles)>10 && (angles = angles .- first(angles))
if angles isa Tuple
angles = collect(angles)
println("angles = ", angles)
else
println("angles = collect($angles)")
angles = collect(angles)
end
else
rand() > 0.7 && (angles = -1 .* angles)
println("angles = ", angles)
end
angles
end
function randommaskcolor(colors)
colors = parsecolor.(unique(colors))
Expand Down Expand Up @@ -232,7 +254,7 @@ function randomfonts()
fonts = rand(AvailableFonts)
else
fonts = rand(AvailableFonts, 2 + floor(Int, 2randexp()))
fonts = Tuple(fonts)
rand() > 0.5 && (fonts = tuple(fonts...))
end
@show fonts
fonts
Expand Down
2 changes: 1 addition & 1 deletion src/strategy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0.
while true
step = step + 1
if step > maxiter
@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`."
@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."
break
end
# cal tg1
Expand Down
2 changes: 1 addition & 1 deletion src/wc-method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function printcollisions(wc)
get_text(i) = i > 1 ? wc.words[i - 1] : "#MASK#"
collwords = [(get_text(i), get_text(j)) for (i, j) in colllist]
if length(colllist) > 0
@warn "Have $(length(colllist)) collisions. Try setting a larger `nepoch` and `retry`, or lower `density` in `wordcloud` to fix that"
@warn "Have $(length(colllist)) collisions. Try setting a larger `nepoch` and `retry`, or lower `density` and `spacing` in `wordcloud` to fix it."
println("$collwords")
end
end
Expand Down

2 comments on commit 8832a7b

@guo-yong-zhi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56937

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.4 -m "<description of version>" 8832a7bec947da88363da343c45d39f347bfb4c1
git push origin v0.10.4

Please sign in to comment.