Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow color interpolation in change #390

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased
- added `@Frames` macro for full power mode of defining frames
- bugfix in `@JLayer` when dimensions are not defined explicitly
- allow color interpolation in `change`
- bugfix `color` can be a non string value in `JBox`

## v0.6.1 (7th of August 2021)
- Add shorthands for basic shapes
Expand Down
6 changes: 3 additions & 3 deletions src/action_animations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ end

function _change(video, object, action, rel_frame, s, vals::Pair)
t = get_interpolation(action, rel_frame)
val = vals[1] + t * (vals[2] - vals[1])
object.change_keywords[s] = val
# use the linear animation power by the Animation package to interpolate colors as well
lin_anim = Animation([0.0, 1.0], interpolateable([vals...]))
object.change_keywords[s] = at(lin_anim, t)
end


function _change(video, object, action, rel_frame, s, val)
object.change_keywords[s] = val
end
Expand Down
15 changes: 4 additions & 11 deletions src/shorthands/JBox.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
function _JBox(
cornerpoint1::Point,
cornerpoint2::Point,
color::String,
color,
action::Symbol,
vertices::Bool,
)
sethue(color)
verts = box(cornerpoint1, cornerpoint2, action, vertices = vertices)
return verts[2]
end
function _JBox(points::Array, color::String, action::Symbol, vertices::Bool)
function _JBox(points::Array, color, action::Symbol, vertices::Bool)
sethue(color)
verts = box(points, action, vertices = vertices)
return verts[2]
end
function _JBox(
pt::Point,
width::Real,
height::Real,
color::String,
action::Symbol,
vertices::Bool,
)
function _JBox(pt::Point, width::Real, height::Real, color, action::Symbol, vertices::Bool)
sethue(color)
box(pt, width, height, action, vertices = vertices)
return Point(pt.x - width / 2, pt.y + height / 2)
Expand All @@ -31,7 +24,7 @@ function _JBox(
width::Real,
height::Real,
cornerradius::Float64,
color::String,
color,
action::Symbol,
)
sethue(color)
Expand Down
9 changes: 9 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,12 @@ function empty_CURRENT_constants()
empty!(PREVIOUS_ACTION)
empty!(CURRENT_OBJECT_ACTION_TYPE)
end

"""
interpolateable(x::AbstractVector)

Return the vector in a datatype that is interpolateable.
Currently only implemented is to change from `<:Integer` to `float`
"""
interpolateable(x::AbstractVector) = x
interpolateable(x::AbstractVector{<:Integer}) = float.(x)
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
GtkReactive = "27996c0f-39cd-5cc1-a27a-05f136f946b6"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
Expand Down
Binary file modified test/refs/shorthands40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/refs/shorthands59.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion test/shorthands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ video = Video(800, 800)
poly0,
poly1,
],
Action(40:51, change(:color, "blue")),
[
Action(40:51, change(:color, "red")),
Action(52:61, change(:color, colorant"red" => colorant"blue")),
],
)
act!(
[
Expand Down