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

How To: draw_text, follow_path and liveview #184

Merged
merged 5 commits into from
Sep 22, 2020
Merged
Changes from all 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
92 changes: 92 additions & 0 deletions docs/src/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,95 @@ Action(1:100, (args...)->rect(pos(:my_circle)+Point(-10, -100), 20, 20, :fill))

In this animation the position of the circle is saved inside `:my_circle` and can be used with `pos(:my_circle)` inside the `rect` function.

## How can I show a text being drawn?

A `text` can appear as *any* other object with `appear(:fade)` and `appear(:scale)`, However, it also has a special [`appear`](@ref) functionality called
`:draw_text`.

You can use
```julia
Action(
1:100,
(args...) -> text("Hello World!"; halign = :center);
subactions = [
SubAction(1:15, sineio(), appear(:draw_text)),
SubAction(76:100, sineio(), disappear(:draw_text)),
]
)
```

to let the text `"Hello World!"` appear from left to right in an animated way.

## How can I have an object follow a path?

We need to create a path by providing a list of points that the object can follow.
All objects that return a list of points can be used directly like `star` and `poly` for others a list of points must be provided as the input.

An action can look like this:

```julia
Action(
1:150
(args...) -> star(O, 20, 5, 0.5, 0, :fill);
subactions = [
SubAction(1:150, follow_path(star(O, 300))),
],
)
```

in this case a star is following the path of a bigger star.
> **NOTE:** the star inside [`follow_path`](@ref) should have the `action=:none` which is the default for most Luxor functions.

> **NOTE:** Unfortunately the above currently only works for some Luxor functions like `ngon` and `star` but not for `circle` and `rect` as they return `true` instead of the points.

In that case you need to define a function like:
```julia
function ground(args...)
background("white")
sethue("black")
end

function luxor2poly(func::Function)
newpath()
func()
closepath()
return pathtopoly()[1]
end

video = Video(600, 400)
javis(video, [
BackgroundAction(1:150, ground),
Action(
1:150,
(args...) -> star(O, 20, 5, 0.5, 0, :fill);
subactions = [
SubAction(1:150, follow_path(luxor2poly(()->rect(O, 100, 100, :path))))
]
)
]; pathname="follow_path.gif")
```


Another possibility is to specify a vector of points like this:

```julia
Action(
1:150
(args...) -> star(O, 20, 5, 0.5, 0, :fill);
subactions = [
SubAction(1:150, sineio(), follow_path([Point(100, 200), Point(-20, -250), Point(-80, -10)]; closed=false)),
],
)
```

In this case I want the star to follow a path consisting of two edges and I use `; closed=false` to specify that it's just two edges and not a closed triangle.

An interesting possibility is to define paths using Bézier curves which can be defined with Luxor see: [Polygons to Bézier paths and back again](https://juliagraphics.github.io/Luxor.jl/stable/polygons/#Polygons-to-B%C3%A9zier-paths-and-back-again)
TheCedarPrince marked this conversation as resolved.
Show resolved Hide resolved

## How can I see a live view of the animation?

A live view of the animation can be useful for creating an animation where one doesn't need the overhead of building a gif or mp4 all the time. It also has the advantage that it's very easy to jump to a specific frame.

The live viewer can be called with adding `; liveview=true` to the [`javis`](@ref) call.

> **NOTE:** If `liveview=true` the `tempdirectory` and `pathname` arguments are ignored.
TheCedarPrince marked this conversation as resolved.
Show resolved Hide resolved