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

Drawing with bezier curves (2 control point)

A bezier curve is a curve that has two control point. Consider the case when creating a line, we draw it between two points. When we want to create a bezier curve, we use two external gravity controller that defines the direction of the curve while one controls one side and the other the other of the bounded area.

Keynotes:

  • What are bezier curves.
  • Understanding how to use the two control point.
  • Drawing a shape.

Video Transcript

00:00It's time for us to move from one control point to two control points with Bezier curves.
00:06What we're going to do in this lesson is first get familiar with the concept of Bezier curves
00:11and basically how to use two control points, understand how to control these points.
00:16By the end of this lesson we'll create a unique shape again that will help us understand the differences
00:21between a Bezier curve and a quadratic curve. So let's jump right into it.
00:27There was all about the quadratic.
00:33I did it. Quadratic. Not going to say it anymore. A one controlled point type of arc.
00:40Now what we want to do is we want to be able to create more control.
00:43And to do that we're going to use something that's called a Bezier curve.
00:47Now a Bezier curve has two different control points.
00:50So instead of having one control point that's controlling everything,
00:54we'll have one control point that controls the first half
00:57and another control point that controls the other half.
01:00Making it easier for us to create something that is much more fluid
01:03and with a lot more finesse and control because you have two control points.
01:07So let's go ahead and see it in action.
01:09And what I'm going to do is I'm going to literally take the exact same sample of that quadratic
01:14I'm not going to say that word anymore.
01:16And instead of that I'm going to create basically I'm going to duplicate it.
01:20And I'm going to go ahead and literally just let me just go ahead and copy it.
01:24I have your pre-configured a function that I called the Bezier.
01:28Now I'm going to go ahead here and just make sure that that's going to be for our old generator,
01:33our canvas generator. And let's go ahead and create the Bezier curve.
01:37Now to do that I'm going to literally go ahead to our quadratic curve
01:41and I'm just going to duplicate the whole thing.
01:43There we go.
01:45And I'm just going to make sure also that I'm going to change the name of the method
01:49of the function to create Bezier.
01:52Now that I've done that literally all I'm going to do is I'm going to literally
01:55I'm just going to go ahead here just so that the colors are a little bit different.
01:59I'm just going to flip the colors around a little bit not even knowing what I'm creating here.
02:03And I'm just going to take that color set it up right here as well.
02:07And instead of creating quadratic curves I'm literally going to go ahead here
02:11and I'm just going to change it from quadratic.
02:15Forget that name, to Bezier.
02:17And I'm going to change it to Bezier.
02:19Now that I changed it to Bezier I'm going to have to send in two control points.
02:25The last point is going to be the point of the point B, remember from our samples.
02:30And then I'm going to have to have your two basically points.
02:33So I'm going to go ahead and just duplicate though whatever points we have there.
02:37And really that's going to be the shape that we want to create.
02:39But before that let's go ahead and even think how do we want to control the item.
02:43Let's start with putting our points at all the way to the top, all the way to the top.
02:47And let's see what value will come back and what shape would come back.
02:50So to do that I'm going to first, for the first point I'm going to set it to be at 0, 0.
02:54For the second point I'm going to set it to be not X but the full width.
02:58So I'm going to put the full width and 0.
03:00Let's go ahead and save this.
03:01And if I go ahead and click on refresh you'll see something really refreshing and interesting.
03:05You'll see that I'm getting this really controlled out shape.
03:08Giving me a lot more control points than I had previously.
03:12I could go ahead and do the exact same thing for the bottom as well.
03:15So for the bottom it wouldn't be 0 but it would be the full, the 0 width and the full height.
03:21And the second parameter we'd probably take the full width and the full height.
03:25And then we would create an exact mirror duplication but exactly the opposite.
03:30So if we wanted our control point to be actually to go into the other direction what we would have to do,
03:35in this case if we're thinking about it.
03:37If our point, right now we're at our width and Y.
03:44What does that mean?
03:45Right now if we're looking at our sample our starting point is this point.
03:49So if I set its control point as I've done right here to 0.
03:53What I'm actually saying that this control point of this region is sitting all the way in the corner here.
03:57What I really wanted to do is set that control point to be right here.
04:01So to do that I'm going to go right back in there and instead of that flip the control order.
04:06And that's really what I wanted to happen.
04:08Because we're starting from the other direction then I'm telling it that its control point will be this item.
04:13And for this half, this quadrant we want our control, our Bezier control to be on this side.
04:18And now when I've done that and I save it, if I go ahead and I click here on refresh,
04:22we'll see that we're going to get this really interesting much more rounded circle, almost oval.
04:28So go ahead and play around with the Bezier curve.
04:31There's a lot more to do with it.
04:33And we're actually going to cover that in the next lecture just seeing a really complicated shape and the process of creating it.
04:40In this lesson we controlled a line with two control points and we named it a Bezier curve.
04:47Let's take a break from curves because in the next lesson we'll learn how to draw images into Canvas.

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!