diff --git a/src/Javis.jl b/src/Javis.jl index d95cf82f5..f9b595933 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -57,7 +57,6 @@ include("structs/Object.jl") include("structs/Transitions.jl") include("structs/Action.jl") - """ Line @@ -97,10 +96,12 @@ include("luxor_overrides.jl") include("backgrounds.jl") include("svg2luxor.jl") include("morphs.jl") +include("structs/Creations.jl") include("action_animations.jl") include("javis_viewer.jl") include("latex.jl") include("object_values.jl") +include("shorthands.jl") """ projection(p::Point, l::Line) @@ -414,6 +415,7 @@ const LUXOR_DONT_EXPORT = [ :get_fontsize, :scale, :text, + :Circle ] # Export each function from Luxor diff --git a/src/action_animations.jl b/src/action_animations.jl index f297ffa2c..420b80fe7 100644 --- a/src/action_animations.jl +++ b/src/action_animations.jl @@ -47,6 +47,11 @@ function _appear(video, object, action, rel_frame, symbol::Val{:draw_text}) object.opts[:draw_text_t] = t end +function _appear(video, object, action, rel_frame, symbol::Val{:draw}) + t = get_interpolation(action, rel_frame) + show_creation(object.metadata[1]["shapetype"], object, action, t) +end + """ disappear(s::Symbol) diff --git a/src/shorthands.jl b/src/shorthands.jl new file mode 100644 index 000000000..c4449fe83 --- /dev/null +++ b/src/shorthands.jl @@ -0,0 +1,84 @@ +abstract type Circle end + +function _Lineobj(p1, p2, color) + sethue(color) + line(p1, p2,:stroke) + return +end + +function Lineobj(p1, p2; color="black") + push!(CURRENT_OBJECT_META, Dict("shapetype"=>Line, "initial_pos" => p1, "final_pos" => p2)) + return (args...) -> _Lineobj(p1, p2, color) +end + +Lineobj(p2) = Lineobj(O, p2) + +function _Circle(center, radius, color, action) + sethue(color) + circle(center, radius, action) + return +end + +function Circle(center::Point, radius::Real; color="black", action=:fill) + push!(CURRENT_OBJECT_META, Dict("shapetype"=>Circle, "center" => center, "radius" => radius, "current_angle" => 0.0)) + return (args...) -> _Circle(center, radius, color, action) +end + +Circle(center_x::Real, center_y::Real, radius::Real; color="black", action=:fill) = Circle(Point(center_x, center_y), radius, color, action) +Circle(p1::Real, p2::Real; color="black", action=:fill) = Circle(midpoint(p1, p2), distance(pt1, pt2)/2, color, action) + +#==================# + +# macros are difficult to generalize with all the different parameters taken by luxor methods + +# macro shapetoobj(name::String, frames, start_pos, func)# todo have some defualt arguments here....defaults in the macro call +# expr = quote +# function ($(Symbol(name)))(frames=$frames, start_pos=$start_pos, func=$func) +# return Object(frames, (args...)->func, start_pos) +# end +# end +# return esc(expr) +# end +# @shapetoobj "JCircle" 1:15 O begin +# circle() +# end + +# function Circle(frames::UnitRange=1:15, center::Point=O, radius::Real=40, action::Symbol=:stroke, color::String="black") +# function func(color, center, radius, action) +# sethue(color) +# circle(center, radius ,action) +# end +# return Object(frames, (args...)->func(color, center, radius, action)) +# end + +# function Circle(frames::UnitRange=1:15, center_x::Float64=0, center_y::Float64=0, radius::Float64=40, action::Symbol=:stroke, color::String="black") +# Circle(frames, Point(center_x, center_y), radius, action, color) +# end + +# function Circle(frames::UnitRange=1:15, p1::Point=Point(20, 0), p2::Point=Point(-20, 0), p3::Point=Point(0, 20), action::Symbol=:stroke, color::String="black") +# sethue(color) +# return Object(frames, (args...)->circle(p1, p2, p3,action)) +# end + +# function Circle(frames::UnitRange=1:15, p1::Point=Point(20, 0), p2::Point=Point(-20, 0), action::Symbol=:stroke, color::String="black") +# sethue(color) +# return Object(frames, (args...)->circle(p1, p2, action)) +# end + +# function shift!(obj::Object, frames::UnitRange=obj.frames, fp::Union{Object,Point}=O, tp::Union{Object,Point}=O, easing=nothing) +# if easing !== nothing +# act!(obj, Action(frames, easing, anim_translate(fp, tp))) +# else +# act!(obj, Action(frames, anim_translate(fp, tp))) +# end +# end + +# function shift!(obj::Object, fp::Union{Object,Point}=O, tp::Union{Object,Point}=O, easing=nothing) +# act!(obj, Action(anim_translate(fp, tp))) +# end + +# function shift!(obj::Object, frames::UnitRange=obj.frames, fp::Union{Object,Point}=O, tp::Union{Object,Point}=O, easing=nothing) +# act!(obj, Action(frames, anim_translate(fp, tp))) +# end + + diff --git a/src/structs/Creations.jl b/src/structs/Creations.jl new file mode 100644 index 000000000..f6616a382 --- /dev/null +++ b/src/structs/Creations.jl @@ -0,0 +1,36 @@ +# to get a flash traversing the path...pass the last position instead of initial + +function show_creation(::Type{Line}, obj::Object, action, t) + metadata = obj.metadata[1] + initial_pos = metadata["initial_pos"] + final_pos = metadata["final_pos"] + if t == 1 + restore_object(t, obj, action) + else + obj.current_setting.mul_opacity = 0 + new_pos = initial_pos + t * (final_pos - initial_pos) + line(initial_pos, new_pos,:stroke) + end +end + +function show_creation(::Type{Circle}, obj::Object, action, t) + metadata = obj.metadata[1] + center = metadata["center"] + radius = metadata["radius"] + + if t == 1 + restore_object(t, obj, action) + else + current_angle = metadata["current_angle"] + obj.current_setting.mul_opacity = 0 + new_angle = t * 6 + pie(center, radius+10, 0, new_angle, :clip) + circle(center, radius, :stroke) + obj.metadata[1]["current_angle"] = new_angle + end +end + +function restore_object(t, obj, action) + obj.current_setting.mul_opacity = t + action.keep = false +end \ No newline at end of file diff --git a/src/structs/Object.jl b/src/structs/Object.jl index fa96a5b44..4c13755b3 100644 --- a/src/structs/Object.jl +++ b/src/structs/Object.jl @@ -23,6 +23,7 @@ struct Object <: AbstractObject opts::Dict{Symbol,Any} change_keywords::Dict{Symbol,Any} result::Vector + metadata::Vector end """ @@ -33,6 +34,7 @@ The current object can be accessed using CURRENT_OBJECT[1] """ const CURRENT_OBJECT = Array{Object,1}() +const CURRENT_OBJECT_META = Array{Any,1}() Object(func::Function, args...; kwargs...) = Object(:same, func, args...; kwargs...) @@ -80,6 +82,12 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. CURRENT_VIDEO[1].background_frames = union(CURRENT_VIDEO[1].background_frames, frames) end + + if !isempty(CURRENT_OBJECT_META) + metadata = CURRENT_OBJECT_META[1] + else + metadata = nothing + end object = Object( frames, func, @@ -89,7 +97,9 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. opts, Dict{Symbol,Any}(), Any[nothing], + Any[metadata], ) + empty!(CURRENT_OBJECT_META) push!(CURRENT_VIDEO[1].objects, object) return object end