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

Creating Curves using Code

At this stage its time for us to learn how to create curves. in this video we will understand how the curving system in flash works. in the most base summery every curve expects 3 points the origin and the final point plus a controller point (one that will help shape the angle of the curve.

Video Transcript

00:00All right, so let's start over.
00:01Let's create now, let's start talking about curves.
00:04To do that, I wanna just show you how curves work
00:07before we actually do it so it doesn't look too confusing.
00:09So let me just scroll up here a bit
00:12so we could grab here and create a corner.
00:15No, even better than that.
00:17Imagine that you have a dot,
00:18unless this is your dot and another dot.
00:20So you wanna draw a line between these two dots,
00:22but you wanna curve them.
00:24The way it works in Flash, you provide a Bezier curve.
00:27Now, the way Bezier curves work
00:29is you provide the first dot, the second dot,
00:32and a third dot, almost like a triangle.
00:34And then what Flash will do, or ActionScript will do,
00:37is when it drives and creates that line,
00:40it's gonna grab that line from the center
00:42and basically curve it in a way
00:47until it creates that curve.
00:50The closest it can to that dot.
00:52Kind of imagine that there's an invisible triangle here
00:55and the line is basically going to be created
00:58inside of that triangle.
01:01So this line is basically going to be created
01:03inside of this triangle as much as it could be pushed up.
01:07Okay, that's basically the logic behind Bezier curve.
01:11So let's see it in action.
01:14To do that, I'm going to just come again to my file
01:16and I wanna have that shape there again
01:18because it's probably better off
01:19not to draw directly onto our class.
01:22So I'm gonna create a new variable.
01:24Again, we're gonna call it shape.
01:26And first thing we're gonna do is create a new shape
01:32and we're gonna add our shape to the stage.
01:34But before we do that,
01:35we're gonna go right into our graphics library
01:37and we're gonna decide what will be our line style.
01:42After we create our line style,
01:44we're just gonna set it to have one
01:45so we can actually see it
01:47and it's time for us to start playing.
01:48So I'm gonna take my shape
01:50and I'm gonna add it to the stage immediately.
01:57Now we could have done that probably the line before that
01:58so let me just put that there
02:00and it's time for us to start playing.
02:01First thing I wanna do is I wanna grab my line
02:03and move it to somewhere else.
02:04So I'm gonna move it to the center of the screen
02:07or somewhere close to it.
02:08So I'm gonna move it to 100, 100.
02:10So like that's a little bit more into the screen.
02:13So now that we know our starting position is 100, 100,
02:16I wanna take our shape, graphics and start creating curves.
02:19So curve two, we're gonna take our controller
02:23which as we said before,
02:24our controller is gonna be that third variable
02:26that floats up there.
02:27So in our scenario, if we go up here again
02:30and we look at our elements
02:32and imagine that we are right now
02:35and if I'm gonna curve this up a bit.
02:38So imagine that right now we are at 100, 100.
02:41We're gonna give it a control point of let's say 0, 100.
02:49No, 0, 0.
02:50Let's give it a control point of 0, 0.
02:52Let's see what happens.
02:53This is really about exploring,
02:55learning and getting more comfortable.
02:56So we're gonna give it a 0, 0 control point
02:59and what I'm gonna do is I'm just gonna take 100
03:02for the X value, actually,
03:03I'm gonna push the X value even further to the right
03:07and I'm gonna keep the Y position static.
03:11So let's give it a run and let's see what happens.
03:14TC first of all, our original dots are in the same place.
03:18Our beginning point is right here.
03:19So if we drew this imaginary line here,
03:22it created this curve which is very extreme.
03:25Now, if we wanted our curve to be balanced,
03:27all we had to do is make sure that our control point
03:29was a point that was exactly between those two points.
03:32So let's see that in action.
03:33What control point would be exactly in the middle?
03:36It would be 150 for the X.
03:38So if I set here 150 for the X,
03:41leaving my Y all the way in the top,
03:42they're leaving that space of 100 pixels space
03:45and I run it one more time,
03:46we're gonna see that now our curve is a much more nice.
03:51Now, obviously, the more we play with it,
03:52the more we change it,
03:54the more interesting it's going to become.
03:57Now, if we wanted to make it even more dramatic,
04:00we could also go to negatives.
04:02That's completely fine.
04:03We can make it more extreme, all right?
04:06Or we can make it more tight.
04:08So if I come in and I put here a number
04:10that's really close to my original value,
04:12let's say 80, which is really not that far away
04:14from a straight line, right?
04:16And I first have to actually save it, obviously.
04:19Then you'll see that my curve
04:20gets less and less dramatic.
04:23Well, the larger, larger I do it,
04:26the more dramatic my curve becomes, all right?
04:30So I could control how much direction,
04:32I could control how wild my curve is,
04:35basically just based on these two graphical games,
04:38these two plays.
04:39Now, let's close our shape completely.
04:43Now, to close our curve completely,
04:45all we have to do is something very similar.
04:47So now that we are at 200, 100,
04:49we wanna go back to 100, 100.
04:52Now, we don't wanna go in the same direction,
04:54we actually wanna go in the exact opposite direction.
04:57So we wanna stay in the center, that is true.
05:00If we wanted the actual duplicate curve,
05:04we would just make sure that our gap is the same.
05:06So if here the gap was of 150,
05:10then we wanna make a gap of 150 forwards from 100.
05:14So 150 plus 100 would be 250.
05:17Now, if we do it that way,
05:18we're gonna see that our curve is gonna be identical.
05:21Obviously, it's not very smooth
05:22because it's not very smooth.
05:24We didn't find that perfect number
05:27that would create a perfect circle, all right?
05:31Now, just one more thing about this,
05:33we could always give it a fill as well.
05:35So our shape, graphics, begin film,
05:40and we could pick whatever color we want.
05:42I'm just gonna pick randomly a color,
05:43see what happens to that.
05:45And as always, when we're done,
05:47we're gonna have an end fill.
05:53Letting flash know you're done painting, all right?
05:57So that covers drawing curves.
05:59Obviously, if you're more creative than me,
06:01then your curves are gonna be a lot more creative
06:03than the curve that we've just created.

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!