From 3bf149ede10b3e2b67e7cc09eec177abce62e37b Mon Sep 17 00:00:00 2001 From: Arsh <184517@nith.ac.in> Date: Wed, 23 Jun 2021 17:14:17 +0530 Subject: [PATCH 1/4] Draw a line --- src/Javis.jl | 3 +- src/action_animations.jl | 5 +++ src/shorthands.jl | 71 ++++++++++++++++++++++++++++++++++++++++ src/structs/Creations.jl | 15 +++++++++ src/structs/Object.jl | 5 ++- 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/shorthands.jl create mode 100644 src/structs/Creations.jl diff --git a/src/Javis.jl b/src/Javis.jl index d95cf82f5..80fa0caaf 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) diff --git a/src/action_animations.jl b/src/action_animations.jl index f297ffa2c..746fb15af 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.result[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..2b401d101 --- /dev/null +++ b/src/shorthands.jl @@ -0,0 +1,71 @@ +function _Lineobj(p1, p2, color) + sethue(color) + line(p1, p2,:stroke) + return Dict("shapetype"=>Line, "initial_pos" => p1, "final_pos" => p2, "current_pos" => p1) +end + +Lineobj(p1, p2; color="black") = (args...) -> _Lineobj(p1, p2, color) +Lineobj(p2) = Lineobj(O, p2) + + + + + + + + +#==================# + +# 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..783953693 --- /dev/null +++ b/src/structs/Creations.jl @@ -0,0 +1,15 @@ +function show_creation(Line, obj::Object, action, t) + metadata = obj.result[1] + initial_pos = metadata["initial_pos"] + final_pos = metadata["final_pos"] + if t == 1 + obj.current_setting.mul_opacity = t + action.keep = false + else + obj.current_setting.mul_opacity = 0 + current_pos = metadata["current_pos"] + new_pos = initial_pos + t * (final_pos - initial_pos) + line(current_pos, new_pos,:stroke) + metadata["current_pos"] = new_pos + end +end diff --git a/src/structs/Object.jl b/src/structs/Object.jl index fa96a5b44..488bb688d 100644 --- a/src/structs/Object.jl +++ b/src/structs/Object.jl @@ -80,6 +80,9 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. CURRENT_VIDEO[1].background_frames = union(CURRENT_VIDEO[1].background_frames, frames) end + + metadata = func() + object = Object( frames, func, @@ -88,7 +91,7 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. ObjectSetting(), opts, Dict{Symbol,Any}(), - Any[nothing], + [metadata], ) push!(CURRENT_VIDEO[1].objects, object) return object From 62860ea66ff950466aab9c6a1dc7dfd674494364 Mon Sep 17 00:00:00 2001 From: Arsh <184517@nith.ac.in> Date: Wed, 23 Jun 2021 18:01:20 +0530 Subject: [PATCH 2/4] results need not store only metadata --- src/Javis.jl | 1 + src/structs/Object.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Javis.jl b/src/Javis.jl index 80fa0caaf..f9b595933 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -415,6 +415,7 @@ const LUXOR_DONT_EXPORT = [ :get_fontsize, :scale, :text, + :Circle ] # Export each function from Luxor diff --git a/src/structs/Object.jl b/src/structs/Object.jl index 488bb688d..4fd49a5a6 100644 --- a/src/structs/Object.jl +++ b/src/structs/Object.jl @@ -91,7 +91,7 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. ObjectSetting(), opts, Dict{Symbol,Any}(), - [metadata], + Any[metadata], ) push!(CURRENT_VIDEO[1].objects, object) return object From 2c471ecf3638acbf5419024a0ad1759684a70b75 Mon Sep 17 00:00:00 2001 From: Arsh <184517@nith.ac.in> Date: Wed, 23 Jun 2021 20:24:01 +0530 Subject: [PATCH 3/4] circle object --- src/shorthands.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shorthands.jl b/src/shorthands.jl index 2b401d101..b3c87fe94 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -7,8 +7,12 @@ end Lineobj(p1, p2; color="black") = (args...) -> _Lineobj(p1, p2, color) Lineobj(p2) = Lineobj(O, p2) +function _Circle(center, radius, color, action) +end +Circle(center, radius, color="black", action=:fill) = (args...) -> _Circle(center, radius, color, action) +Circle(p1, p2; color="black", action=:fill) = _Circle(, , color, action) From d72b74f3c8ee8110ec80e02c681254959382ba33 Mon Sep 17 00:00:00 2001 From: Arsh <184517@nith.ac.in> Date: Thu, 24 Jun 2021 04:47:57 +0530 Subject: [PATCH 4/4] Circle object declaration and drawing --- src/action_animations.jl | 2 +- src/shorthands.jl | 25 +++++++++++++++++-------- src/structs/Creations.jl | 35 ++++++++++++++++++++++++++++------- src/structs/Object.jl | 11 +++++++++-- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/action_animations.jl b/src/action_animations.jl index 746fb15af..420b80fe7 100644 --- a/src/action_animations.jl +++ b/src/action_animations.jl @@ -49,7 +49,7 @@ end function _appear(video, object, action, rel_frame, symbol::Val{:draw}) t = get_interpolation(action, rel_frame) - show_creation(object.result[1]["shapetype"], object, action, t) + show_creation(object.metadata[1]["shapetype"], object, action, t) end """ diff --git a/src/shorthands.jl b/src/shorthands.jl index b3c87fe94..c4449fe83 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -1,22 +1,31 @@ +abstract type Circle end + function _Lineobj(p1, p2, color) sethue(color) line(p1, p2,:stroke) - return Dict("shapetype"=>Line, "initial_pos" => p1, "final_pos" => p2, "current_pos" => p1) + 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(p1, p2; color="black") = (args...) -> _Lineobj(p1, p2, color) Lineobj(p2) = Lineobj(O, p2) function _Circle(center, radius, color, action) - + sethue(color) + circle(center, radius, action) + return end -Circle(center, radius, color="black", action=:fill) = (args...) -> _Circle(center, radius, color, action) -Circle(p1, p2; color="black", action=:fill) = _Circle(, , color, action) - - - +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) #==================# diff --git a/src/structs/Creations.jl b/src/structs/Creations.jl index 783953693..f6616a382 100644 --- a/src/structs/Creations.jl +++ b/src/structs/Creations.jl @@ -1,15 +1,36 @@ -function show_creation(Line, obj::Object, action, t) - metadata = obj.result[1] +# 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 - obj.current_setting.mul_opacity = t - action.keep = false + restore_object(t, obj, action) else obj.current_setting.mul_opacity = 0 - current_pos = metadata["current_pos"] new_pos = initial_pos + t * (final_pos - initial_pos) - line(current_pos, new_pos,:stroke) - metadata["current_pos"] = new_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 4fd49a5a6..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...) @@ -81,8 +83,11 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. union(CURRENT_VIDEO[1].background_frames, frames) end - metadata = func() - + if !isempty(CURRENT_OBJECT_META) + metadata = CURRENT_OBJECT_META[1] + else + metadata = nothing + end object = Object( frames, func, @@ -91,8 +96,10 @@ function Object(frames, func::Function, start_pos::Union{Object,Point}; kwargs.. ObjectSetting(), opts, Dict{Symbol,Any}(), + Any[nothing], Any[metadata], ) + empty!(CURRENT_OBJECT_META) push!(CURRENT_VIDEO[1].objects, object) return object end