Created
November 6, 2018 10:22
-
-
Save SimonDanisch/953925b3f7fe3aee60d789d051d63eb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Makie | |
N = 100 | |
scene = mesh( | |
FRect3D(Vec3f0(-0.5), Vec3f0(1)), color = :skyblue2, | |
) | |
rect = scene[end] # last plot is the rect | |
# there are a couple of ratate! functions, that accept e.g. a vector etc | |
rotate!(rect, Quaternionf0(0, 0.4, 0, 1)) | |
scene | |
function create_poly(x, y1, y2, where::Nothing) | |
x, y1, y2 | |
end | |
function create_poly(x, y1, y2, where::Function) | |
create_poly(x, y1, y2, where.(x, y1, y2)) | |
view(x, bools), view(y1, bools), view(y2, bools) | |
end | |
function create_poly(x, y1, y2, bools::AbstractVector{<: Union{Integer, Bool}}) | |
polygon = Vector{Point2f0}[] | |
b_state = iterate(bools) | |
poly1 = Point2f0[] | |
poly2 = Point2f0[] | |
for (i, b) in enumerate(bools) | |
if b | |
push!(poly1, Point2f0(x[i], y1[i])) | |
pushfirst!(poly2, Point2f0(x[i], y2[i])) | |
else | |
isempty(poly1) || push!(polygon, unique!(vcat(poly1, poly2))) | |
poly1 = Point2f0[] | |
poly2 = Point2f0[] | |
end | |
end | |
isempty(poly1) || push!(polygon, unique!(vcat(poly1, poly2))) | |
polygon | |
end | |
function fill_between!(x, y1, y2; where = nothing, scene = AbstractPlotting.current_scene(), kw_args...) | |
polygon = create_poly(x, y1, y2, where) | |
for poly in polygon | |
poly!(scene, poly; kw_args...) | |
end | |
scene | |
end | |
x = -5:0.01:5 | |
y1 = -5 .* x .* x .+ x .+ 10 | |
y2 = 5 .* x .* x .+ x | |
scene = lines(x, y1) | |
lines!(x, y2) | |
fill_between!(x, y1, y2, where = y2 .> y1, color = :yellow) | |
fill_between!(x, y1, y2, where = y2 .<= y1, color = :red) | |
scene |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment