Skip to content

Commit

Permalink
merge master in v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikunia committed Sep 10, 2020
1 parent b0e3e6b commit a853a0f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Use [VideoIO](https://github.com/JuliaIO/VideoIO.jl) for faster rendering without temporary images

## Unreleased
- Ability to not define frames for the first `SubAction` -> all frames of the `Action` will be used
- Ability to scale an object with `Scaling`. Works similar to `Translation` and `Rotation`
- Added JuliaFormatter GitHub Action

Expand Down
8 changes: 4 additions & 4 deletions docs/src/tutorials/tutorial_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ By the end of this tutorial, you will have made the following animation:

![](assets/dancing_circles.gif)

With all that said, let's dive in to this tutorial! ✨
With all that said, let's dive into this tutorial! ✨

## So... What Is `Javis.jl`?

Expand All @@ -41,7 +41,7 @@ In order to use `Javis`, we will start with the following import:
using Javis
```

Then, we will introduce our first and most import function from `Javis` - the `javis` function:
Then, we will introduce our first and most important function from `Javis` - the `javis` function:

```
javis(
Expand All @@ -51,7 +51,7 @@ javis(
)
```

The `javis` function has three key word parameters that the user must define in order to create an animation:
The `javis` function has three keyword arguments (kwargs) that the user must define in order to create an animation:

- `video` - a `Video` struct
- `actions` - a vector of `Action` objects
Expand Down Expand Up @@ -346,7 +346,7 @@ To recap, by working through this animation you should now:
3. Be able to connect actions together using variable syntax

If you want to know more and experiment with `Javis`, go onto the following tutorials!
We wish you best on your `Javis` journey!
We wish you the best on your `Javis` journey!

> **Author(s):** @sudomaze, Ole Kröger, Jacob Zelko \
> **Date:** August 14th, 2020 \
Expand Down
11 changes: 10 additions & 1 deletion src/Javis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ mutable struct SubAction <: AbstractAction
internal_transitions::Vector{InternalTransition}
end

SubAction(transitions::Transition...) = SubAction(:same, transitions...)
SubAction(func::Function) = SubAction(:same, func)
SubAction(
easing_or_animation::Union{ReversedEasing,Easing,Animation},
transitions::Transition...,
) = SubAction(:same, easing_or_animation, transitions...)
SubAction(easing_or_animation::Union{ReversedEasing,Easing,Animation}, func::Function) =
SubAction(:same, easing_or_animation, func)

"""
SubAction(frames, easing::Union{ReversedEasing, Easing}, args...)
Expand Down Expand Up @@ -1157,7 +1166,7 @@ function javis(
compute_frames!(actions)

for action in actions
compute_frames!(action.subactions)
compute_frames!(action.subactions; last_frames = get_frames(action))
end

# get all frames
Expand Down
10 changes: 6 additions & 4 deletions src/util.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
compute_frames!(actions::Vector{AA}) where AA <: AbstractAction
compute_frames!(actions::Vector{AA}; last_frames=nothing) where AA <: AbstractAction
Set action.frames.frames to the computed frames for each action in actions.
"""
function compute_frames!(actions::Vector{AA}) where {AA<:AbstractAction}
last_frames = nothing
function compute_frames!(
actions::Vector{AA};
last_frames = nothing,
) where {AA<:AbstractAction}
for action in actions
if last_frames === nothing && get_frames(action) === nothing
throw(ArgumentError("Frames need to be defined explicitly in the inital
throw(ArgumentError("Frames need to be defined explicitly in the initial
AbstractAction like Action/BackgroundAction or SubAction."))
end
if get_frames(action) === nothing
Expand Down
42 changes: 42 additions & 0 deletions test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,46 @@
],
)
end

@testset "Frame computation" begin

actions = [
BackgroundAction(1:50, (args...) -> 1),
Action(:atom, (args...) -> 1, subactions = [SubAction(Scaling(1, 2))]),
]
demo = Video(500, 500)
javis(demo, actions; pathname = "")
@test Javis.get_frames(actions[1]) == 1:50
@test Javis.get_frames(actions[2]) == 1:50
@test Javis.get_frames(actions[2].subactions[1]) == 1:50

actions = [
BackgroundAction(1:50, (args...) -> 1),
Action(:atom, (args...) -> 1, subactions = [SubAction((args...) -> 1)]),
]
demo = Video(500, 500)
javis(demo, actions; pathname = "")
@test Javis.get_frames(actions[1]) == 1:50
@test Javis.get_frames(actions[2]) == 1:50
@test Javis.get_frames(actions[2].subactions[1]) == 1:50

actions = [
BackgroundAction(1:50, (args...) -> 1),
Action(
Rel(-19:0),
:atom,
(args...) -> 1,
subactions = [
SubAction(1:10, Scaling(1, 2)),
SubAction(Rel(10), Scaling(1, 2)),
],
),
]
demo = Video(500, 500)
javis(demo, actions; pathname = "")
@test Javis.get_frames(actions[1]) == 1:50
@test Javis.get_frames(actions[2]) == 31:50
@test Javis.get_frames(actions[2].subactions[1]) == 1:10
@test Javis.get_frames(actions[2].subactions[2]) == 11:20
end
end

0 comments on commit a853a0f

Please sign in to comment.