Skip to content

Instantly share code, notes, and snippets.

@jw3126
Created January 12, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jw3126/0a560d116cc1b28c509acd61cb49a5ba to your computer and use it in GitHub Desktop.
Save jw3126/0a560d116cc1b28c509acd61cb49a5ba to your computer and use it in GitHub Desktop.
MakieSphericalHarmonics
using GSL
using Makie
struct Y
l::Int
m::Int
function Y(l,m)
@assert -l <= m <= l
new(l,m)
end
end
function (y::Y)(θ,φ)
Plm = GSL.sf_legendre_sphPlm_e(y.l, abs(y.m), cos(θ)).val
exp(im*y.m*φ) * Plm
end
θ = range(0,stop=π, length=50)
φ = range(0, stop=2π, length=100)
x = [sin(θ)*cos(φ) for θ in θ, φ in φ]
y = [sin(θ)*sin(φ) for θ in θ, φ in φ]
z = [cos(θ) for θ in θ, φ in φ]
function scale01(xs)
mi, ma = extrema(xs)
(xs .- mi) ./ (ma - mi)
end
function compute_color(l,m)
vals = [Y(l,m)(θ, φ) for θ in θ, φ in φ]
Float32.(scale01(imag.(vals))) * RGBf0(1,1,1)
end
scene = Scene(raw = false, resolution = (500, 500))
surface!(scene, x, y, z)
l = 1
m = 0
thm = Theme(raw = true, camera = campixel!)
sliderl = slider(thm, 1:10, start=l)
# sliderm = slider(thm, -10:10, start=m)
sliderm = slider(thm, 0:10, start=m)
on(sliderl[end][:value]) do l_new
global l = l_new
scene[end][:color] = compute_color(l,m)
end
on(sliderm[end][:value]) do m_new
global m = clamp(m_new, -l, l)
scene[end][:color] = compute_color(l,m)
end
scene[end][:color] = compute_color(l,m)
vbox(
hbox(sliderl,sliderm),
scene)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment