Drawing with quadratic curves
A quadratic curve is a curve that has one control point. Consider the case when creating a line, we draw it between two points. When we want to create a quadratic curve, we use an external gravity controller that defines the direction of the curve while the middle line (the dotted line) defines how far will the curve reach.
Keynotes:
- Adding a control point to create curves.
- Understanding how to use the control point.
- Drawing an eye.
Video Transcript
00:00While the only control we had on an arc was its radius,
00:04when we're drawing with quadratic curves,
00:08we control where that control point is.
00:11So we could create a shape that is a lot more fluid.
00:14The process really is, instead of drawing
00:16from point A to point B, we're adding a control point
00:20in between them of a gravity of sort
00:22that pulls that line to create a curve.
00:25We're gonna learn how to use that in this selection
00:27and understand how to use a control point.
00:30By the end of this lesson, we'll create an eye.
00:33We're gonna draw an eye out together,
00:35leveraging the knowledge of creating a curve,
00:37a quadratic curve with a control point.
00:41So let's jump right into it.
00:44Let's take a step further in our animation.
00:48Now in your references, you're gonna find a chart.
00:52And this chart really shows you the next point,
00:54which is called quadric curves.
00:56Now, quadratic curves.
00:59Quadratic curves, the idea behind them
01:01is that you have a point that you wanna go from
01:04to a point that you wanna get to.
01:06But instead of taking a direct straight line to it,
01:09you really wanna curve it up.
01:11To be able to control that curve,
01:12you're gonna have a visual invisible dot
01:16that's controlling that dot
01:18to be able to create your curve.
01:21Now, let's say it in action.
01:22It's a little bit complicated.
01:23Once you get it, it gets much easier.
01:26The idea is, again, you have a starting point
01:28and an ending point.
01:29And something that's controlling it,
01:31by moving this line, you're changing the curve itself.
01:34And basically, it basically creates a circle
01:37that is going roughly to half of the length
01:41of that shape that you're creating.
01:44Let's go ahead and give it a try.
01:45So I'm gonna go right into my code and I already,
01:47again, pre-created a function called create quadric
01:51and set it up.
01:52I set my width and height and x and y,
01:54which were in the center point as we've done before,
01:57configured also a fill style, filled up our rectangle,
02:01and then set a stroke style, a fill style,
02:03and defined our line width.
02:06With that said, let's go ahead and start drawing.
02:07I'm gonna go into my context
02:09and I'm going to begin a new path.
02:12And I'm gonna show you the steps involved
02:14and what I wanna do is I'm gonna create an eye type
02:17of shape.
02:18To do that, I'm gonna go ahead and go to my context
02:21and I'm gonna move my item.
02:23First of all, I wanna move it to the first point
02:25and I wanna move it to the center point of our height
02:30but all the way to the edge in our x position.
02:33So x will be set and the y will be our center point
02:36which is set to y because our y is in the center
02:39of our screen.
02:40Once we move that, I'm ready to start drawing
02:42my quadric curve.
02:44And to do that, I'm gonna go to the context
02:46and call the method quadratic curve two.
02:52It's a mouthful.
02:53And it expects two, well four parameters.
02:56The x and y coordinates that are gonna be controlling
03:00which will be the first coordinates, the controllers.
03:04And the next coordinates are gonna be the actual target
03:07which will be our target points.
03:09So our target is gonna be in our case
03:11if we take a look at our application.
03:13If we're right here, our target is gonna be
03:15all the way to the end.
03:16So let's go ahead and define it.
03:18Those are the two last parameters.
03:19And all the way to the end would be the same y coordinate
03:23but instead of that, we'll take the full width
03:25and stay to the y.
03:26Taking the full width of our screen.
03:30For our controllers, where do we want our controller to be?
03:33Let's assume for a second that we want our controller
03:35to be basically exactly in the center point.
03:38So I'm gonna go ahead exactly in the center of this line
03:41which would be half of the width.
03:43Or really for that matter, it would be the x position
03:45because that's half of the width as well.
03:47If I do that, you'll see that I'm not gonna get
03:49much of an interesting quadratic curve.
03:51Well, actually it's gonna be very hard for us to see this.
03:54That is move two, first of all.
03:55And let me go ahead here and to call the context stroke
03:58so we could actually see what's actually going on in there.
04:02And let me, oh, it's gonna be blue right now.
04:05So let me actually close this shape up.
04:08So I'm gonna go to my context and I'm gonna close shape,
04:11close path really, and I'm gonna call the fill.
04:14So we should see your something maybe
04:17or maybe we won't see anything
04:18because really our shape itself is gonna be so thin
04:21and I have a little typo.
04:23Let me just copy from the side of my quadratic curve
04:26because I had there, I put there an extra e
04:29that was not needed.
04:30So let me go ahead here and click on refresh.
04:34And we're not seeing anything.
04:35Why aren't we seeing anything?
04:36Because our shape is so thin
04:38that we're actually not seeing anything.
04:40To be able to control that,
04:41let me go ahead to my x position
04:42and I'm gonna subtract from the position
04:45that I actually wanna control.
04:46Really the controller point that I want is the y.
04:49So I'm gonna go and just,
04:50so let's say I subtract 10 from that controller,
04:53you'll see that now we're gonna start getting a shape.
04:55And as that number will grow,
04:57as I change it and get it smaller and smaller,
05:00that shape will grow
05:01because literally I have your controller
05:03that is literally getting bigger and bigger and bigger,
05:06getting closer and closer.
05:08Now really what I wanna do,
05:08I wanna put my controller all the way on the top here.
05:11So to do that, all I really have to do
05:12is set my y to be zero.
05:14And if I do that,
05:15then I'm gonna get a beautiful half of an eye type of a shape.
05:20And I wanna do the exact same thing
05:22and do it to the other direction.
05:23So let me just copy this.
05:25Now, the one thing that you wanna do
05:26when you're doing these type of things
05:28is where is our first point?
05:30Our first point is now gonna be
05:31the last point where we were.
05:33Where do we wanna go to?
05:34Well, we wanna go to the same point
05:35that we were initially and that is our zero y.
05:38What controller do we want?
05:40We don't want the controller to be on the top.
05:42Contrary to that, we want the controllers
05:43to be all the way in the bottom,
05:45which will be the bottom of our height.
05:47And if I do that,
05:48then we'll have ourselves a nice, beautiful eye.
05:50Now, if I move that pointer, for example,
05:53here in our scope or here in our scope,
05:55notice what will happen.
05:56So if I go to my x coordinate,
05:58but this time around I tell them,
05:59hey, the control, I want you to be half of the x,
06:01which would be a quarter of our screen
06:03would be somewhere here at the controller.
06:05Notice how our eye will start getting distorted
06:08and leaning towards that point.
06:09And that's really the point of quadratic curves
06:13in general.
06:14Now, there's much more that you could do with it.
06:16The logic is all there.
06:17We covered everything.
06:18It's really just a matter of practice.
06:20And a lot of times it's also going to applications
06:23that have screen drawing capabilities
06:27because then you could see what the curve is.
06:29And we're gonna talk about that more soon.
06:32But before we wrap this up,
06:33I really wanna make this into an eye.
06:35So I'm gonna take advantage of our arc
06:37and I'm gonna begin another path.
06:39And what I wanna do, I'm gonna do it really quickly
06:41because it's something that we're familiar of.
06:43I'm gonna go to our arc.
06:45I'm gonna set it to the xy coordinates.
06:46I'm gonna define a radius that's gonna be
06:48half of the size of half of our screen.
06:51And I'm gonna go ahead and set my positions
06:54from zero all the way to 360,
06:56which would be math.py, two times math.py.
07:00Last but not least, this property doesn't really matter
07:02because we're closing it.
07:03It's that counterclockwise item.
07:05I'm gonna go ahead again and close my path.
07:07And last but not least,
07:08I'm gonna go ahead and call the stroke.
07:11And once I've done that,
07:12I've just created a kinda cool flag,
07:14which we could call it maybe the eye flag.
07:16But in our case, we decided to call it
07:18the quadratic flag.
07:20Try to say that 10 times fast.
07:24In this lesson, we controlled a curve
07:25with one control point,
07:27which was named a quadratic curve.
07:29In the next lecture,
07:31we'll learn how to draw with a Bezier curve,
07:34which basically means that we have two control points.
