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

Commit

Permalink
Merge pull request #418 from JuliaPlots/sd/fixes
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
SimonDanisch authored Apr 29, 2020
2 parents 5d0e66d + 7040503 commit 8171d54
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/basic_recipes/basic_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,9 @@ function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
end
volume!(
plot, x, y, z, volume, colormap = cmap, colorrange = cliprange, algorithm = 7,
transparency = plot[:transparency],
overdraw = plot[:overdraw]
transparency = plot.transparency, overdraw = plot.overdraw,
ambient = plot.ambient, diffuse = plot.diffuse, lightposition = plot.lightposition,
shininess = plot.shininess, specular = plot.specular
)
end

Expand Down
7 changes: 4 additions & 3 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,7 @@ end
convert_attribute(c::Colorant, ::key"color") = convert(RGBA{Float32}, c)
convert_attribute(c::Symbol, k::key"color") = convert_attribute(string(c), k)
function convert_attribute(c::String, ::key"color")
c in all_gradient_names && return to_colormap(c)
parse(RGBA{Float32}, c)
return parse(RGBA{Float32}, c)
end

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

convert_attribute(c::Tuple, k::key"color") = convert_attribute.(c, k)

function convert_attribute(c::Tuple{T, F}, k::key"color") where {T, F <: Number}
RGBAf0(Colors.color(to_color(c[1])), c[2])
end

convert_attribute(c::Billboard, ::key"rotations") = Quaternionf0(0, 0, 0, 1)
convert_attribute(r::AbstractArray, ::key"rotations") = to_rotation.(r)
convert_attribute(r::StaticVector, ::key"rotations") = to_rotation(r)
Expand Down Expand Up @@ -802,7 +803,7 @@ function convert_attribute(cs::Union{String, Symbol}, ::key"colormap", n::Intege
if cs_string in colorbrewer_8color_names # special handling for 8 color only
return to_colormap(ColorBrewer.palette(cs_string, 8), n)
else # cs_string must be in plotutils_names
return to_colormap(PlotUtils.get_colorscheme(:viridis).colors, n)
return to_colormap(PlotUtils.get_colorscheme(Symbol(cs_string)).colors, n)
end
else
error("There is no color gradient named: $cs")
Expand Down
66 changes: 63 additions & 3 deletions test/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ using GLMakie
using GeometryBasics
using Observables
using FileIO
using MakieGallery
using GeometryBasics: Pyramid
using PlotUtils

scatter(1:4, color=rand(RGBf0, 4))
scatter(1:4, color=rand(RGBf0, 4)) |> display
scatter(1:4, color=:red)

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

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

meshes = GeometryBasics.normal_mesh.([Sphere(Point3f0(0.5), 1), Rect(Vec3f0(1, 0, 0), Vec3f0(1))])
mesh(meshes, color=[1, 2])

# Axis
scene = lines(IRect(Vec2f0(0), Vec2f0(1)))
axis = scene[Axis]
Expand All @@ -85,3 +88,60 @@ scene

# Text
x = text("heyllo") |> display


# Gradients
data = ((x, y) -> x^2 + y^2).(1:100, (1:100)')
heatmap(data; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true)


# Animations
function n_times(f, n=10, interval=0.05)
obs = Observable(f(1))
@async for i in 2:n
try
obs[] = f(i)
sleep(interval)
catch e
@warn "Error!" exception=CapturedException(e, Base.catch_backtrace())
end
end
return obs
end

annotations(n_times(i-> map(j-> ("$j", Point2f0(j*30, 0)), 1:i)), textsize=20, limits=FRect2D(30, 0, 320, 50))
scatter(n_times(i-> Point2f0.((1:i).*30, 0)), limits=FRect2D(30, 0, 320, 50), markersize=20px)
linesegments(n_times(i-> Point2f0.((2:2:2i).*30, 0)), limits=FRect2D(30, 0, 620, 50), markersize=20px)
lines(n_times(i-> Point2f0.((2:2:2i).*30, 0)), limits=FRect2D(30, 0, 620, 50), markersize=20px)


# Set up sliders to control lighting attributes
s1, ambient = textslider(0f0:0.01f0:1f0, "ambient", start = 0.55f0)
s2, diffuse = textslider(0f0:0.025f0:2f0, "diffuse", start = 0.4f0)
s3, specular = textslider(0f0:0.025f0:2f0, "specular", start = 0.2f0)
s4, shininess = textslider(2f0.^(2f0:8f0), "shininess", start = 32f0)

# Set up (r, θ, ϕ) for lightposition
s5, radius = textslider(2f0.^(0.5f0:0.25f0:20f0), "light pos r", start = 2f0)
s6, theta = textslider(0:5:180, "light pos theta", start = 30f0)
s7, phi = textslider(0:5:360, "light pos phi", start = 45f0)

# transform signals into required types
la = map(Vec3f0, ambient)
ld = map(Vec3f0, diffuse)
ls = map(Vec3f0, specular)
lp = map(radius, theta, phi) do r, theta, phi
r * Vec3f0(
cosd(phi) * sind(theta),
sind(phi) * sind(theta),
cosd(theta)
)
end

scene = Scene()
contour!(scene, 0..1, 0..1, 0..1, rand(10, 10, 10), levels = 2;
ambient = la, diffuse = ld, specular = ls, shininess = shininess,
lightposition = lp)
scatter!(scene, map(v -> [v], lp), color=:yellow, markersize=0.2f0)

vbox(hbox(s4, s3, s2, s1, s7, s6, s5), scene) |> display

0 comments on commit 8171d54

Please sign in to comment.