Public functions
Javis.Action
— TypeAction
Defines what is drawn in a defined frame range.
Fields
frames::Frames
: A range of frames for which theAction
is calledid::Union{Nothing, Symbol}
: An id which can be used to save the result offunc
func::Function
: The drawing function which draws something on the canvas. It gets called with the argumentsvideo, action, frame
anim::Animation
: defines the interpolation function for the transitionstransitions::Vector{Transition}
a list of transitions which can be performed before the function gets called.internal_transitions::Vector{InternalTransition}
: Similar totransitions
but holds the concrete information whereasTransition
can hold links to other actions which need to be computed first. Seecompute_transition!
opts::Any
can hold any options defined by the userchange_keywords::Vector{Pair}
Javis.Action
— MethodAction(frames, func::Function, args...)
The most simple form of an action (if there are no args
/kwargs
) just calls func(video, action, frame)
for each of the frames it is defined for. args
are defined it the next function definition and can be seen in action in this example javis
Javis.Action
— MethodAction(frames, id::Union{Nothing,Symbol}, func::Function,
transitions::Transition...; kwargs...)
Arguments
frames
: defines for which frames this action is calledid::Symbol
: Is used if thefunc
returns something which shall be accessible by other actions laterfunc::Function
the function that is called after thetransitions
are performedtransitions::Transition...
a list of transitions that are performed before the functionfunc
itself is called
The keywords arguments will be saved inside .opts
as a Dict{Symbol, Any}
Javis.Action
— MethodAction(frames, id::Union{Nothing,Symbol}, func::Function, easing::Union{ReversedEasing, Easing},
args...; kwargs...)
Fallback constructor for an Action which does define an animation using an easing function.
Example
javis(
video, [
BackgroundAction(1:100, ground),
Action((args...)->t(), sineio(), Translation(250, 0))
]
)
Javis.Action
— MethodAction(frames, id::Union{Nothing,Symbol}, func::Function,
transitions::Transition...; kwargs...)
Fallback constructor for an Action which doesn't define an animation. A linear animation is assumed.
Javis.Action
— MethodAction(func::Function, args...)
Similar to the above but uses the same frames as the action above.
Javis.Action
— MethodAction(frames_or_id::Symbol, func::Function, args...)
This function decides whether you wrote Action(frames_symbol, ...)
, or Action(id_symbol, ...)
If the symbol frames_or_id
is not a FRAMES_SYMBOL
then it is used as an id_symbol.
Javis.Line
— TypeLine
A type to define a line by two points. Can be used i.e. in projection
We mean the mathematic definition of a continuous line and not a segment of a line.
Fields
p1::Point
: start pointp2::Point
: second point to define the line
Javis.Rel
— TypeRel
Ability to define frames in a relative fashion.
Example
Action(1:100, ground; in_global_layer=true),
Action(1:90, :red_ball, (args...)->circ(p1, "red"), Rotation(from_rot, to_rot)),
Action(Rel(10), :blue_ball, (args...)->circ(p2, "blue"), Rotation(2π, from_rot, :red_ball)),
Action((video, args...)->path!(path_of_red, pos(:red_ball), "red"))
is the same as
Action(1:100, ground; in_global_layer=true),
Action(1:90, :red_ball, (args...)->circ(p1, "red"), Rotation(from_rot, to_rot)),
Action(91:100, :blue_ball, (args...)->circ(p2, "blue"), Rotation(2π, from_rot, :red_ball)),
Action(91:100, (video, args...)->path!(path_of_red, pos(:red_ball), "red"))
Fields
- rel::UnitRange defines the frames in a relative fashion.
Javis.Rel
— MethodRel(i::Int)
Shorthand for Rel(1:i)
Javis.Rotation
— TypeRotation <: Transition
Stores the rotation similar to Translation
with from
and to
but also the rotation point.
Fields
from::Union{Float64, Symbol}
: The start rotation or a link to itto::Union{Float64, Symbol}
: The end rotation or a link to itcenter::Union{Point, Symbol}
: The center of the rotation or a link to it.
Javis.Rotation
— MethodRotation(from, to)
Rotation as a transition from from
to to
(in radians) around the origin.
Javis.Rotation
— MethodRotation(r::Union{Float64, Symbol}, center::Union{Point, Symbol})
Rotation as a transition from 0.0
to r
around center
. Can be used as a short-hand for rotating around a center
point.
Javis.Rotation
— MethodRotation(r::Union{Float64, Symbol})
Rotation as a transition from 0.0 to r
. Can be used as a short-hand.
Javis.Scaling
— TypeScaling <: Transition
Stores the scaling similar to Translation
with from
and to
.
Example
- Can be called with different constructors like:
Scaling(10) -> Scaling(CURRENT_SCALING, (10.0, 10.0))
Scaling(10, :my-scale) -> Scaling((10.0, 10.0), :my_scale)
Scaling(10, 2) -> Scaling((10.0, 10.0), (2.0, 2.0))
Scaling(10, (1,2)) -> Scaling((10.0, 10.0), (1.0, 2.0))
Fields
from::Union{Tuple{Float64, Float64}, Symbol}
: The start scaling or a link to itto::Union{Tuple{Float64, Float64}, Symbol}
: The end scaling or a link to itcompute_from_once::Bool
: Saves whether the from is computed for the first frame or every frame. Is true if from is:_current_scale
.
Javis.SubAction
— TypeSubAction <: AbstractAction
A SubAction can be used in the keyword arguments of an Action
to define small sub actions on the action function, such as appear
.
A SubAction should not be created by hand but instead by using one of the constructors.
Fields
frames::Frames
: the frames relative to the parentAction
anim::Animation
: defines the interpolation function for the transitionsfunc::Function
: the function that gets called in each of those frames. Takes the following arguments:video, action, subaction, rel_frame
transitions::Vector{Transition}
: A list of transitions likeTranslation
internal_transitions::Vector{InternalTransition}
: A list of internal transitions which store the current transition for a specific frame.defs::Dict{Symbol, Any}
any kind of definitions that are relevant for the subaction.
Javis.SubAction
— MethodSubAction(frames, func::Function)
A SubAction
can be defined with frames and a function inside the subactions
kwarg of an Action
. In the following example a filled circle with radius 50 appears in the first 20 frames, which means the opacity is increased from 0 to 1.0. Then it stays at full opacity and disappears the same way in the last 20 frames.
Example
javis(demo, [ BackgroundAction(1:100, ground), Action((args...)->circle(O, 50, :fill); subactions = [ SubAction(1:20, appear(:fade)), SubAction(81:100, disappear(:fade)) ]) ])
Arguments
frames
: A list of frames for which the function should be called.- The frame numbers are relative to the parent
Action
.
- The frame numbers are relative to the parent
func::Function
: The function that gets called for the frames.
Javis.SubAction
— MethodSubAction(frames, easing::Union{ReversedEasing, Easing}, args...)
A SubAction
can be defined with frames an easing function and either a function or transformation(s).
Example
In the following example a filled circle with radius 50 appears in the first 20 frames, which means the opacity is increased from 0 to 1.0. The interpolation function used here is sineio from Animations.jl
. Then it stays at full opacity and disappears the same way in the last 20 frames using a linear decay.
javis(demo, [
BackgroundAction(1:100, ground),
Action((args...)->circle(O, 50, :fill); subactions = [
SubAction(1:20, sineio(), appear(:fade)),
SubAction(81:100, disappear(:fade))
])
])
Arguments
frames
: A list of frames for which the function should be called.- The frame numbers are relative to the parent
Action
.
- The frame numbers are relative to the parent
easing::Union{ReversedEasing, Easing}
: The easing function forargs...
args...
: Either a function likeappear
or a Transformation likeTranslation
Javis.SubAction
— MethodSubAction(frames, trans::Transition...)
A SubAction
can also be defined this way with having a list of transitions. This is similar to defining transitions inside Action
In the following example a circle is faded in during the first 25 frames then moves to
Point(100, 20)
then toPoint(120, -20)
(the translations are added)- and then back to the origin
In the last 25 frames it disappears from the world.
Example
javis(demo, [
BackgroundAction(1:200, ground_opacity),
Action((args...)->circle(O, 50, :fill); subactions = [
SubAction(1:25, appear(:fade)),
SubAction(26:75, Translation(Point(100, 20))),
SubAction(76:100, Translation(Point(20, -40))),
SubAction(101:175, Translation(Point(-120, 20))),
SubAction(176:200, disappear(:fade))
]),
], tempdirectory="current/images", pathname="current/circle_square.gif")
Arguments
frames
: A list of frames for which the function should be called.- The frame numbers are relative to the parent
Action
.
- The frame numbers are relative to the parent
trans::Transition...
: A list of transitions that shall be performed.
Javis.Transformation
— TypeTransformation
Defines a transformation which can be returned by an action to be accessible later. See the circ
function inside the javis
as an example.
It can be accessed by another [Action
])(@ref) using the symbol notation like :red_ball
in the example.
Fields
p::Point
: the translation part of the transformationangle::Float64
: the angle component of the transformation (in radians)
Javis.Translation
— TypeTranslation <: Transition
Stores the Point
or a link for the start and end position of the translation
Fields
from::Union{Point, Symbol}
: The start position or a link to the start position. See :red_ball
in javis
to::Union{Point, Symbol}
: The end position or a link to the end position
Javis.Translation
— MethodTranslation(x::Real, y::Real)
Create a Translation(O, Point(x,y))
such that a translation is done from the origin. Shorthand for writing Translation(Point(x,y))
.
Javis.Translation
— MethodTranslation(p::Union{Point, Symbol})
Create a Translation(O, p)
such that a translation is done from the origin.
Javis.Video
— TypeVideo
Defines the video canvas for an animation.
Fields
width::Int
the width in pixelheight::Int
the height in pixeldefs::Dict{Symbol, Any}
Some definitions which should be accessible throughout the video.
Javis.Video
— MethodVideo(width, height)
Create a video with a certain width
and height
in pixel. This also sets CURRENT_VIDEO
.
Base.:*
— MethodBase.:*(m::Array{Float64,2}, transformation::Transformation)
Convert the transformation to a matrix and multiplies m*trans_matrix. Return a new Transformation
Javis.BackgroundAction
— MethodBackgroundAction(frames, func::Function, args...; kwargs...)
Create an Action where in_global_layer
is set to true such that i.e the specified color in the background is applied globally (basically a new default)
Javis.BackgroundAction
— MethodBackgroundAction(frames, id::Symbol, func::Function, args...; kwargs...)
Create an Action where in_global_layer
is set to true and saves the return into id
.
Javis.ang
— Methodang(x)
ang
is just a short-hand for get_angle
Javis.appear
— Methodappear(s::Symbol)
Appear can be used inside a SubAction
Example
Action(101:200, (args...)->house_of_nicholas(); subactions = [
SubAction(1:20, appear(:fade)),
SubAction(81:100, disappear(:fade))
])
In this case the house_of_nicholas
will fade in during the first 20 frames of the Action
so 101-120
.
Arguments
s::Symbol
: the symbol defines the animation of appearance The only symbols that are currently supported are::fade_line_width
which increases the line width up to the default value or the value specified bysetline
:fade
which increases the opcacity up to the default value or the value specified bysetopacity
:scale
which increases the scale up to the default value1
or the value specified byscale
:draw_text
which only works fortext
and lets it appear from left to right.
Javis.change
— Methodchange(s::Symbol, [vals::Pair])
Changes the keyword s
of the parent Action
from vals[1]
to vals[2]
in an animated way.
Arguments
s::Symbol
Change the keyword with the names
vals::Pair
If vals is given i.e0 => 25
it will be animated from 0 to 25.- The default is to use
0 => 1
or use the value given by the animation
SubAction
- The default is to use
Example
myvideo = Video(500, 500)
javis(
myvideo,
[
BackgroundAction(1:100, ground),
Action(
(args...; radius = 25) -> object(Point(100, 0), radius, "red"),
Rotation(0.0, 4π);
subactions = [
SubAction(1:50, change(:radius, 25 => 0))
SubAction(51:100, change(:radius, 0 => 25))
],
)
]; pathname = "current/_change.gif"
)
Javis.disappear
— Methoddisappear(s::Symbol)
Disappear can be used inside a SubAction
Example
Action(101:200, (args...)->house_of_nicholas(); subactions = [
SubAction(1:20, appear(:fade)),
SubAction(81:100, disappear(:fade))
])
In this case the house_of_nicholas
will fade out during the last 20 frames of the Action
so 181-200
.
Arguments
s::Symbol
: the symbol defines the animation of disappearance The only symbols that are currently supported are::fade_line_width
which decreases the line width down to0
:fade
which decreases the opacity down to0
:scale
which decreases the scale down to0
:draw_text
which only works for text and let the text disappear from right to left.
Javis.draw_grid
— Methoddraw_grid(video::Video, action::Action, frame::Int; direction::AbstractString = "TR", line_gap = 25)
Draws an oriented grid on the given frame of a Video.
Arguments
direction::AbstractString
: Where grid animation finishes. Default:"TR"
Available Orientations:"TR"
- Animation finishes in the Top Right corner of the frame."TL"
- Animation finishes in the Top Left corner of the frame."BR"
- Animation finishes in the Bottom Right corner of the frame."BL"
- Animation finishes in the Bottom Left corner of the frame.
line_gap
: How many pixels between each line. Default:25
Example
Example call of this function within an Action
.
...
Action(1:100, :line, draw_grid(direction = "TL", line_gap = 25))
...
Javis.follow_path
— Methodfollow_path(points::Vector{Point}; closed=true)
Can be applied inside a subaction such that the object defined in the parent action follows a path. It takes a vector of points which can be created as an example by calling circle(O, 50)
<- notice that the action is set to :none
the default.
Example
SubAction(1:150, follow_path(star(O, 300)))
Arguments
points::Vector{Point}
- the vector of points the object should follow
Keywords
closed::Bool
default: true, sets whether the path is a closed path as for example when using a circle, ellipse or any polygon. For a bezier path it should be set to false.
Javis.fontsize
— Methodfontsize(fsize)
Same as Luxor.fontsize
: Sets the current font size.
Example
fontsize(12)
text("Hello World!")
Arguments:
fsize
: the new font size
Javis.get_angle
— Methodget_angle(s::Symbol)
Get access to the angle that got saved in s
by a previous action.
Returns
Float64
: the angle stored by a previous action i.e viareturn Transformation(p, angle)
Javis.get_fontsize
— Methodget_fontsize(fsize)
Same as Luxor.get_fontsize
but works with every version of Luxor that is supported by Javis.
Example
fontsize(12)
fsize = get_fontsize()
text("Hello World! $fsize")
Returns
Float64
: the current font size
Javis.get_position
— Methodget_position(s::Symbol)
Get access to the position that got saved in s
by a previous action.
Returns
Point
: the point stored by a previous action.
Javis.get_value
— Methodget_value(s::Symbol)
Get access to the value that got saved in s
by a previous action. If you want to access a position or angle check out get_position
and get_angle
.
Returns
Any
: the value stored by a previous action.
Javis.javis
— Methodjavis(
video::Video,
actions::Vector{AbstractAction};
framerate=30,
pathname="",
tempdirectory="",
liveview=false
)
Similar to animate
in Luxor with a slightly different structure. Instead of using actions and a video instead of scenes in a movie.
Arguments
video::Video
: The video which defines the dimensions of the outputactions::Vector{Action}
: All actions that are performed
Keywords
framerate::Int
: The frame rate of the videopathname::String
: The path for the rendered gif or mp4 (i.eoutput.gif
oroutput.mp4
)tempdirectory::String
: The folder where each frame is stored Defaults to a temporary directory when not setliveview::Bool
: Causes a live image viewer to appear to assist with animation development
Example
function ground(args...)
background("white")
sethue("black")
end
function circ(p=O, color="black")
sethue(color)
circle(p, 25, :fill)
return Transformation(p, 0.0)
end
from = Point(-200, -200)
to = Point(-20, -130)
p1 = Point(0,-100)
p2 = Point(0,-50)
from_rot = 0.0
to_rot = 2π
demo = Video(500, 500)
javis(demo, [
Action(1:100, ground),
Action(1:100, :red_ball, (args...)->circ(p1, "red"), Rotation(from_rot, to_rot)),
Action(1:100, (args...)->circ(p2, "blue"), Rotation(to_rot, from_rot, :red_ball))
], tempdirectory="images", pathname="rotating.gif")
This structure makes it possible to refer to positions of previous actions i.e :red_ball is an id for the position or the red ball which can be used in the rotation of the next ball.
Javis.latex
— Methodlatex(text::LaTeXString, pos::Point, action::Symbol)
Add the latex string text
to the top left corner of the LaTeX path. Can be added to Luxor.jl
graphics via Video
.
NOTES:
This only works if
tex2svg
is installed. It can be installed using the following command (you may have to prefix this command withsudo
depending on your installation):npm install -g mathjax-node-cli
The
latex
method must be called from within anAction
.
Arguments
text::LaTeXString
: a LaTeX string to render.pos::Point
: position of the upper left corner of the latex text. Default:O
- can be written as
x, y
instead ofPoint(x, y)
- can be written as
action::Symbol
: graphics actions defined byLuxor.jl
. Default:stroke
.
Available actions:
:stroke
- Draws the latex string on the canvas. For more info checkLuxor.strokepath
:path
- Creates the path of the latex string but does not render it to the canvas.
Throws
IOError
: mathjax-node-cli is not installed
Example
using Javis
using LaTeXStrings
function ground(args...)
background("white")
sethue("black")
end
function draw_latex(video, action, frame)
fontsize(50)
x = 100
y = 120
latex(L"\sqrt{5}", x, y)
end
demo = Video(500, 500)
javis(demo, [BackgroundAction(1:2, ground), Action(draw_latex)],
pathname = "latex.gif")
Javis.morph
— Methodmorph(from_func::Function, to_func::Function; action=:stroke)
A closure for the _morph
function. This makes it easier to write the function inside an Action
.
Currently morphing is quite simple and only works for basic shapes. It especially does not work with functions which produce more than one polygon or which produce filled polygons. Blending between fills of polygons is definitely coming at a later stage.
Important: The functions itself should not draw the polygon i.e. use circle(Point(100,100), 50)
instead of circle(Point(100,100), 50, :stroke)
Arguments
from_func::Function
: The function that creates the path for the first polygon.to_func::Function
: Same asfrom_func
but it defines the "result" polygon, which will be displayed at the end of the Action
Keywords
action::Symbol
defines whether the object has a fill or just a stroke. Defaults to stroke.
Example
This creates a star that morphs into a circle and back.
using Javis
astar(args...) = star(O, 50)
acirc(args...) = circle(Point(100,100), 50)
video = Video(500, 500)
javis(video, [
Action(1:100, ground),
Action(1:50, morph(astar, acirc)),
Action(51:100, morph(acirc, astar))
], creategif=true, tempdirectory="images",
pathname="star2circle.gif", deletetemp=true)
Javis.pos
— Methodpos(x)
pos
is just a short-hand for get_position
Javis.projection
— Methodprojection(p::Point, l::Line)
Return the projection of a point to a line.
Javis.rev
— Methodrev(e::Easing)
Reverse an easing function such that easing_to_animation
maps it to [1.0, 0.0]
instead of [0.0, 1.0]
. An example can be seen in rotate
Javis.rotate_around
— Methodrotate_around(p::Point)
Rotate a function defined inside a SubAction
using an Animation defined with Animations.jl around the point p
.
An example can be seen in rotate
.
Arguments
p::Point
: the point to rotate around
Javis.scale
— Methodscale(scl_x, scl_y)
Same as scale
but the x scale and y scale can be changed independently.
Arguments:
scl_x
: scale in x directionscl_y
: scale in y direction
Javis.scale
— Methodscale(scl)
Set the scale and multiply it with the current multiplier which is i.e. set by appear
and disappear
.
Normal behavior without any animation is the same as Luxor.scale
.
Example
scale(0.5)
circle(O, 20, :fill) # the radius would be 10 because of the scaling
Arguments:
scl
: the new default scale
Javis.scale
— Methodscale()
Scale a function defined inside a SubAction
using an Animation defined with Animations.jl around the point p
.
An example can be seen in rotate
.
Javis.scaleto
— Methodscaleto(x, y)
Scale to a specific scaling instead of multiplying it with the current scale. For scaling on top of the current scale have a look at scale
.
Javis.setline
— Methodsetline(linewidth)
Set the line width and multiply it with the current multiplier which is i.e. set by appear
and disappear
.
Normal behavior without any animation is the same as Luxor.setline
.
Example
setline(10)
line(O, Point(10, 10))
Arguments:
linewidth
: the line width in pixel
Javis.setopacity
— Methodsetopacity(opacity)
Set the opacity and multiply it with the current multiplier which is i.e. set by appear
and disappear
.
Normal behavior without any animation is the same as Luxor.setopacity
.
Example
setopacity(0.5)
circle(O, 20, :fill)
Arguments:
opacity
: the opacity between 0.0 and 1.0
Javis.text
— Functiontext(str, pos = O; valign = :baseline, halign = :left, angle = 0.0)
Has bacially the same functionality as Luxor.text but overrides that method to allow to animate text with appear
.
Example
Action(
1:100,
(args...) -> text("Hello Stream!"; halign = :center);
subactions = [
SubAction(1:15, sineio(), appear(:draw_text)),
SubAction(76:100, sineio(), disappear(:draw_text)),
],
)
draws the text from left to right in the first 15 frames and in the last 15 frames it disappears.
Arguments
str::AbstractString
the string that should be shownpos::Point
defaults to the origin and can be written asx,y
as well asPoint(x,y)
.
Keywords
valign::Symbol
defaults to:baseline
and takes(:top, :middle, :bottom, :baseline)
halign::Symbol
defaults to:left
and takes(:left, :center, :centre, :right)
angle::Float64
defaults to0.0
and specifies the angle of the text
Javis.val
— Methodval(x)
val
is just a short-hand for get_value
Javis.zero_lines
— Methodzero_lines(video::Video, action::Action, frame::Int; direction::AbstractString = "TR", line_thickness = 10)
Draws zero lines on the given frame of a Video.
Arguments
direction::AbstractString
: Direction for how vertical and horizontal axes are drawn.
Default: "TR"
Available Orientations:
"TR"
- Vertical axis drawn towards the Top and horizontal axis drawn to the Right of the frame."TL"
- Vertical axis drawn towards the Top and horizontal axis drawn to the Left of the frame."BR"
- Vertical axis drawn towards the Bottom and horizontal axis drawn to the Right of the frame."BL"
- Vertical axis drawn towards the Bottom and horizontal axis drawn to the Left of the frame.line_thickness
: Defines the thickness of the zero lines. Default:10
Example
This example will produce an animation with the vertical axis being drawn towards the top and the horizontal axis being drawn towards the left. One will need to define their own path for tempdirectory
and pathname
.
...
Action(1:100, :line, zero_lines(direction = "TL", line_thickness = 10)),
...
Luxor.rotate
— Methodrotate()
Rotate a function defined inside a SubAction
using an Animation defined with Animations.jl.
If you're used to working with Animations.jl this should feel quite natural. Instead of defining each movement in its own subaction it's possible to define it in one by using an Animation.
Example
using Javis, Animations
video = Video(500, 500)
translate_anim = Animation(
[0, 1], # must go from 0 to 1
[O, Point(150, 0)],
[sineio()],
)
translate_back_anim = Animation(
[0, 1], # must go from 0 to 1
[O, Point(-150, 0)],
[sineio()],
)
rotate_anim = Animation(
[0, 1], # must go from 0 to 1
[0, 2π],
[linear()],
)
javis(
video,
[
BackgroundAction(1:150, ground),
Action(
(args...) -> circle(O, 25, :fill);
subactions = [
SubAction(1:10, sineio(), scale()),
SubAction(11:50, translate_anim, translate()),
SubAction(51:100, rotate_anim, rotate_around(Point(-150, 0))),
SubAction(101:140, translate_back_anim, translate()),
SubAction(141:150, rev(sineio()), scale())
],
),
],
pathname = "animation.gif",
)
which uses the SubAction
syntax five times with both easing functions directly and animation objects. The rev(sineio())
creates an Animation
which goes from 1.0
to 0.0
.
Luxor.sethue
— Methodsethue()
Set the color of a function defined inside a SubAction
using an Animation defined with Animations.jl.
Example
A possible animation would look like this:
color_anim = Animation(
[0, 0.5, 1], # must go from 0 to 1
[
Lab(colorant"red"),
Lab(colorant"cyan"),
Lab(colorant"black"),
],
[sineio(), sineio()],
)
An example on how to integrate this into a SubAction can be seen in rotate
. Where this would be a valid SubAction: SubAction(1:150, color_anim, sethue())
.
Luxor.translate
— Methodtranslate()
Translate a function defined inside a SubAction
using an Animation defined with Animations.jl.
If you're used to working with Animations.jl this should feel quite natural. Instead of defining each movement in its own subaction it's possible to define it in one by using an Animation.
Example
using Javis, Animations
function ground(args...)
background("black")
sethue("white")
end
video = Video(500, 500)
circle_anim = Animation(
[0.0, 0.3, 0.6, 1.0], # must go from 0 to 1
# the circle will move from the origin to `Point(150, 0)` then `Point(150, 150)`
# and back to the origin `O`.
[O, Point(150, 0), Point(150, 150), O],
[sineio(), polyin(5), expin(8)],
)
javis(
video, [
BackgroundAction(1:150, ground),
Action((args...)->circle(O, 25, :fill); subactions=[
SubAction(1:150, circle_anim, translate())
])
], pathname="moving_a_circle.gif"
)
This notation uses the Animations.jl library very explicitly. It's also possible to do the same with:
javis(
video,
[
BackgroundAction(1:150, ground),
Action((args...)->circle(O, 25, :fill); subactions = [
SubAction(1:50, sineio(), Translation(150, 0)),
SubAction(51:100, polyin(2), Translation(0, 150)),
SubAction(101:150, expin(8), Translation(-150, -150))
])
],
pathname = "moving_a_circle_javis.gif",
)
which uses the SubAction
syntax three times and only uses easing functions instead of specifying the Animation
directly.
Here circle_anim
defines the movement of the circle. The most important part is that the time in animations has to be from 0.0
to 1.0
.
Private functions
Javis.CURRENT_ACTION
— ConstantCURRENT_ACTION
holds the current action in an array to be declared as a constant The current action can be accessed using CURRENT_ACTION[1]
Javis.CURRENT_VIDEO
— ConstantCURRENT_VIDEO
holds the current video in an array to be declared as a constant The current video can be accessed using CURRENT_VIDEO[1]
Javis.ActionSetting
— TypeActionSetting
The current settings of an Action
which are saved in action.current_setting
.
Fields
line_width::Float64
: the current line widthmul_line_width::Float64
: the current multiplier for line width. The actual line width is then:mul_line_width * line_width
opacity::Float64
: the current opacitymul_opacity::Float64
: the current multiplier for opacity. The actual opacity is then:mul_opacity * opacity
fontsize::Float64
the current font sizeshow_action::Bool
is set to false if scale would be 0.0 which is forbidden by Cairocurrent_scale::Tuple{Float64, Float64}
: the current scaledesired_scale::Tuple{Float64, Float64}
: the new desired scalemul_scale::Float64
: the multiplier for the new desired scale. The actual new scale is then:mul_scale * desired_scale
Javis.Frames
— TypeFrames
Stores the actual computed frames and the user input which can be :same
or Rel(10)
. The frames
are computed in javis
.
Javis.InternalRotation
— TypeInternalRotation <: InternalTransition
Saves a rotation as described by Rotation
for the current frame. Is part of the Action
struct.
Javis.InternalScaling
— TypeInternalScaling <: InternalTransition
Saves a scaling as described by Scaling
for the current frame. Is part of the Action
struct.
Javis.InternalTranslation
— TypeInternalTranslation <: InternalTransition
Saves a translation as described by Translation
for the current frame. Is part of the Action
struct.
Javis.ReversedEasing
— TypeReversedEasing
Will be used to reverse an easing inside easing_to_animation
. Can be constructed from an easing function using rev
.
Javis._decrement
— Method_decrement(video::Video, widgets::Vector, actions::Vector, dims::Vector,
canvas::Gtk.Canvas, frames::Int)
Decrements a given value and returns the associated frame.
Javis._draw_image
— Method_draw_image(video::Video, actions::Vector, frame::Int, canvas::Gtk.Canvas,
img_dims::Vector)
Internal function to create an image that is drawn on a Gtk Canvas.
Javis._increment
— Method_increment(video::Video, widgets::Vector, actions::Vector, dims::Vector,
canvas::Gtk.Canvas, frames::Int)
Increments a given value and returns the associated frame.
Javis._javis_viewer
— Function _javis_viewer(video::Video, frames::Int, action_list::Vector, show::Bool)
Internal Javis Viewer built on Gtk that is called for live previewing.
Javis._morph
— Method_morph(video::Video, action::Action, frame, from_func::Function, to_func::Function; draw_action=:stroke)
Internal version of morph
but described there.
Javis.animate_text
— Methodanimate_text(
str,
pos::Point,
valign::Symbol,
halign::Symbol,
angle::Float64,
t::Float64,
)
This function is used as a subfunction of text
and animates the str
by clipping the textoutlines and creating a growing circle in the lower left corner to display the text from left to right in an animated fashion.
Javis.compute_frames!
— Methodcompute_frames!(actions::Vector{AA}; last_frames=nothing) where AA <: AbstractAction
Set action.frames.frames to the computed frames for each action in actions.
Javis.compute_transition!
— Methodcompute_transition!(action::AbstractAction, video::Video, frame::Int)
Update action.internal_transitions for the current frame number
Javis.compute_transition!
— Methodcompute_transition!(internal_rotation::InternalRotation, rotation::Rotation, video,
action::AbstractAction, frame)
Computes the rotation transformation for the action
. If the Rotation
is given directly it uses the frame number for interpolation. If rotation
includes symbols the current definition of that look up is used for computation.
Javis.compute_transition!
— Methodcompute_transition!(internal_translation::InternalScaling, translation::Scaling,
video, action::AbstractAction, frame)
Computes the scaling transformation for the action
. If the scaling
is given directly it uses the frame number for interpolation. If scaling
includes symbols, the current definition of that symbol is looked up and used for computation.
Javis.compute_transition!
— Methodcompute_transition!(internal_translation::InternalTranslation, translation::Translation,
video, action::AbstractAction, frame)
Computes the translation transformation for the action
. If the translation
is given directly it uses the frame number for interpolation. If translation
includes symbols the current definition of that symbol is looked up and used for computation.
Javis.create_internal_transitions!
— Methodcreate_internal_transitions!(action::AbstractAction)
For every translation an internal translation is added to action.internal_transitions
. Same is true for all other transitions.
Javis.draw_obj
— Methoddraw_obj(::Val{:g}, o, defs)
Draws a group by setting the attributes (like transformations) and then calls draw_obj
for all child elements.
Javis.draw_obj
— Methoddraw_obj(::Val{:path}, o, defs)
Calls the commands specified in the path data. Currently supports only a subset of possible SVG commands.
Javis.draw_obj
— Methoddraw_obj(::Val{:rect}, o, defs)
Draw the rectangle defined by the object o
.
Javis.draw_obj
— Methoddraw_obj(::Val{:use}, o, defs)
Calls the command specified in defs
.
Javis.easing_to_animation
— Methodeasing_to_animation(easing)
Converts an easing to an Animation with time goes from 0.0
to 1.0
and value from 0
to 1
.
Javis.easing_to_animation
— Methodeasing_to_animation(rev_easing::ReversedEasing)
Converts an easing to an Animation with time goes from 0.0
to 1.0
and value from 1
to 0
.
Javis.float_attribute
— Methodfloat_attribute(o, name)
Get the attribute name
of the XMLElement and parse it as a Float64
Javis.get_current_setting
— Methodget_current_setting()
Return the current setting of the current action
Javis.get_frames
— Methodget_frames(a::AbstractAction)
Return a.frames.frames
which holds the computed frames for the AbstractAction a
.
Javis.get_frames
— Methodget_frames(frames::Rel, last_frames::UnitRange)
Return the frames based on a relative frames Rel
object and the last_frames
.
Javis.get_frames
— Methodget_frames(frames::Symbol, last_frames::UnitRange)
Get the frames based on a symbol (currently only same
) and the last_frames
. Throw ArgumentError
if symbol is unknown
Javis.get_interpolation
— Methodget_interpolation(action::AbstractAction, frame)
Return the value of the action.anim
Animation based on the relative frame given by get_interpolation(get_frames(action), frame)
Javis.get_interpolation
— Methodget_interpolation(frames::UnitRange, frame)
Return a value between 0 and 1 which represents the relative frame
inside frames
.
Javis.get_javis_frame
— Methodget_javis_frame(video, actions, frame)
Get a frame from an animation given a video object, its actions, and frame.
Arguments
video::Video
: The video which defines the dimensions of the outputactions::Vector{Action}
: All actions that are performedframe::Int
: Specific frame to be returned
Returns
Array{ARGB32, 2}
- request frame as a matrix
Javis.get_scale
— Methodget_scale(s::Symbol)
Get access to the scaling that got saved in s
by a previous action.
Returns
Scaling
: the scale stored by a previous action.
Javis.match_num_point!
— Methodmatch_num_point!(poly_1::Vector{Point}, poly_2::Vector{Point})
This is a helper function for morph
. Given two polygons poly_1
and poly_2
points are added to the polygon with less points until both polygons have the same number of points. The polygon with less points gets mutated during this process.
Arguments
poly_1::Vector{Point}
: The points which define the first polygonpoly_2::Vector{Point}
: The points which define the second polygon
Javis.path_move
— Methodpath_move(x,y)
Moving to the specified point
Javis.path_quadratic
— Methodpath_quadratic(c_pt::Point, x,y, xe, ye)
Drawing a quadratic bezier curve by computing a cubic one as that is supported by Luxor
Javis.pathsvg
— Methodpathsvg(svg)
Convert an svg to a path using Luxor. Normally called via the latex
command. It handles only a subset of the full power of svg.
Javis.perform_action
— Methodperform_action(action, video, frame, origin_matrix)
Is called inside the javis
and does everything handled for an AbstractAction
. It is a 4-step process:
- compute the transformation for this action (translation, rotation, scale)
- do the transformation
- call the action function
- save the result of the action if wanted inside
video.defs
Javis.perform_transformation
— Methodperform_transformation(action::AbstractAction)
Perform the transformations as described in action.internal_transitions
Javis.perform_transformation
— Methodperform_transformation(trans::InternalRotation)
Translate and rotate as described in trans
.
Javis.perform_transformation
— Methodperform_transformation(trans::InternalScaling)
Scale as described in trans
.
Javis.perform_transformation
— Methodperform_transformation(trans::InternalTranslation)
Translate as described in trans
.
Javis.save_morph_polygons!
— Methodsave_morph_polygons!(action::Action, from_func::Function, to_func::Function)
Converts the paths created by the functions to polygons and calls match_num_point!
such that both polygons have the same number of points. This is done once inside _morph
. Saves the two polygons inside action.opts[:from_poly]
and action.opts[:to_poly]
.
Assumption: Both functions create only a single polygon each.
Javis.scl
— Methodscl(x)
scl
is just a short-hand for get_scale
Javis.set_action_defaults!
— Methodset_action_defaults!(action)
Set the default action values
- line_width and calls
Luxor.setline
. - opacity and calls
Luxor.opacity
. - scale and calls
Luxor.scale
.
Javis.set_attr
— Methodset_attr(::Val{:transform}, transform_str)
Call the corresponding set_transform
method i.e matrix
, scale
and translate
Javis.set_attrs
— Methodset_attrs(o)
Setting the attributes of the object o
by calling set_attr
methods.
Javis.set_frames!
— Methodset_frames!(a::AbstractAction, last_frames::UnitRange)
Compute the frames based on a.frames and last_frames
. Save the result in a.frames.frames
which can be accessed via get_frames
.
Javis.set_transform
— Methodset_transform(::Val{:matrix}, args...)
Multiply the new matrix with the current matrix and set it.
Javis.update_ActionSetting!
— Methodupdate_ActionSetting!(as::ActionSetting, by::ActionSetting)
Set the fields of as
to the same as by
. Basically copying them over.