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

Animate change of color #363

Closed
Sov-trotter opened this issue Jul 17, 2021 · 8 comments · Fixed by #390
Closed

Animate change of color #363

Sov-trotter opened this issue Jul 17, 2021 · 8 comments · Fixed by #390
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Sov-trotter
Copy link
Member

I couldn't really figure out a way to fill color in a shape gradually(not instantly).
eg: Something like

act!(star_obj, Action(41:50, change(:do_action, :fill)))
act!(star_obj, Action(41:50, change(:color, "red")))

Fills color in the 41st frame rather than animating the filing.

@Sov-trotter Sov-trotter added the enhancement New feature or request label Jul 17, 2021
@Wikunia
Copy link
Member

Wikunia commented Jul 17, 2021

change takes either something of the form a => b or a value. When given a value like here it just sets the value without animation.

@Sov-trotter
Copy link
Member Author

OH!
Something like change(:color, "white"=>"red") throws an error.

ERROR: LoadError: MethodError: no method matching -(::String, ::String)
Closest candidates are:
  -(::ChainRulesCore.NotImplemented, ::Any) at /home/ezio/.julia/packages/ChainRulesCore/4bCB1/src/differential_arithmetic.jl:62
  -(::ChainRulesCore.NoTangent, ::Any) at /home/ezio/.julia/packages/ChainRulesCore/4bCB1/src/differential_arithmetic.jl:77
  -(::ChainRulesCore.ZeroTangent, ::Any) at /home/ezio/.julia/packages/ChainRulesCore/4bCB1/src/differential_arithmetic.jl:117
  ...
Stacktrace:
  [1] _change(video::Video, object::Object, action::Action, rel_frame::Int64, s::Symbol, vals::Pair{String, String})
    @ Javis ~/.julia/dev/Javis/src/action_animations.jl:419

@Wikunia
Copy link
Member

Wikunia commented Jul 17, 2021

Yeah because it can't interpolate. I think you can use RGB from the colors package though

@Sov-trotter
Copy link
Member Author

Oh yeah. Better to tag it as a goodfirstissue or we might take a look at it later.

@Sov-trotter Sov-trotter changed the title Animate filling of color Animate change of color Jul 17, 2021
@Wikunia
Copy link
Member

Wikunia commented Jul 17, 2021

Just for clarification: you meant interpolation of the fill color and not filling a circle from top to bottom for example, right? That might be interesting as well though.
Regarding the change function a bit more: the problem we faced is that we don't know the initial color and therefore need this pair for interpolation. With #313 there might be a way to fix this as well, right?

@Wikunia Wikunia added the good first issue Good for newcomers label Jul 17, 2021
@Sov-trotter
Copy link
Member Author

Sov-trotter commented Jul 17, 2021

Yeah. Filling from top to bottom can go in the draw action.
I think the user has to provide the previous color then. Just like we do it for radius and other properties.

Yeah #313 includes all the relevant arguments/Metadata that change can operate on.

@TheCedarPrince
Copy link
Member

TheCedarPrince commented Jul 18, 2021

We could chat more @Sov-trotter , but here is how I would do it right now without convenience functionalities:

using Javis, Animations, Colors

function ground(args...)
    background("black")
    sethue("white")
end

color_anim = Animation(
    [0, 0.25, 0.5, 0.75, 1], # must go from 0 to 1
    [Lab(colorant"black"), Lab(colorant"red"), Lab(colorant"cyan"), Lab(colorant"red"), Lab(colorant"black")],
    [sineio(), sineio(), sineio(), sineio()],
)

video = Video(600, 400)
Background(1:200, ground)

blob = Object(1:150, (args...) -> circle(O, 60, :fill))
act!(blob, Action(1:150, color_anim, sethue()))

render(
    video;
    pathname = "loading.gif",
)

Which gives:

loading

Obviously a bit verbose. Would be nice to make some reasonable default animation syntax for change where we could have something like:

act!(star_obj, Action(41:50, change(:do_action, :fill)))
act!(star_obj, Action(41:50, change(:color, colorant"red" => colorant"blue", sineio())))

@Wikunia
Copy link
Member

Wikunia commented Aug 11, 2021

We probably want to have
https://github.com/jkrumbiegel/Animations.jl/blob/master/src/interpolation.jl#L95-L97
to make this work. The sineio() should still be directly after defining the frames though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants