Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 8171d54

Browse files
authored
Merge pull request #418 from JuliaPlots/sd/fixes
fixes
2 parents 5d0e66d + 7040503 commit 8171d54

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

src/basic_recipes/basic_recipes.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,9 @@ function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
702702
end
703703
volume!(
704704
plot, x, y, z, volume, colormap = cmap, colorrange = cliprange, algorithm = 7,
705-
transparency = plot[:transparency],
706-
overdraw = plot[:overdraw]
705+
transparency = plot.transparency, overdraw = plot.overdraw,
706+
ambient = plot.ambient, diffuse = plot.diffuse, lightposition = plot.lightposition,
707+
shininess = plot.shininess, specular = plot.specular
707708
)
708709
end
709710

src/conversions.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ end
567567
convert_attribute(c::Colorant, ::key"color") = convert(RGBA{Float32}, c)
568568
convert_attribute(c::Symbol, k::key"color") = convert_attribute(string(c), k)
569569
function convert_attribute(c::String, ::key"color")
570-
c in all_gradient_names && return to_colormap(c)
571-
parse(RGBA{Float32}, c)
570+
return parse(RGBA{Float32}, c)
572571
end
573572

574573
# Do we really need all colors to be RGBAf0?!
@@ -578,9 +577,11 @@ convert_attribute(c::AbstractArray{<: Union{Tuple{Any, Number}, Symbol}}, k::key
578577
convert_attribute(c::AbstractArray, ::key"color", ::key"heatmap") = el32convert(c)
579578

580579
convert_attribute(c::Tuple, k::key"color") = convert_attribute.(c, k)
580+
581581
function convert_attribute(c::Tuple{T, F}, k::key"color") where {T, F <: Number}
582582
RGBAf0(Colors.color(to_color(c[1])), c[2])
583583
end
584+
584585
convert_attribute(c::Billboard, ::key"rotations") = Quaternionf0(0, 0, 0, 1)
585586
convert_attribute(r::AbstractArray, ::key"rotations") = to_rotation.(r)
586587
convert_attribute(r::StaticVector, ::key"rotations") = to_rotation(r)
@@ -802,7 +803,7 @@ function convert_attribute(cs::Union{String, Symbol}, ::key"colormap", n::Intege
802803
if cs_string in colorbrewer_8color_names # special handling for 8 color only
803804
return to_colormap(ColorBrewer.palette(cs_string, 8), n)
804805
else # cs_string must be in plotutils_names
805-
return to_colormap(PlotUtils.get_colorscheme(:viridis).colors, n)
806+
return to_colormap(PlotUtils.get_colorscheme(Symbol(cs_string)).colors, n)
806807
end
807808
else
808809
error("There is no color gradient named: $cs")

test/simple.jl

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ using GLMakie
33
using GeometryBasics
44
using Observables
55
using FileIO
6-
using MakieGallery
76
using GeometryBasics: Pyramid
7+
using PlotUtils
88

9-
scatter(1:4, color=rand(RGBf0, 4))
9+
scatter(1:4, color=rand(RGBf0, 4)) |> display
1010
scatter(1:4, color=:red)
1111

1212
scatter(1:4, marker='')
@@ -69,12 +69,15 @@ contour(rand(4, 4, 4)) |> display
6969
# Meshes
7070
using MeshIO, FileIO
7171
cat = load(GLMakie.assetpath("cat.obj"))
72-
tex = load(GLMakie.assetpath("diffusemap.tga"))
72+
tex = load(GLMakie.assetpath("diffusemap.tga"));
7373
scren = mesh(cat, color=tex)
7474

7575
m = mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue],
7676
shading = false) |> display
7777

78+
meshes = GeometryBasics.normal_mesh.([Sphere(Point3f0(0.5), 1), Rect(Vec3f0(1, 0, 0), Vec3f0(1))])
79+
mesh(meshes, color=[1, 2])
80+
7881
# Axis
7982
scene = lines(IRect(Vec2f0(0), Vec2f0(1)))
8083
axis = scene[Axis]
@@ -85,3 +88,60 @@ scene
8588

8689
# Text
8790
x = text("heyllo") |> display
91+
92+
93+
# Gradients
94+
data = ((x, y) -> x^2 + y^2).(1:100, (1:100)')
95+
heatmap(data; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true)
96+
97+
98+
# Animations
99+
function n_times(f, n=10, interval=0.05)
100+
obs = Observable(f(1))
101+
@async for i in 2:n
102+
try
103+
obs[] = f(i)
104+
sleep(interval)
105+
catch e
106+
@warn "Error!" exception=CapturedException(e, Base.catch_backtrace())
107+
end
108+
end
109+
return obs
110+
end
111+
112+
annotations(n_times(i-> map(j-> ("$j", Point2f0(j*30, 0)), 1:i)), textsize=20, limits=FRect2D(30, 0, 320, 50))
113+
scatter(n_times(i-> Point2f0.((1:i).*30, 0)), limits=FRect2D(30, 0, 320, 50), markersize=20px)
114+
linesegments(n_times(i-> Point2f0.((2:2:2i).*30, 0)), limits=FRect2D(30, 0, 620, 50), markersize=20px)
115+
lines(n_times(i-> Point2f0.((2:2:2i).*30, 0)), limits=FRect2D(30, 0, 620, 50), markersize=20px)
116+
117+
118+
# Set up sliders to control lighting attributes
119+
s1, ambient = textslider(0f0:0.01f0:1f0, "ambient", start = 0.55f0)
120+
s2, diffuse = textslider(0f0:0.025f0:2f0, "diffuse", start = 0.4f0)
121+
s3, specular = textslider(0f0:0.025f0:2f0, "specular", start = 0.2f0)
122+
s4, shininess = textslider(2f0.^(2f0:8f0), "shininess", start = 32f0)
123+
124+
# Set up (r, θ, ϕ) for lightposition
125+
s5, radius = textslider(2f0.^(0.5f0:0.25f0:20f0), "light pos r", start = 2f0)
126+
s6, theta = textslider(0:5:180, "light pos theta", start = 30f0)
127+
s7, phi = textslider(0:5:360, "light pos phi", start = 45f0)
128+
129+
# transform signals into required types
130+
la = map(Vec3f0, ambient)
131+
ld = map(Vec3f0, diffuse)
132+
ls = map(Vec3f0, specular)
133+
lp = map(radius, theta, phi) do r, theta, phi
134+
r * Vec3f0(
135+
cosd(phi) * sind(theta),
136+
sind(phi) * sind(theta),
137+
cosd(theta)
138+
)
139+
end
140+
141+
scene = Scene()
142+
contour!(scene, 0..1, 0..1, 0..1, rand(10, 10, 10), levels = 2;
143+
ambient = la, diffuse = ld, specular = ls, shininess = shininess,
144+
lightposition = lp)
145+
scatter!(scene, map(v -> [v], lp), color=:yellow, markersize=0.2f0)
146+
147+
vbox(hbox(s4, s3, s2, s1, s7, s6, s5), scene) |> display

0 commit comments

Comments
 (0)