From d9a2d21ae2d5417d5a3fcda0339d55d208d64faa Mon Sep 17 00:00:00 2001 From: Petr Krysl Date: Tue, 26 Sep 2023 13:51:10 -0700 Subject: [PATCH] update examples --- examples/beams/graphics/edit_plot.jl | 47 ++++++++------ examples/beams/graphics/loading_plot.jl | 51 +++++++++------ examples/beams/graphics/making_frames.jl | 79 ++++++++++++++---------- 3 files changed, 104 insertions(+), 73 deletions(-) diff --git a/examples/beams/graphics/edit_plot.jl b/examples/beams/graphics/edit_plot.jl index b814072..0a38c47 100644 --- a/examples/beams/graphics/edit_plot.jl +++ b/examples/beams/graphics/edit_plot.jl @@ -1,31 +1,40 @@ +module edit_plot_examples using FinEtools -using FinEtoolsFlexStructures.FESetCorotBeamModule: FESetL2CorotBeam +using FinEtoolsFlexStructures.FESetL2BeamModule: FESetL2Beam using FinEtoolsFlexStructures.CrossSectionModule: CrossSectionCircle, CrossSectionRectangle using FinEtoolsFlexStructures.MeshFrameMemberModule: frame_member, merge_members using VisualStructures: plot_nodes, plot_midline, render, plot_space_box, plot_solid, space_aspectratio, default_layout_3d, plot_from_json using PlotlyJS using JSON -L = 42 -xyz = [0 0 0; -0 L/4 L*1/4; -L/4 L/4 L*2/4; -L/4 0 L*3/4; -0 0 L] -nL = 20 +function allrun() -cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) -fens, fes = frame_member(xyz, nL, cs) -plots = cat(plot_nodes(fens), - plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), - dims = 1) -layout = default_layout_3d(autosize=true) + L = 42 + xyz = [0 0 0; + 0 L/4 L*1/4; + L/4 L/4 L*2/4; + L/4 0 L*3/4; + 0 0 L] + nL = 20 + + cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) + fens, fes = frame_member(xyz, nL, cs) + plots = cat(plot_nodes(fens), + plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), + dims = 1) + layout = default_layout_3d(autosize=true) # layout = default_layout_3d(width=400, height=400) -layout[:showLegend] = true + layout[:showLegend] = true + + config = PlotConfig(plotlyServerURL="https://chart-studio.plotly.com", showLink=true) + pl = plot(plots, layout; config = config) -config = PlotConfig(plotlyServerURL="https://chart-studio.plotly.com", showLink=true) -pl = plot(plots, layout; config = config) + display(pl) + true +end -display(pl) -true +@info "All examples may be executed with " +println("using .$(@__MODULE__); $(@__MODULE__).allrun()") +end # module +nothing diff --git a/examples/beams/graphics/loading_plot.jl b/examples/beams/graphics/loading_plot.jl index 6cff7a4..0734f14 100644 --- a/examples/beams/graphics/loading_plot.jl +++ b/examples/beams/graphics/loading_plot.jl @@ -1,35 +1,46 @@ +module edit_plot_examples using FinEtools -using FinEtoolsFlexStructures.FESetCorotBeamModule: FESetL2CorotBeam +using FinEtoolsFlexStructures.FESetL2BeamModule: FESetL2Beam using FinEtoolsFlexStructures.CrossSectionModule: CrossSectionCircle, CrossSectionRectangle using FinEtoolsFlexStructures.MeshFrameMemberModule: frame_member, merge_members using VisualStructures: plot_nodes, plot_midline, render, plot_space_box, plot_solid, space_aspectratio, default_layout_3d, plot_from_json using PlotlyJS using JSON -L = 42 -xyz = [0 0 0; -0 L/4 L*1/4; -L/4 L/4 L*2/4; -L/4 0 L*3/4; -0 0 L] -nL = 20 +function allrun() -cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) -fens, fes = frame_member(xyz, nL, cs) -plots = cat(plot_nodes(fens), - plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), - dims = 1) -layout = default_layout_3d(width = 500, height = 500) -layout[:title] = "" -config = PlotConfig(plotlyServerURL="https://chart-studio.plotly.com", showLink=true) + L = 42 + xyz = [0 0 0; + 0 L/4 L*1/4; + L/4 L/4 L*2/4; + L/4 0 L*3/4; + 0 0 L] + nL = 20 + cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) + fens, fes = frame_member(xyz, nL, cs) + plots = cat(plot_nodes(fens), + plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), + dims = 1) + layout = default_layout_3d(width = 500, height = 500) + layout[:title] = "" + config = PlotConfig(plotlyServerURL="https://chart-studio.plotly.com", showLink=true) -pl = plot(plots, layout; config=config) -display(pl) + pl = plot(plots, layout; config=config) -savejson(pl, "plot.json") + display(pl) + + savejson(pl, "plot.json") # The below works when run interactively from the command line: -pl = plot_from_json("plot.json") + pl = plot_from_json("plot.json") + true +end + +@info "All examples may be executed with " +println("using .$(@__MODULE__); $(@__MODULE__).allrun()") + +end # module +nothing diff --git a/examples/beams/graphics/making_frames.jl b/examples/beams/graphics/making_frames.jl index 5dc1b27..0a14e4a 100644 --- a/examples/beams/graphics/making_frames.jl +++ b/examples/beams/graphics/making_frames.jl @@ -1,45 +1,51 @@ +module making_frames_examples using FinEtools -using FinEtoolsFlexStructures.FESetCorotBeamModule: FESetL2CorotBeam +using FinEtoolsFlexStructures.FESetL2BeamModule: FESetL2Beam using FinEtoolsFlexStructures.CrossSectionModule: CrossSectionCircle, CrossSectionRectangle using FinEtoolsFlexStructures.MeshFrameMemberModule: frame_member, merge_members using VisualStructures: plot_nodes, plot_midline, render, plot_space_box, plot_solid, space_aspectratio, default_layout_3d, plot_from_json using PlotlyJS using JSON -L = 42 -xyz = [0 0 0; -0 L/4 L*1/4; -L/4 L/4 L*2/4; -L/4 0 L*3/4; -0 0 L] -nL = 20 - -cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) -fens, fes = frame_member(xyz, nL, cs) -plots = cat(plot_nodes(fens), - plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), - dims = 1) -layout = default_layout_3d(width = 500, height = 500) -layout[:title] = "" - - -pl = plot(plots, layout; - config=PlotConfig(showLink = true, toImageButtonOptions = Dict(:format=>"webp"))) -display(pl) - -f(frame) = if frame < 10; "0$frame"; else "$frame"; end - -sleep(0.5) -let - frame = 1 - for eyex in 1.0:-0.1:-1.0 - pl.plot.layout["scene"][:camera][:eye][:x] = eyex - pl.plot.layout[:title] = "$(eyex)" - react!(pl, pl.plot.data, pl.plot.layout) - sleep(0.05) - savefig(pl, "a$(f(frame)).png") - frame += 1 +function allrun() + + L = 42 + xyz = [0 0 0; + 0 L/4 L*1/4; + L/4 L/4 L*2/4; + L/4 0 L*3/4; + 0 0 L] + nL = 20 + + cs = CrossSectionCircle(s -> 5.9910, s -> [0.0, 0.0, 1.0]) + fens, fes = frame_member(xyz, nL, cs) + plots = cat(plot_nodes(fens), + plot_midline(fens, fes; color = "rgb(155, 155, 255)", lwidth = 4), + dims = 1) + layout = default_layout_3d(width = 500, height = 500) + layout[:title] = "" + + + pl = plot(plots, layout; + config=PlotConfig(showLink = true, toImageButtonOptions = Dict(:format=>"webp"))) + display(pl) + + f(frame) = if frame < 10; "0$frame"; else "$frame"; end + + sleep(0.5) + let + frame = 1 + for eyex in 1.0:-0.1:-1.0 + pl.plot.layout["scene"][:camera][:eye][:x] = eyex + pl.plot.layout[:title] = "$(eyex)" + react!(pl, pl.plot.data, pl.plot.layout) + sleep(0.05) + savefig(pl, "a$(f(frame)).png") + frame += 1 + end end + true + end # Convert to a gif @@ -61,3 +67,8 @@ end # savefig(pl, "a.png") # end +@info "All examples may be executed with " +println("using .$(@__MODULE__); $(@__MODULE__).allrun()") + +end # module +nothing