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

When one controller is not enough: qubic curves

Although I don't control the elements I do control qubic bezier curves and animations and so will you by the end of this lesson. A qubic bezier curve is a curve that is controlled with two points. In other words, between A and B there are two control Point that help define the angle of the curve.

Video Transcript

00:00As always, I made a slight error. I thought it's completely fine.
00:04This is a complicated topic, so it's a really good practice.
00:07So as you're watching, just try to figure out where my error is.
00:10It's towards the end. I kind of panically say,
00:12AHHH!
00:13And then you'll know that's basically that phase.
00:15But basically, the difference between the curve that we're going to be working on now,
00:20contrary to the first curve, is that now we have two control points.
00:24So really, it's not that hard.
00:25It just helps us create a plethora of even more intricate things, which is kind of nice, right?
00:35Right, let's see it in action. Let's see what I'm talking about.
00:38Animation.
00:39We've even seen the quadric animation that basically said we have a control point.
00:44The last item, and don't worry, there won't be 10 of them,
00:46there's the cubic animation.
00:49And the cubic animation enables us to have two points.
00:52So let's see it now. Let's see it in action.
00:56Let's take a visualization again. Let's first draw it.
00:58It's going to make our life a lot easier.
01:01So I'm going to go ahead there into my editor, and I'm going to go ahead and change these lines.
01:05And what I'm going to do this time around,
01:07I'm going to start just to make things really, really clean and simple.
01:10I'm going to start from the point 150, and I'm going to start from 150, 150, both.
01:16I'm going to draw my line to 290, which is almost the bottom of my screen.
01:22Actually, I want to keep my Y position constant.
01:26So I'm going to go ahead and, what am I doing? Why did I change the X?
01:29I'm going to go ahead and change the Y to stick to the same spot that it was before.
01:34And literally, I'm more or less drawing a square here.
01:37So I'm continuing down. Once I kept that in the same spot,
01:40I'm going to now push it all the way to 290.
01:43I'm literally just creating an arch here in the sorts.
01:47And last but not least, I'm going to bring it back up to that 150 point.
01:51But now we're going to stick to that 290 position.
01:54So literally, I'm creating here almost a box.
01:57And it's going to be a small little box.
01:59So if you go ahead there and click on refresh, we should see basically,
02:02and we have your apart missing because I really want it to be basically
02:06from here, going down here, here, and here.
02:08So how about I go back and tweak it a bit?
02:10Because what I really want is to start, let's say this point is fine,
02:13but I want it to actually go down to this point here and here
02:16to create like an arch, archy area kind of going on inside of here.
02:20So let me do that again. And let me start.
02:22Let me let me clean. Let me do a clean slate here.
02:25So I'm going to start from exposition of 100.
02:27I'm going to start from position 10.
02:28And let me just I'm going to go ahead here and even just delete everything here.
02:32Just draw my first line for my exit self.
02:35I don't really want to move the X.
02:37I'm going to stick to the same X that I was in,
02:39but I want to draw my line down almost to the bottom.
02:42So I'll draw it down to 290.
02:44If I save this and go back to my application,
02:46I should have your a nice long line here, which I do.
02:49Next step is I want to draw a lot a long line all the way down this line.
02:53So I'm going to go ahead and do that.
02:55So the next line that I'm going to draw, you know, sometimes you just,
02:58it's hard to wrap your head around things.
03:00So now that I'm already in the bottom position,
03:02I'm going to take this line and I'm going to continue going all the way to 700 here.
03:07And that should give me L shaped line two lines.
03:11So we have your in L shape.
03:13And last but not least, I want to pull back to the top,
03:16only not updating my exposition anymore.
03:19So I could literally just copy this.
03:21And this time around, I just want to animate.
03:23I want to just draw up my item back to position 10 that it was in.
03:28So I'll have your a nice two points that are my controllers
03:32and one point and one point, which is my starting point and ending point.
03:36So it's time for me to actually draw out my elements
03:38and have it draw out inside of this kind of a construction and see what would happen.
03:43So let's go ahead there.
03:44And I'm just going to comment out that animation that we had there also in the meantime,
03:48just so we don't have anything that is bothering our site as we're looking at this.
03:54Okay, perfect.
03:55So the next step is now that we've set that it's time for us to go to our curvatures
03:59and I'm going to undo that quadratic curve.
04:03And instead of that, I'm going to call my context dot bezier curve two.
04:09Now the bezier because don't forget we have our first point.
04:12This is where our starting point is.
04:13Our next two points are going to be controllers.
04:15So I'm going to put there a hundred and two ninety and I'm going to put there
04:20my seven hundred and two ninety as my two control points.
04:24And last but not least is my final position, which is seven hundred ten.
04:28Now, once I change and created this bezier curve,
04:31I'll be able to see how what happens when I have two control points.
04:35Now, if I look at this, you're going to tell me, Ben,
04:37there's not much of a difference really going on here.
04:40And the answer is you're right.
04:41There isn't a big difference between the two,
04:44but the big difference that's really going on here.
04:46And by the way, I want to adjust the starting point to be one hundred and ten
04:50instead of one hundred and fifty.
04:52So that way we should have the we should match up exactly where we should have been.
04:56And now that we start we're starting from the exact same starting point,
04:59we could see basically contrary to a quadratic curve,
05:05there was only one control point.
05:06In other words, there was only one curve possible.
05:10Contrary to that, when I'm using a cubic curve,
05:13I could change the point even to a place where I have here a snake zigzag.
05:17And it really just depends where this point is.
05:20So let me go ahead and just push this point to be maybe somewhere here instead.
05:23So let's go ahead and do that.
05:25And let me push that line to that second line too.
05:27I'm going to push my exposition down a little bit more inside
05:31and I'm going to push up my why.
05:32So it's going to be two hundred two hundred instead of what it was.
05:36And I'm going to go ahead and make sure that my first point here is also two hundred two hundred.
05:40So we can literally visually see that difference between those implementations.
05:45And if I do that, you'll see that you can see that we're having this.
05:47By the way, this is how you create really cool 3D effect styles going on as well.
05:52And you can see how I have here this two curvatures that are controlling things.
05:56And the more I push this in, the more of the curvature would be dramatic.
06:00So if I go ahead and say, hey, you know, let me put this really somewhere deep inside here,
06:04but it's going to be in a low y position.
06:06So if I go ahead here and say, OK, let me take this and I'm going to
06:09put it in a really deep position, I'm going to put it maybe even at four hundred
06:13and I'm going to set my y position only slightly bigger than our starting position.
06:19And what that would do is going to create a much more dramatic effect because now
06:23our rectangular area is wrapping inside of itself already.
06:27And the more we push it in, the more that curvature is going to be dramatically changed.
06:31So if I take this and I even push it even further in, how about we do that?
06:35We'll take this and maybe even push it even further to this point even.
06:39So if I go ahead and do that and I just just this is really just for the sake of art almost,
06:44just so you really understand the power of having more than one control point.
06:48And by doing that, I could literally create really, really custom curves that you can see.
06:54This is not a linear curve.
06:56This is a curve that's going in and going out.
06:58And the more of these that we have, the more detailed this art that we're creating could be.
07:03So now that we've seen the curvature itself, it's time for us to actually animate it.
07:07And lucky for us, the animation part itself is really easy once you understand the logic
07:11of how these elements are drawn out and make sure that you do understand that logic.
07:16All right.
07:16So now that we have the logic, all that's left for me to do is to copy the same
07:20tween that we had there.
07:21But instead of the values that we had inside before, let me just put it up.
07:26Oopsie.
07:27Let me just put it right here after that.
07:31And the next is instead of setting it to quadratic, I will set it to be cubic.
07:35And once I send it to cubic, now I have to make sure that I'm passing in all the values.
07:39So I'm starting with 110.
07:41So let me just set it to 110 and we have your 510.
07:46That would be our second point.
07:48500, what's it 10?
07:52No, 500, 100.
07:55So much from my memory.
07:59700 and 290.
08:01700 and 290.
08:05And we had also 700 and 10.
08:09And I'm just going to get rid of that extra item.
08:11And again, by the way, only I'll talk about that in a second.
08:13But first of all, we have our anchor point.
08:16Well, we have our actual point in the animation, our actual point animation.
08:21And we always have two that are actually our controllers.
08:26So if I save this and run it one more time,
08:28we're going to see that now our animation should follow through the curvature
08:32that we've created.
08:33Now, this gives us a lot more control
08:34because we can create really sophisticated curves for our animations as we need them.
08:40So before I wrap this up, I just want to say one more thing about this.
08:43And we're almost done with this chapter
08:45and almost done with talking about this plugin,
08:47which is a very important one for animation in general,
08:50is you can have as many as you want.
08:52Again, you just have to always have two controllers in between each one
08:55when you're using the cubic.
08:56So have two controllers.
08:57So in my case, if we wanted to flip our animation backwards
09:00and have it animate all the way back again,
09:02all I really had to do is just copy these items all the way
09:06in the same order, in the same sequence as they were in.
09:09Well, basically, I'm creating a mirror effect here, basically,
09:13and I'm giving it, taking it all the way back to the beginning as well.
09:17And literally, I could create this way very, very smooth animations
09:20and I could create as many as I want.
09:21So again, this was our first point.
09:24This is the controllers.
09:25Our second point, its controllers, our last point.
09:29And if we save this, go back to our application, click on refresh.
09:32We're going to see that it's going to go and come back
09:34in the same curvature, same exact path as it was before.
09:38Now, I want to show just one more small little thing
09:40is if you change the positions of our curvatures,
09:42and you might do that by mistake,
09:44you're going to create a completely different effect
09:45that you might not have planned.
09:47And if I do that, and let me just go ahead also
09:49and just show just, you know what,
09:51just for the sake of creating these lines,
09:54I'm going to go ahead and create another Bezier curve
09:56right after it and basically just switch around our Bezier curves.
10:01So this time around, it's going to be 700 to 90.
10:04That's our first one.
10:06Our second one is going to be our 510,
10:08and last is going to be our starting point that was before,
10:10which is going to be our ending point this time around.
10:13So that way we could see those curves as well,
10:15that new curve that we're creating.
10:18And if I click on Save here, we're going to see that,
10:19first of all, oh, we're not even seeing that curve
10:22that we created for some reason.
10:24But let's see if we could sort out why we're not seeing it.
10:27Let's see if we can do that.
10:38It's going to be crazy, I spent the last few minutes
10:40trying to figure out what the hell was I doing wrong.
10:42So basically what I was doing wrong is this,
10:45that I was switching these two together
10:47and I was also switching this to this item.
10:49But by doing that, what I was actually doing
10:51was just drawing the same line from the other direction.
10:54But what I really wanted to do was basically do this.
10:57Without changing the initial parameters here,
11:00basically call out our animation back.
11:02So I was a fool.
11:04I'll keep that beginning there
11:05because it will help you see that even I could be a fool,
11:08which I know that all the time.
11:10But it will help you also as you're practicing
11:12to see that we all make mistakes
11:14and that's how it will look like once you do that.
11:16And then you'll be able to see that curvature
11:19and that dramatic shift and dramatic difference
11:21because we're flipping it around
11:22and using different, basically the exact opposite.
11:25So creating here a very intricate animation.
11:29All right, so we'll see you in the next lecture.

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!