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

Transforming the canvas

Throughout this title all our manipulations have targeted the items that where drawn. In the last lecture we moved to a type of transformation that focused on the canvas itself and in the next two lecture we continue down this path. In this lecture, we will learn how to transform the canvas.

Keynotes:

  • Understanding what transformation is.
  • Going over the properties.
  • Seeing it through samples.

Video Transcript

00:00In the last lesson when we were clipping,
00:02we were introduced to the concept of saving
00:04and restoring our canvas itself.
00:07We're gonna continue down this path
00:09because now we're gonna go ahead
00:10and completely manipulate our canvas and transform it.
00:14There's a lot of properties,
00:15so we're gonna understand what transformation is
00:17and we're gonna go through property by property
00:20and understand the six different numbers
00:22that we could use to really make our canvas
00:25look completely different
00:26or the shapes that we're working on
00:28and that specific point in time.
00:30So let's go ahead and let's see it through a live example.
00:36We're gonna stay in the sample
00:37that we were in in the last lecture
00:39and we're gonna move into a completely brand new type
00:42of manipulation which manipulates the canvas itself.
00:46We're gonna use the transform command
00:48and I wanna show you how that works.
00:50Just like with the clipping,
00:53once the clipping was done,
00:54then anything that was added was clipped,
00:57the same is true with transformations.
00:59And transformations ought to work
01:01with that instance of the constant.
01:04So if I saved it,
01:05I could go and restore.
01:06So if after I saved
01:07and probably I would wanna do it after a save,
01:09I would go ahead and create a transformation.
01:11Whenever I would call the restore,
01:13the restore would return it back to the way it was before.
01:17Now for the sake of the ARRI sample,
01:18I'm gonna go ahead
01:19and just get rid of the restore point for now
01:22because I wanna be able to show you the transform
01:24in a much more visible, very easy to see way.
01:28All right, so now let's go ahead
01:30and start manipulating the transform
01:32and I'm gonna go ahead in our sample,
01:34just go ahead to our context,
01:35call the transform command.
01:38And the transform command accepts six parameters.
01:42The first two parameters relate to the horizontal elements
01:46that are being manipulated.
01:48In this case,
01:49we're gonna transform everything here from here
01:51and there on until a restore point.
01:53And for the first point, I'm gonna say,
01:55I'm gonna go ahead
01:56and put here the default values of transformations,
01:59which are literally one, zero, zero, one, zero, zero.
02:04If I say this and go back and click on refresh,
02:06you'll see that literally it's gonna do absolutely nothing.
02:10So now that we have the core foundation,
02:12we'll go one by one and get to know them.
02:14The first item controls the scaling,
02:17the horizontal scaling.
02:19So if I go ahead here and say
02:20I want it to be 20% scaled upwards horizontally
02:24by saying one dot two,
02:26I'm gonna go ahead and you'll see
02:27that everything will be scaled 20% horizontally.
02:30I could, at the same way,
02:32go and also define the skewing
02:34and with the skewing,
02:35I could put here any value really
02:37that would skew the value.
02:38So in this case, I'm gonna put a very small value,
02:41like zero dot two
02:42and notice how sharp the skew is already gonna be
02:45with just zero dot two.
02:47So you could literally put here
02:48very, very small finite information
02:51that would skew our shape.
02:53The next step and the next two properties,
02:56the first one is skew,
02:57but this time it's not instead of a horizontal skew,
03:00we're moving to the vertical skew
03:02and the parameter after that is the vertical scaling.
03:06As you could see, it's one by default.
03:08So if I'm gonna go ahead to our vertical skewing,
03:10I could say, okay,
03:11I want to also do a skew of zero dot two
03:14that is also gonna be this horizontal,
03:16also the vertical skew,
03:18not only the horizontal,
03:19and if I do that,
03:20you'll see that it's now getting skewed also horizontally
03:23and if I wanted to,
03:24I could have said, hey,
03:25I want it to be in the negative quadrant
03:26and if I would set it to be negative,
03:28then it would skew towards the other direction.
03:31But I'm gonna keep it in the positive area
03:33and I'm also gonna make sure
03:34that this item is gonna be 30% larger
03:37than it was intended to be by default.
03:40Last but not least are the last two properties
03:43that are basically pushing our X and Y coordinates,
03:46moving our horizontal point
03:47as the first parameter and moving our vertical point.
03:51So I'm gonna say,
03:52I want to push my X position really,
03:55I want to push my horizontal point
03:57by let's say by 20 points forwards
03:59and my horizontal,
04:00I want to go back,
04:01let's say I want to go back,
04:02I want to go back 30 points.
04:04Let me go ahead and save this
04:05and if I click here on refresh,
04:07we'll have a very, very interesting shape
04:09where I'm pushing it also and moving it.
04:11Last thing that I want to do before we ramp things up
04:13and I actually want this to go like all the way
04:15to the end here.
04:16So I'm gonna go inside of here
04:17and I'm gonna set this to be maybe minus 20
04:20and I just want to be,
04:22I want my shape to go all the way to the end here.
04:24So I'm gonna go ahead here
04:25and go a little bit further
04:27and I'm gonna push this a little bit more
04:29because I basically want my shape to go all the way,
04:32all a little bit more.
04:33I actually want this to go maybe to zero.
04:36Let's give it another shot
04:38and this is almost almost good.
04:39Let me just push this a little bit further to 35
04:42and I think that should do the trick
04:44and I want to wrap this up
04:45but I want to show you another one thing
04:47before I ramp it up.
04:49In this case, I made everything transform
04:51but in reality, I would love for this drawing to happen
04:54before our transformation.
04:56To do that, I could literally cut that item,
04:58draw this out because I don't want it to be clipped.
05:01I could draw it out and have it drawn out
05:02before the transformation has been done
05:05and then I could go ahead and start a transform.
05:08I don't even need to restore a point in the stage
05:10because I'm creating a transform
05:13and followed suit after that,
05:14I'm beginning all the manipulation
05:17that's done later down the line.
05:19If I go ahead here and click on refresh,
05:21we'll see a very interesting shape
05:23of a combination of two different dimensions
05:25which makes it feel very 3D
05:27even though this is done in a two-dimensional sphere.
05:30So in this lesson, we learned about transformations
05:33and the next lesson is much easier
05:35in a wrapper of this title
05:37because then we're going to focus on one thing at a time
05:39as we're going to look at scaling, rotating and translating
05:42which in a sense is maybe all that transform
05:46only broken apart into three steps
05:48that are separate and distinct.
05:50So we'll see you in the next lesson
05:51when we scale, rotate and translate.

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!