02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Exploring Bezier Curves: Bezier Thru

By the end of this lecture will feel like you crossed deep into the dark world of animation. So far, all of our animations have been relatively flat, linear and any other negative term you want to call them. But from here on, our animations will be wicked deep and curvy. In this lesson, and for the first time, we will incorporate bezier thru animations with the BezierPlugin.

Video Transcript

00:00Let's start with the easiest Bezier curve, or more like Bezier-ish.
00:03The idea behind it is, instead of us drawing an animation from point one to point B,
00:08well, from point one to point two to point three, and having like this odd trajectory where our
00:14animation kind of like, oooh, stucks and moves back up, instead of that we want to use a little
00:19bit of smoothness so our animation will basically kind of travel through without it feeling
00:24handmade that the turn was arbitrary or mechanical, which that's what would happen
00:29if we animate something from point A to point B to point C. So for that, we're going to use
00:33the Bezier plugin. Let's see it in action. It's not that hard this first part, but as promised,
00:39it's going to get more complicated, but if you're learning with me, it won't be too complicated.
00:45I'm not going to do too many introductions to Bezier curves. Now I want to start off with
00:50the default animation that is done in Tween Light and Tween Max. All you really have to do is just
00:56import the where are you Bezier, and if we find the Bezier, I'm just going to go ahead and
01:03incorporate that into our script. And I'm not going to give any interest right now because we're
01:08going to look into this Bezier curve animation thingy going on in the next few lessons,
01:14not only this one. Now by default, there's kind of like the easy way and the simplified logic
01:22to draw in a Bezier curve, and we're going to see what a Bezier curve is immediately. But before
01:27that, I just want to show you in action, when do we want to use it? So I'm going to go ahead and
01:33if I go into my illustration here, what would happen if I wanted to create basically that my
01:39item is going from one spot to another spot beyond one line. So I'm going to go ahead here
01:43just for the sake of this animation idea. I'm going to go ahead and draw a little bit more,
01:48and I'm going to change the position where it's going to. I'm going to have it animate
01:52all the way down and then go up in a straight line. So if you look at this here for a second
01:57here right now, we look at this right now. First of all, we'll see that our item is obviously not
02:01going in the path that we want it to go. But beyond that, really, what we wanted to do is
02:05to go down and then go up. Now traditionally, what you could do and you probably already know
02:09is I'm going to just, you know, get rid of the tweens that we're doing to canvas. Let me just
02:14comment it out. And I'm going to go ahead and literally all I have to do is create another
02:20two. And if that was six seconds, let me just drop it down. So it'll be a bit faster. That
02:25would be three seconds. This would be three seconds. I would just make sure that I'm also
02:29adding a delay of three seconds so we could wait for the first animation to complete.
02:36And then I would have the first animation go to that seven hundred three hundred.
02:40And I would have the second animation go to seven hundred ten. So that would definitely
02:44solve my problem. And if I run this, run my application, we'll have our animation going
02:49on. But the problem with this animation that it's not incredibly natural and the ease is
02:54not natural as well because of that. Ideally, we would want it to just feel more organic
03:00and have an animation flow that doesn't kind of like go to a spot freeze almost and move
03:05on to the next spot. Even if we had different eases, wouldn't it be wonderful if we could
03:10do this motion in one animation? And the answer is we could. And we could very easily. Now,
03:16I'm not going to show you every single scenario. You could add here a lot of pivot points. You
03:19could have a hundred different points that it goes through. We're just going to show
03:22you two points of this Bezier plugin. Now, the way that it works is incredibly simple.
03:27I'm just going to go ahead here and just comment this out here for a second.
03:31Okay. And I'm going to go ahead and I'm just going to create a new tween light too.
03:36And let me just grab this, you know, we're going to have it for one second here.
03:40And I'm going to go ahead here. And what I want to do is I want to basically approach and say,
03:46I want to do a Bezier animation. So what I have to do is I have to wrap this CSS element
03:53in a Bezier as well. So let me start over from scratch and delete that whole area.
03:57I'm going to write the object Bezier so it knows that it needs to approach that
04:02plugin. And for the Bezier, I need to send in a contrary to a lot of other objects I send in
04:08an array. And that array will basically list out all the points that this animation is going to go
04:13through or animate through. And that's basically the default. The default is called animate through,
04:18which basically will go through those specific points. So I'm going to add here an object.
04:23And in the object, I'm basically going to set the properties in our case, it was that left and top,
04:28so I could grab that left and top and just position it right in there. And for our second
04:32property, I'm going to go ahead and just copy the same exact construct only this time around,
04:38we want to send the new point that we want to go to. Now just by doing this, and just by
04:43setting these two points and making my animation tween to using a Bezier instead of just using
04:49a CSS attribute, but instead of that, we're working with the Bezier and adding the points
04:53that we want our animation to go through. Right now I set it to three seconds. If I go ahead
04:58to that animation and click on refresh, we're going to see that this time around, it's going
05:01to animate through. And now the logic itself is out of our control how and in what velocity it
05:07goes. But that velocity really is determined based on the, I would say the inner algorithm
05:14of tween light. So in our case, our animation is finding the most smooth position it can go
05:20from point one to point B. And we can literally, if we wanted to add as many points as we want
05:26and create whatever flow we want, basically positioning it one line at a time and letting
05:32green sock the library itself figure out how is it going to get it from this point to this point,
05:37and it's using this anchor point, this flow to create a more wiggly animation process as it's
05:44going through to try to figure out the point. And you can see how it's going through the point.
05:48So it's touching that dot and going through and looping in and finding that position to go.
05:52So as you add more dots, it's got to make sure that it goes through that dot, but it's
05:57going to animate through in a kind of like a, not in a linear way, but in a much more smooth
06:03kind of style of animation, which could be very, very useful if you're animating something and
06:07it's moving between different dots. Now that was easy. And that's why I wanted to start
06:12with the easy logic. And literally all you have to do is just come up with the points you
06:16want your element to go through. Now in the next lesson, I'm going to go back and we're
06:21not walking away from, from Bezier curves, and we're going to see how could we add a control
06:25point and have better control over how is it actually and what, what is the, is the
06:33curvature and what is the path that it's actually going through? Because literally,
06:37as this is animating, and if we're looking at this, we have your curvature, there's this
06:41curve that's going on here and there's a curve that's going on here. So we have your two
06:46theoretical strands that are being pulled and twigged and letting it go in a specific duration.
06:53In the next lesson, we're going to jump back into canvas for a second to kind of take a look
06:57at and understand how these curvature ideas work. How do you create a curved line in general?
07:03And what are the parameters that, that control those type of line creating? And then we're
07:08going to also see it, how do we control it with our Bezier plugin to make those type of
07:12animations and have that more in-depth control over our animation? It's a little bit more complex,
07:17but now that we watch this section and watch this video, I believe it's going to be really
07:21easy and really, really fun. So we'll see you in the next lecture where we continue
07:25modifying and controlling the curvature and directions, where our animations and how our
07:29animations are going to be rendered out.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!