From 476289d355030767f6134aa7bbb8be9095bf57b4 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Tue, 28 Apr 2020 23:23:54 +0200 Subject: [PATCH 1/3] add some animation test --- test/simple.jl | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/test/simple.jl b/test/simple.jl index d76359d89..3380a71a7 100644 --- a/test/simple.jl +++ b/test/simple.jl @@ -3,10 +3,9 @@ using GLMakie using GeometryBasics using Observables using FileIO -using MakieGallery using GeometryBasics: Pyramid -scatter(1:4, color=rand(RGBf0, 4)) +scatter(1:4, color=rand(RGBf0, 4)) |> display scatter(1:4, color=:red) scatter(1:4, marker='☼') @@ -69,12 +68,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] @@ -85,3 +87,23 @@ scene # Text x = text("heyllo") |> display + + +# 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) From 1efe7999f4b63f91d981cb89002bb457e6453e68 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 29 Apr 2020 00:36:07 +0200 Subject: [PATCH 2/3] fix light for volume + colors --- src/basic_recipes/basic_recipes.jl | 5 ++-- src/conversions.jl | 5 ++-- test/simple.jl | 38 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/basic_recipes/basic_recipes.jl b/src/basic_recipes/basic_recipes.jl index d3ec4befe..d7a058816 100644 --- a/src/basic_recipes/basic_recipes.jl +++ b/src/basic_recipes/basic_recipes.jl @@ -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 diff --git a/src/conversions.jl b/src/conversions.jl index bb12ed4a7..edbefd3c6 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -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?! @@ -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) diff --git a/test/simple.jl b/test/simple.jl index 3380a71a7..203691010 100644 --- a/test/simple.jl +++ b/test/simple.jl @@ -4,6 +4,7 @@ using GeometryBasics using Observables using FileIO using GeometryBasics: Pyramid +using PlotUtils scatter(1:4, color=rand(RGBf0, 4)) |> display scatter(1:4, color=:red) @@ -89,6 +90,11 @@ scene 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)) @@ -107,3 +113,35 @@ annotations(n_times(i-> map(j-> ("$j", Point2f0(j*30, 0)), 1:i)), textsize=20, l 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 From 7040503a591291375cfbe937eac00291d329c4e5 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 29 Apr 2020 15:49:12 +0530 Subject: [PATCH 3/3] fix typo, this is really stupid --- src/conversions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conversions.jl b/src/conversions.jl index edbefd3c6..5dc57e219 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -803,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")