Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a27493

Browse files
shravanngoswamiixukai92penelopeysm
authoredApr 21, 2025··
Merging turing-logo-graphics repository (#120)
* port logo codes * update docstring * add acknowledgement * update url * Default branch rename --------- Co-authored-by: Kai Xu <xukai921110@gmail.com> Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
1 parent 44e705d commit 1a27493

24 files changed

+1251
-0
lines changed
 

‎turing-logo-graphics/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
Manifest.toml

‎turing-logo-graphics/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
3+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
4+
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
5+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

‎turing-logo-graphics/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Turing logo graphics
2+
3+
![Turing logo text](images/logo-text-small.png) ![Turing logo text dark](images/logo-text-dark-small.png)
4+
5+
![Turing logo](images/logo-medium.png)
193 KB
Binary file not shown.
33.4 KB
Loading

‎turing-logo-graphics/images/logo-large.svg

Lines changed: 273 additions & 0 deletions
Loading
25.3 KB
Loading

‎turing-logo-graphics/images/logo-medium.svg

Lines changed: 273 additions & 0 deletions
Loading
17.8 KB
Loading

‎turing-logo-graphics/images/logo-small.svg

Lines changed: 273 additions & 0 deletions
Loading
Loading
Lines changed: 42 additions & 0 deletions
Loading
Loading
Lines changed: 42 additions & 0 deletions
Loading
Loading
Lines changed: 42 additions & 0 deletions
Loading
13.9 KB
Loading
Lines changed: 42 additions & 0 deletions
Loading
6.57 KB
Loading
Lines changed: 42 additions & 0 deletions
Loading
3.32 KB
Loading
Lines changed: 42 additions & 0 deletions
Loading

‎turing-logo-graphics/src/logo-text.jl

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using Luxor
2+
using Luxor: julia_blue
3+
4+
function getloc(tpath, idx)
5+
xpoint = 0
6+
ypoint = Inf
7+
xpoint = polycentroid(tpath[idx]).x
8+
for t in tpath
9+
cpos = polycentroid(t)
10+
(cpos.y < ypoint) && (ypoint = cpos.y)
11+
end
12+
return xpoint, ypoint
13+
end
14+
15+
function find_i_index(txt)
16+
i = 0
17+
for c in txt
18+
if c in (
19+
'a', 'b', 'c', 'd', 'e',
20+
'f', 'g', 'h',
21+
'k', 'l', 'm', 'n', 'o',
22+
'p', 'q', 'r', 's', 't',
23+
'u', 'v', 'w', 'x', 'y',
24+
'z',
25+
'A', 'B', 'C', 'D', 'E',
26+
'F', 'G', 'H', 'I', 'J',
27+
'K', 'L', 'M', 'N', 'O',
28+
'P', 'Q', 'R', 'S', 'T',
29+
'U', 'V', 'W', 'X', 'Y',
30+
'Z',
31+
)
32+
i += 1
33+
elseif c == 'j'
34+
i += 2
35+
elseif c == 'i'
36+
return i + 1
37+
else
38+
@error "Unsupoorted character \"$c\""
39+
end
40+
end
41+
@error "No \"i\" in the given text \"$txt\""
42+
end
43+
44+
"""
45+
Create a Julia style logo for the
46+
given text which contains an "i".
47+
48+
Example:
49+
```julia
50+
textlogo("Turing")
51+
```
52+
![](https://github.com/TuringLang/turing-logo-graphics/raw/main/images/logo-text-small.png)
53+
54+
Acknowledgement for https://github.com/JuliaGraphics/Luxor.jl/issues/78#issuecomment-570317514
55+
"""
56+
function textlogo(
57+
txt::String;
58+
ff::String="TamilMN-Bold", # TamilMN-Bold is the font Julia's logo
59+
fs::Int=50, # font size
60+
xshift=( fs / 6), # shifts for x
61+
yshift=(-fs / 6), # and y axes to move Julia circles
62+
is_dark::Bool=false, # dark mode or not
63+
is_firstblue::Bool=false, # to draw a transparent blue on the first letter or not
64+
is_overlapred=true, # to overlap red or purple?
65+
filename="$(lowercase(txt))-logo.svg"
66+
)
67+
@assert !('c' in txt) "No \"i\" in the given text \"$txt\""
68+
ratio, wratio = fs / 50, length(txt) / 6
69+
radius = fs / 5
70+
for suffix in ("png", "svg")
71+
drawing = Drawing(180 * ratio * wratio, 80 * ratio, "$filename.$suffix")
72+
73+
translate(5 * ratio * wratio, 65 * ratio)
74+
fontface(ff)
75+
fontsize(fs)
76+
if is_dark
77+
background("black")
78+
sethue("white")
79+
else
80+
background("white")
81+
sethue("black")
82+
end
83+
84+
text(txt)
85+
textoutlines(txt, O, :path)
86+
tpath = pathtopoly()
87+
88+
# Red, green and purple circles
89+
xpoint, ypoint = getloc(tpath, find_i_index(txt))
90+
if is_overlapred
91+
xtrans, ytrans = xpoint + xshift, ypoint + yshift
92+
else
93+
xtrans, ytrans = xpoint + xshift, ypoint + yshift
94+
end
95+
translate( xtrans, ytrans)
96+
juliacircles(radius)
97+
translate(-xtrans, -ytrans)
98+
99+
# Blue circle
100+
if is_firstblue
101+
xpoint, ypoint = getloc(tpath, 1)
102+
translate(xpoint - xshift, ypoint)
103+
p = ngon(O, radius, 1, pi/6, vertices=true)[1]
104+
setcolor((julia_blue..., 0.5))
105+
circle(p, 2 * radius, :fill)
106+
end
107+
108+
finish()
109+
end
110+
preview()
111+
end
112+
113+
turinglogo(; kwargs...) = textlogo("Turing"; kwargs...)
114+
115+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-small"), fs=50)
116+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-medium"), fs=100)
117+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-large"), fs=200)
118+
119+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-small"), fs=50, is_dark=true)
120+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-medium"), fs=100, is_dark=true)
121+
turinglogo(; filename=joinpath(@__DIR__, "../images/logo-text-dark-large"), fs=200, is_dark=true)

‎turing-logo-graphics/src/logo.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Distributions, Plots, Colors
2+
3+
# Gaussian with known variance
4+
# mu ~ Normal(mu0, sig0)
5+
# xi ~ Normal(mu, sig_like)
6+
# Ref: https://en.wikipedia.org/wiki/Conjugate_prior#Continuous_distributions
7+
function get_posterior_parameters(xs, mu0, sig0, siglike)
8+
n = length(xs)
9+
var = inv(1 / sig0^2 + n / siglike^2)
10+
mu = var * (mu0 / sig0^2 + sum(xs) / siglike^2)
11+
return mu, sqrt(var)
12+
end
13+
14+
function turinglogo(filename::String; figsize=(450, 300))
15+
default(size=figsize, leg=false)
16+
17+
mu0, sig0, siglike = 0.0, 1.0, 1.0
18+
prior = Normal(mu0, sig0)
19+
# Inference with one datum
20+
obs = [5.0]
21+
post1 = Normal(get_posterior_parameters(obs, mu0, sig0, siglike)...)
22+
# Inference with more data
23+
push!(obs, 1.0)
24+
post2 = Normal(get_posterior_parameters(obs, mu0, sig0, siglike)...)
25+
26+
julia_purple = parse(Colorant, RGBA(0.702, 0.322, 0.8))
27+
julia_brown = parse(Colorant, RGBA(0.8, 0.2, 0.2))
28+
julia_green = parse(Colorant, RGBA(0.133, 0.541, 0.133))
29+
30+
xs = -3:0.01:5
31+
lw = 15.0
32+
fig = plot(xs, pdf.(Ref(prior), xs), color=julia_purple, linewidth=lw, grid=false)
33+
plot!(xs, pdf.(Ref(post1), xs), color=julia_brown, linewidth=lw)
34+
plot!(xs, pdf.(Ref(post2), xs), color=julia_green, linewidth=lw)
35+
xaxis!(false)
36+
yaxis!(false)
37+
38+
display(fig)
39+
40+
for suffix in ("png", "svg")
41+
savefig(joinpath(@__DIR__, "$filename.$suffix"))
42+
end
43+
end
44+
45+
turinglogo("../images/logo-small"; figsize=(450, 300))
46+
turinglogo("../images/logo-medium"; figsize=(600, 400))
47+
turinglogo("../images/logo-large"; figsize=(750, 500))

0 commit comments

Comments
 (0)
Please sign in to comment.