diff --git a/turing-logo-graphics/.gitignore b/turing-logo-graphics/.gitignore new file mode 100644 index 000000000..35459689d --- /dev/null +++ b/turing-logo-graphics/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +Manifest.toml diff --git a/turing-logo-graphics/Project.toml b/turing-logo-graphics/Project.toml new file mode 100644 index 000000000..09eb32ac2 --- /dev/null +++ b/turing-logo-graphics/Project.toml @@ -0,0 +1,5 @@ +[deps] +Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" diff --git a/turing-logo-graphics/README.md b/turing-logo-graphics/README.md new file mode 100644 index 000000000..5a32a0444 --- /dev/null +++ b/turing-logo-graphics/README.md @@ -0,0 +1,5 @@ +## Turing logo graphics + +![Turing logo text](images/logo-text-small.png) ![Turing logo text dark](images/logo-text-dark-small.png) + +![Turing logo](images/logo-medium.png) diff --git a/turing-logo-graphics/font/TamilMN-Bold.ttf b/turing-logo-graphics/font/TamilMN-Bold.ttf new file mode 100644 index 000000000..13e423bc3 Binary files /dev/null and b/turing-logo-graphics/font/TamilMN-Bold.ttf differ diff --git a/turing-logo-graphics/images/logo-large.png b/turing-logo-graphics/images/logo-large.png new file mode 100644 index 000000000..eb853e33b Binary files /dev/null and b/turing-logo-graphics/images/logo-large.png differ diff --git a/turing-logo-graphics/images/logo-large.svg b/turing-logo-graphics/images/logo-large.svg new file mode 100644 index 000000000..ea364018e --- /dev/null +++ b/turing-logo-graphics/images/logo-large.svg @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-medium.png b/turing-logo-graphics/images/logo-medium.png new file mode 100644 index 000000000..f525f6c97 Binary files /dev/null and b/turing-logo-graphics/images/logo-medium.png differ diff --git a/turing-logo-graphics/images/logo-medium.svg b/turing-logo-graphics/images/logo-medium.svg new file mode 100644 index 000000000..03f70aa8e --- /dev/null +++ b/turing-logo-graphics/images/logo-medium.svg @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-small.png b/turing-logo-graphics/images/logo-small.png new file mode 100644 index 000000000..fb2ea3ec2 Binary files /dev/null and b/turing-logo-graphics/images/logo-small.png differ diff --git a/turing-logo-graphics/images/logo-small.svg b/turing-logo-graphics/images/logo-small.svg new file mode 100644 index 000000000..a0bc2a9ca --- /dev/null +++ b/turing-logo-graphics/images/logo-small.svg @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-dark-large.png b/turing-logo-graphics/images/logo-text-dark-large.png new file mode 100644 index 000000000..991ba92fd Binary files /dev/null and b/turing-logo-graphics/images/logo-text-dark-large.png differ diff --git a/turing-logo-graphics/images/logo-text-dark-large.svg b/turing-logo-graphics/images/logo-text-dark-large.svg new file mode 100644 index 000000000..2cf94fd65 --- /dev/null +++ b/turing-logo-graphics/images/logo-text-dark-large.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-dark-medium.png b/turing-logo-graphics/images/logo-text-dark-medium.png new file mode 100644 index 000000000..05db13abf Binary files /dev/null and b/turing-logo-graphics/images/logo-text-dark-medium.png differ diff --git a/turing-logo-graphics/images/logo-text-dark-medium.svg b/turing-logo-graphics/images/logo-text-dark-medium.svg new file mode 100644 index 000000000..1729ee918 --- /dev/null +++ b/turing-logo-graphics/images/logo-text-dark-medium.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-dark-small.png b/turing-logo-graphics/images/logo-text-dark-small.png new file mode 100644 index 000000000..26eb3e19c Binary files /dev/null and b/turing-logo-graphics/images/logo-text-dark-small.png differ diff --git a/turing-logo-graphics/images/logo-text-dark-small.svg b/turing-logo-graphics/images/logo-text-dark-small.svg new file mode 100644 index 000000000..77b19550f --- /dev/null +++ b/turing-logo-graphics/images/logo-text-dark-small.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-large.png b/turing-logo-graphics/images/logo-text-large.png new file mode 100644 index 000000000..4f555c71a Binary files /dev/null and b/turing-logo-graphics/images/logo-text-large.png differ diff --git a/turing-logo-graphics/images/logo-text-large.svg b/turing-logo-graphics/images/logo-text-large.svg new file mode 100644 index 000000000..19725907a --- /dev/null +++ b/turing-logo-graphics/images/logo-text-large.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-medium.png b/turing-logo-graphics/images/logo-text-medium.png new file mode 100644 index 000000000..6812db357 Binary files /dev/null and b/turing-logo-graphics/images/logo-text-medium.png differ diff --git a/turing-logo-graphics/images/logo-text-medium.svg b/turing-logo-graphics/images/logo-text-medium.svg new file mode 100644 index 000000000..4929ef492 --- /dev/null +++ b/turing-logo-graphics/images/logo-text-medium.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/images/logo-text-small.png b/turing-logo-graphics/images/logo-text-small.png new file mode 100644 index 000000000..1873bdda2 Binary files /dev/null and b/turing-logo-graphics/images/logo-text-small.png differ diff --git a/turing-logo-graphics/images/logo-text-small.svg b/turing-logo-graphics/images/logo-text-small.svg new file mode 100644 index 000000000..7d5207aee --- /dev/null +++ b/turing-logo-graphics/images/logo-text-small.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/turing-logo-graphics/src/logo-text.jl b/turing-logo-graphics/src/logo-text.jl new file mode 100644 index 000000000..86b359289 --- /dev/null +++ b/turing-logo-graphics/src/logo-text.jl @@ -0,0 +1,121 @@ +using Luxor +using Luxor: julia_blue + +function getloc(tpath, idx) + xpoint = 0 + ypoint = Inf + xpoint = polycentroid(tpath[idx]).x + for t in tpath + cpos = polycentroid(t) + (cpos.y < ypoint) && (ypoint = cpos.y) + end + return xpoint, ypoint +end + +function find_i_index(txt) + i = 0 + for c in txt + if c in ( + 'a', 'b', 'c', 'd', 'e', + 'f', 'g', 'h', + 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', + 'z', + 'A', 'B', 'C', 'D', 'E', + 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', + 'Z', + ) + i += 1 + elseif c == 'j' + i += 2 + elseif c == 'i' + return i + 1 + else + @error "Unsupoorted character \"$c\"" + end + end + @error "No \"i\" in the given text \"$txt\"" +end + +""" +Create a Julia style logo for the +given text which contains an "i". + +Example: +```julia +textlogo("Turing") +``` +![](https://github.com/TuringLang/turing-logo-graphics/raw/main/images/logo-text-small.png) + +Acknowledgement for https://github.com/JuliaGraphics/Luxor.jl/issues/78#issuecomment-570317514 +""" +function textlogo( + txt::String; + ff::String="TamilMN-Bold", # TamilMN-Bold is the font Julia's logo + fs::Int=50, # font size + xshift=( fs / 6), # shifts for x + yshift=(-fs / 6), # and y axes to move Julia circles + is_dark::Bool=false, # dark mode or not + is_firstblue::Bool=false, # to draw a transparent blue on the first letter or not + is_overlapred=true, # to overlap red or purple? + filename="$(lowercase(txt))-logo.svg" +) + @assert !('c' in txt) "No \"i\" in the given text \"$txt\"" + ratio, wratio = fs / 50, length(txt) / 6 + radius = fs / 5 + for suffix in ("png", "svg") + drawing = Drawing(180 * ratio * wratio, 80 * ratio, "$filename.$suffix") + + translate(5 * ratio * wratio, 65 * ratio) + fontface(ff) + fontsize(fs) + if is_dark + background("black") + sethue("white") + else + background("white") + sethue("black") + end + + text(txt) + textoutlines(txt, O, :path) + tpath = pathtopoly() + + # Red, green and purple circles + xpoint, ypoint = getloc(tpath, find_i_index(txt)) + if is_overlapred + xtrans, ytrans = xpoint + xshift, ypoint + yshift + else + xtrans, ytrans = xpoint + xshift, ypoint + yshift + end + translate( xtrans, ytrans) + juliacircles(radius) + translate(-xtrans, -ytrans) + + # Blue circle + if is_firstblue + xpoint, ypoint = getloc(tpath, 1) + translate(xpoint - xshift, ypoint) + p = ngon(O, radius, 1, pi/6, vertices=true)[1] + setcolor((julia_blue..., 0.5)) + circle(p, 2 * radius, :fill) + end + + finish() + end + preview() +end + +turinglogo(; kwargs...) = textlogo("Turing"; kwargs...) + +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-small"), fs=50) +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-medium"), fs=100) +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-large"), fs=200) + +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-small"), fs=50, is_dark=true) +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-medium"), fs=100, is_dark=true) +turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-large"), fs=200, is_dark=true) diff --git a/turing-logo-graphics/src/logo.jl b/turing-logo-graphics/src/logo.jl new file mode 100644 index 000000000..391dc99ae --- /dev/null +++ b/turing-logo-graphics/src/logo.jl @@ -0,0 +1,47 @@ +using Distributions, Plots, Colors + +# Gaussian with known variance +# mu ~ Normal(mu0, sig0) +# xi ~ Normal(mu, sig_like) +# Ref: https://en.wikipedia.org/wiki/Conjugate_prior#Continuous_distributions +function get_posterior_parameters(xs, mu0, sig0, siglike) + n = length(xs) + var = inv(1 / sig0^2 + n / siglike^2) + mu = var * (mu0 / sig0^2 + sum(xs) / siglike^2) + return mu, sqrt(var) +end + +function turinglogo(filename::String; figsize=(450, 300)) + default(size=figsize, leg=false) + + mu0, sig0, siglike = 0.0, 1.0, 1.0 + prior = Normal(mu0, sig0) + # Inference with one datum + obs = [5.0] + post1 = Normal(get_posterior_parameters(obs, mu0, sig0, siglike)...) + # Inference with more data + push!(obs, 1.0) + post2 = Normal(get_posterior_parameters(obs, mu0, sig0, siglike)...) + + julia_purple = parse(Colorant, RGBA(0.702, 0.322, 0.8)) + julia_brown = parse(Colorant, RGBA(0.8, 0.2, 0.2)) + julia_green = parse(Colorant, RGBA(0.133, 0.541, 0.133)) + + xs = -3:0.01:5 + lw = 15.0 + fig = plot(xs, pdf.(Ref(prior), xs), color=julia_purple, linewidth=lw, grid=false) + plot!(xs, pdf.(Ref(post1), xs), color=julia_brown, linewidth=lw) + plot!(xs, pdf.(Ref(post2), xs), color=julia_green, linewidth=lw) + xaxis!(false) + yaxis!(false) + + display(fig) + + for suffix in ("png", "svg") + savefig(joinpath(@__DIR__, "$filename.$suffix")) + end +end + +turinglogo("../images/logo-small"; figsize=(450, 300)) +turinglogo("../images/logo-medium"; figsize=(600, 400)) +turinglogo("../images/logo-large"; figsize=(750, 500))