Public functions
Javis.Action — TypeActionDefines what is drawn in a defined frame range.
Fields
frames::Frames: A range of frames for which theActionis calledid::Union{Nothing, Symbol}: An id which can be used to save the result offuncfunc::Function: The drawing function which draws something on the canvas. It gets called with the argumentsvideo, action, frametransitions::Vector{Transition}a list of transitions which can be performed before the function gets called.internal_transitions::Vector{InternalTransition}: Similar totransitionsbut holds the concrete information whereasTransitioncan hold links to other actions which need to be computed first. Seecompute_transformation!opts::Anycan hold any options defined by the user
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 thefuncreturns something which shall be accessible by other actions laterfunc::Functionthe function that is called after thetransitionsare performedtransitions::Transition...a list of transitions that are performed before the functionfuncitself is called
The keywords arguments will be saved inside .opts as a Dict{Symbol, Any}
Javis.Action — MethodAction(func::Function, args...)Similar to the above but uses the same as 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 — TypeLineA 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 — TypeRelAbility 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 <: TransitionStores 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 <: TransitionStores 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 <: AbstractActionA 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 parentActionfunc::Function: the function that gets called in each of those frames. Takes the following arguments:video, action, subaction, rel_frametransitions::Vector{Transition}: A list of transitions likeTranslationinternal_transitions::Vector{InternalTransition}: A list of internal transitions which store the current transition for a specific frame.
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, 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 — TypeTransformationDefines 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 <: TransitionStores 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 — TypeVideoDefines the video canvas for an animation.
Fields
width::Intthe width in pixelheight::Intthe 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_widthwhich increases the line width up to the default value or the value specified bysetline:fadewhich increases the opcacity up to the default value or the value specified bysetopacity
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_widthwhich descreases the line width up to the default value or the value specified bysetline:fadewhich decreases the opcacity up to the default value or the value specified bysetopacity
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.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=""
)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.giforoutput.mp4)tempdirectory::String: The folder where each frame is stored Defaults to a temporary directory when not set
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
tex2svgis installed. It can be installed using the following command (you may have to prefix this command withsudodepending on your installation):npm install -g mathjax-node-cliThe
latexmethod 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, yinstead 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)
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)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_funcbut it defines the "result" polygon, which will be displayed at the end of the Action
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.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 scalingArguments:
scl: the new default 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.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)),
...Private functions
Javis.CURRENT_ACTION — ConstantCURRENT_ACTIONholds 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_VIDEOholds the current video in an array to be declared as a constant The current video can be accessed using CURRENT_VIDEO[1]
Javis.ActionSetting — TypeActionSettingThe 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_widthopacity::Float64: the current opacitymul_opacity::Float64: the current multiplier for opacity. The actual opacity is then:mul_opacity * opacityfontsize::Float64the current font sizecurrent_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 — TypeFramesStores the actual computed frames and the user input which can be i.e. :same or Rel(10). The frames are computed in javis.
Javis._morph — Method_morph(video::Video, action::Action, frame, from_func::Function, to_func::Function)Internal version of morph but described there.
Javis.compute_frames! — Methodcompute_frames!(actions::Vector{AA}; last_frames=nothing) where AA <: AbstractActionSet action.frames.frames to the computed frames for each action in actions.
Javis.compute_transformation! — Methodcompute_transformation!(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.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_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.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.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.