0:00

[MUSIC].

Â Today we're going to talk a bit more about moving things around in graphics.

Â So in the first week we talked about how to draw stuff and there we could position

Â objects and then like rectangles, by giving the pixel positions.And for

Â example the white command and the ellipse command.

Â And, and that's fine, we can do that. And last week we talked about doing

Â animation, but animation with image sequences where we're playing lots of

Â different images all in the same position.

Â Today I'm going to talk about more powerful ways of moving objects around

Â beyond what you can do simply by putting positions into the x y coordinates to say

Â say, a rectangle. These techniques accord transforms, and

Â there are three of them. The first transform is translate, which

Â is a basic movement. Not too different from what you could do

Â by putting an X-Y position into, the position of a rectangle, so.

Â And that is a command for translate and you pass in an x and a y which is the

Â position you're moving whatever object too and it's a separate command to

Â whatever command drawing you're doing this.

Â So you can apply single translate to multiple objects.

Â And group objects together and move them around and I'll talk a little bit more in

Â detail about how you do that. And the basic premise to translate an x

Â and a y which gives you the position for which you'll translate.

Â So very similar to what we've done before.

Â The second one is a scale that's getting things bigger and smaller and that just

Â basically takes a number That is how much of scaling apply.

Â If that number's one you're not scaling it at all.

Â If it's less than one it's getting smaller.

Â If it's more than one it's getting bigger.

Â One quite useful thing about scale is you can also give it two parameters which

Â means you can scale separately about the x and the y.

Â So, you can make something wider While making it sort of the same time, having

Â high x scale and a small y scale. So the rotate command is used to spin

Â objects around. And it takes an angle as its parameter.

Â So that's how much you want to spin it by.

Â the normal way we talk about angles is in degrees 0, 360 degrees.

Â But in computer programming we often work with another way of dealing with angles

Â called radians. Now the units we shall explain in a

Â minute and you have to pass in that value and radiance through a take command.

Â If you don't want to get involved in radians, there's a very simple command

Â radians, that takes an angle in degrees and converts it to radians.

Â So I can just put radians 90 degrees, and it will do it all for me.

Â But if you want to know what radians are, this is it.

Â So radians work in terms of a circle. And we can think of an angle as cutting

Â out a chunk of a circle. So, like a, a, a slice of the pie.

Â now, if we make the circle of radius one. So, each of these two straight edges is

Â linked one. Then we can measure the angle by taking

Â the length of the arc, along the way just to be certain, so that's how much of the

Â edge of the circle is being cut out by my angle.

Â And that is a perfectly good measure of, of, of angles, and that's what's called

Â radians. A few things you need to know.

Â it's useful to know particular angles in radians, if you ever use them.

Â 4:11

The, 360 degrees is the entire circumference of the circle, and if you

Â remember from school maths And the circumference of a circle is two pi times

Â the radius. Because the radius is 1, the arc length

Â of 360 degrees is two pi. 180 degrees is half that, pi.

Â And 90 degrees is pi divided by two. So that, that's a useful way.

Â Thinking about, angles, you can use, put values in terms of pi directly into the

Â rotate command. But if you're not, if you don't want to

Â get involved in that, you can also the radians command I just showed you to

Â convert that to degrees. So what are transforms doing?

Â I said. That transforms can apply to multiple

Â objects and they're independent of the objects.

Â But how does a transform know to actually move an object, if it's a separate

Â command from do, doing so, drawing a rectangle or an ellipse.

Â Well what a transform does is in a way not move just the object, but move the

Â entire coordinate system. Sort of.

Â The, the screen. What does that mean?

Â Well I taught, told you a couple weeks ago about how we can represent any point

Â on screen by an x and a y. How we do that is that we need to know

Â which direction is x and which direction is y and that's normally horizontal and

Â vertical. We can change that.

Â But also, we need a starting point, we need to know where 0, X and 0 Y are and

Â normally, that is top left of the screen. But what a translation does, is move

Â that, so that anything after the translate.

Â 6:02

The zero-zero point. If I do Translate 20,100, I move my

Â zero-zero point to 20,100. So, if I draw an ellipse at point say,

Â 20,30, if I've done a transform on that, Then that's 20, 30, relative to the new

Â zero, zero points. So if I've transformed my 20 100s, it's

Â 20, 30 relative to 20, 100. Which is 20 plus 20, 40, 100 plus 30,

Â 130, relative. To the top left of the screen.

Â So I'm drawing, changing the way you draw everything.

Â It changes the meaning of the numbers you're putting into your rect command and

Â direct command .And what that means is that if you draw both an ellipse and a

Â rectangle they're both affect the same way.

Â So you can draw as many shapes as you like.

Â You can draw really complicated drawings, and then put a translate in front of it,

Â and they'll all move together. Exactly the same thing with scale, but

Â this time, rather than changing the 0,0 point, you're changing how much one unit

Â of x or one unit of y means, so If you scale up by two, each one unit you leave

Â in x counts for double. So each time you move one in x, you're

Â moving two in the original screen used. And finally the rotation, what that does

Â is it actually What takes the x and y axis.

Â So, it changes the direction of x and the direction of y.

Â So, they're pointing in different directions.

Â So, if I've done this translation you're seeing on, rotation you're seeing on the

Â screen then when I move across an x I'm no longer moving Just horizontal and

Â moving diagonal down the screen. So these transforms are very powerful

Â because they give you new ways of deforming and changing shapes.

Â But also because they can apply universally to multiple shapes. [MUSIC].

Â [MUSIC]

Â