WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000 00:00:00.000 --> 00:00:04.960 [MUSIC PLAYING] 00:00:17.033 --> 00:00:19.200 BRIAN YU: Welcome back, everyone, to An Introduction 00:00:19.200 --> 00:00:20.430 to Programming with Scratch. 00:00:20.430 --> 00:00:23.220 And so far, in Scratch, we've seen our Scratch programs 00:00:23.220 --> 00:00:25.350 use a variety of different values. 00:00:25.350 --> 00:00:28.890 Values that keep track of what direction a sprite is pointing in, or how big, 00:00:28.890 --> 00:00:30.420 or how small the sprite is. 00:00:30.420 --> 00:00:31.930 Where it is, for example. 00:00:31.930 --> 00:00:35.940 And these are all pieces of information stored inside of our Scratch program 00:00:35.940 --> 00:00:39.210 that we can use later in our program to make decisions, 00:00:39.210 --> 00:00:42.150 or to make our program behave in different ways. 00:00:42.150 --> 00:00:45.070 But sometimes, as our programs get a little bit more complex, 00:00:45.070 --> 00:00:48.540 we will want to store other pieces of information inside of our program 00:00:48.540 --> 00:00:52.320 as well where we decide what information gets stored in our program, 00:00:52.320 --> 00:00:55.320 and how we use that information later on. 00:00:55.320 --> 00:00:58.680 And we're going to start to call these variables in the world of programming. 00:00:58.680 --> 00:01:01.140 And today, we'll explore variables in Scratch, 00:01:01.140 --> 00:01:03.460 and how it is that we can use them. 00:01:03.460 --> 00:01:06.142 So I'll go ahead and open up Scratch here as we have before. 00:01:06.142 --> 00:01:08.100 And there's one tab here that we haven't looked 00:01:08.100 --> 00:01:11.220 at yet, which is this Variables tab. 00:01:11.220 --> 00:01:14.220 And a variable you can think of as just some value. 00:01:14.220 --> 00:01:16.710 Some container inside of our Scratch program 00:01:16.710 --> 00:01:18.990 that's going to store some information. 00:01:18.990 --> 00:01:24.130 Information that we might be able to use later inside of our program as well. 00:01:24.130 --> 00:01:26.310 And so, for example, let's imagine I was trying 00:01:26.310 --> 00:01:31.740 to create a program that kept track of how many times I've clicked on the cat. 00:01:31.740 --> 00:01:34.350 So to do that, I want some piece of information, 00:01:34.350 --> 00:01:37.320 some container inside of my Scratch program, that's keeping 00:01:37.320 --> 00:01:40.500 track of how many times I've clicked on the cat. 00:01:40.500 --> 00:01:43.800 And to do that, I'll click on this Make a Variable button 00:01:43.800 --> 00:01:47.190 that will let me create a new variable, a new piece of information, 00:01:47.190 --> 00:01:49.598 that I would like to store inside of my program. 00:01:49.598 --> 00:01:51.390 And when I create a new variable, there are 00:01:51.390 --> 00:01:53.700 two things that I need to decide on. 00:01:53.700 --> 00:01:55.650 One is the name of that variable. 00:01:55.650 --> 00:01:58.590 And I'll call this, count, for example because I'm 00:01:58.590 --> 00:02:02.190 going to be counting how many times I've clicked on the cat. 00:02:02.190 --> 00:02:06.570 And the second decision I need to make is is this variable for all sprites, 00:02:06.570 --> 00:02:08.310 or for this sprite only? 00:02:08.310 --> 00:02:10.479 So there are two different types of variables. 00:02:10.479 --> 00:02:13.110 If I have a variable that's for all sprites, 00:02:13.110 --> 00:02:17.580 that means that any sprite is allowed to use or modify that variable. 00:02:17.580 --> 00:02:19.440 We often call this a global variable. 00:02:19.440 --> 00:02:21.870 Everyone can use that variable. 00:02:21.870 --> 00:02:24.420 Or we can have a variable that's for this sprite only. 00:02:24.420 --> 00:02:25.560 That's only for the cat. 00:02:25.560 --> 00:02:27.750 Nobody else is going to get to touch it. 00:02:27.750 --> 00:02:29.790 That's what we often call a local variable. 00:02:29.790 --> 00:02:32.550 Other sprites don't have the ability to use it. 00:02:32.550 --> 00:02:34.840 For now, we'll go ahead and use for all spites only. 00:02:34.840 --> 00:02:36.520 And we'll see why in just a moment. 00:02:36.520 --> 00:02:39.540 And that is the default. When you normally create a variable in Scratch, 00:02:39.540 --> 00:02:43.600 any sprite is going to have the ability to use it. 00:02:43.600 --> 00:02:46.200 So I've created a new variable called, count. 00:02:46.200 --> 00:02:48.960 And you'll notice that by default it's checked here. 00:02:48.960 --> 00:02:51.490 You see the little mark on the left hand side. 00:02:51.490 --> 00:02:54.270 And what you might have noticed is that on the stage 00:02:54.270 --> 00:02:58.260 we see something appear in the upper left portion of the stage that's 00:02:58.260 --> 00:03:01.800 just reporting to me what the current value of the count is. 00:03:01.800 --> 00:03:05.880 What information is stored inside of that container. 00:03:05.880 --> 00:03:09.360 And right now, I see that's stored inside of my count variable 00:03:09.360 --> 00:03:10.710 is the number 0. 00:03:10.710 --> 00:03:13.090 That's what happens to be there to begin with. 00:03:13.090 --> 00:03:15.090 If I don't want to see that, I could uncheck it. 00:03:15.090 --> 00:03:19.320 And then I wouldn't see the count appear on the stage at all. 00:03:19.320 --> 00:03:21.570 But here's what I want to have happen. 00:03:21.570 --> 00:03:23.590 Every time the cat is clicked-- 00:03:23.590 --> 00:03:26.370 so when this sprite clicked, that's the event that I want-- 00:03:26.370 --> 00:03:31.800 I'm going to go into variables and change the count by one. 00:03:31.800 --> 00:03:34.440 Change count by one means take that variable count 00:03:34.440 --> 00:03:37.170 and add 1 to whatever number is currently 00:03:37.170 --> 00:03:41.070 being stored inside of that variable. 00:03:41.070 --> 00:03:45.510 And then let's not say, hello, for two seconds. 00:03:45.510 --> 00:03:47.640 But whenever you create a variable, you suddenly 00:03:47.640 --> 00:03:49.770 get this variable block that appears here 00:03:49.770 --> 00:03:52.330 that you can drag into your program. 00:03:52.330 --> 00:03:54.270 Let's say the count for-- 00:03:54.270 --> 00:03:54.960 not two seconds. 00:03:54.960 --> 00:03:57.610 Let's say for one second, for example. 00:03:57.610 --> 00:04:01.260 So now, when I click on the cat, the cat says one. 00:04:01.260 --> 00:04:04.020 Click again, the cat says two. 00:04:04.020 --> 00:04:05.230 Now it says three. 00:04:05.230 --> 00:04:10.020 Every time I click on it, we're updating the value of that count variable. 00:04:10.020 --> 00:04:13.112 And the cat is saying whatever its value is. 00:04:13.112 --> 00:04:14.820 And I can check this count checkbox to be 00:04:14.820 --> 00:04:19.529 able to see right now count happens to be equal to the number seven. 00:04:19.529 --> 00:04:21.360 And when I click the count Again, now you 00:04:21.360 --> 00:04:24.360 see the count update to be the number eight. 00:04:24.360 --> 00:04:28.320 And so these variables give you the ability to keep track of information. 00:04:28.320 --> 00:04:30.880 And you might keep track of information in a number of ways. 00:04:30.880 --> 00:04:33.490 And we'll explore some of those ways today. 00:04:33.490 --> 00:04:36.780 But right now, every time I click on the cat, the count is going up, and up, 00:04:36.780 --> 00:04:37.320 and up. 00:04:37.320 --> 00:04:40.050 And there is no way for me to reset this thing. 00:04:40.050 --> 00:04:43.350 If I keep pressing the count, the count is going to keep going up. 00:04:43.350 --> 00:04:45.330 But it's never going back to 0. 00:04:45.330 --> 00:04:48.240 So let's add the ability to reset my program. 00:04:48.240 --> 00:04:52.620 Maybe a button that lets me reset the count back to 0. 00:04:52.620 --> 00:04:53.940 And how would that work? 00:04:53.940 --> 00:04:57.180 Well, a button is going to be a new sprite. 00:04:57.180 --> 00:05:01.040 So I go down below, and choose a new sprite to add. 00:05:01.040 --> 00:05:04.760 And let's add this button here. 00:05:04.760 --> 00:05:07.010 I'll drag it to the corner. 00:05:07.010 --> 00:05:09.220 And I want to change what the button says. 00:05:09.220 --> 00:05:13.190 So we'll go into costumes, and let's add some text. 00:05:13.190 --> 00:05:17.960 And the text is going to say, "Reset." 00:05:17.960 --> 00:05:21.200 It should change the color of that text. 00:05:21.200 --> 00:05:24.390 We;ll make it black text. 00:05:24.390 --> 00:05:25.890 And let's make it a little larger. 00:05:30.100 --> 00:05:33.720 So now I have a button to reset the count. 00:05:33.720 --> 00:05:37.950 And now what do I want to have happen when this sprite is clicked on? 00:05:37.950 --> 00:05:39.780 When the reset button is clicked? 00:05:39.780 --> 00:05:45.920 Let's go into variables, and let's set the count to 0. 00:05:45.920 --> 00:05:48.740 And so because this variable I said should 00:05:48.740 --> 00:05:52.440 be accessible by all of the sprite, it's a global variable, 00:05:52.440 --> 00:05:55.910 it means both the cat sprite and the button sprite 00:05:55.910 --> 00:05:57.710 are allowed to use that variable. 00:05:57.710 --> 00:06:01.620 They can both make reference to that count variable. 00:06:01.620 --> 00:06:04.160 And here, I'm using set count to 0. 00:06:04.160 --> 00:06:08.420 Meaning take the number 0, and put that inside of the container. 00:06:08.420 --> 00:06:12.530 That's different from change count by, which adds or subtracts 00:06:12.530 --> 00:06:15.440 a number from one particular variable. 00:06:15.440 --> 00:06:19.610 Here, I'm just saying whatever value the count has now, ignore that and instead 00:06:19.610 --> 00:06:24.010 put the value 0 inside of the count instead. 00:06:24.010 --> 00:06:28.990 And so now at this point, I can keep clicking on the cat. 00:06:28.990 --> 00:06:31.840 Count goes up to 9, and then to 10. 00:06:31.840 --> 00:06:34.460 But watch what happens when I click the Reset button. 00:06:34.460 --> 00:06:38.320 When I click Reset, you'll notice the count goes back to 0. 00:06:38.320 --> 00:06:41.170 And now the next time that I click on the cat, now the cat 00:06:41.170 --> 00:06:45.830 is going to say one, and then two, and then three. 00:06:45.830 --> 00:06:49.680 So these variables now give us the ability to keep track of information. 00:06:49.680 --> 00:06:50.990 But what can we use that for? 00:06:50.990 --> 00:06:52.640 How is that helpful to us? 00:06:52.640 --> 00:06:55.340 Well, you might imagine that we could use this inside of a game. 00:06:55.340 --> 00:06:58.722 In many games you might have played, for example, on a phone or on a computer, 00:06:58.722 --> 00:07:00.680 you might have had the game keep score for you. 00:07:00.680 --> 00:07:04.170 It's keeping track of how many points you've earned in the game for example. 00:07:04.170 --> 00:07:06.470 And it goes up, and up, and up as you earn points. 00:07:06.470 --> 00:07:09.110 We can achieve that by using a variable. 00:07:09.110 --> 00:07:12.830 We can have a variable that's keeping track of what score we have in a game. 00:07:12.830 --> 00:07:16.860 And we update that variable as the score changes. 00:07:16.860 --> 00:07:17.840 So let's build a game. 00:07:17.840 --> 00:07:20.660 I'm going to delete these sprites for now. 00:07:20.660 --> 00:07:22.940 And I'm also going to delete the count variable, which 00:07:22.940 --> 00:07:24.980 I can do by control clicking on Count. 00:07:24.980 --> 00:07:27.690 And just saying delete the count variable. 00:07:27.690 --> 00:07:29.270 Now that goes away. 00:07:29.270 --> 00:07:34.590 Let's create a game using the hedgehog. 00:07:34.590 --> 00:07:36.270 So here's our hedgehog. 00:07:36.270 --> 00:07:40.500 And I'll do something similar to what I did with the fish last time. 00:07:40.500 --> 00:07:43.380 I'll say when the green flag is clicked, let's 00:07:43.380 --> 00:07:50.940 have it forever point towards the mouse pointer, and move five steps. 00:07:50.940 --> 00:07:52.680 We've seen this kind of code before. 00:07:52.680 --> 00:07:55.290 What this is going to do is when I press the green flag, 00:07:55.290 --> 00:07:57.000 the hedgehog is going to start moving. 00:07:57.000 --> 00:08:00.480 And it's just constantly going to be following the cursor forever. 00:08:00.480 --> 00:08:02.820 It's going to point towards my mouse cursor, 00:08:02.820 --> 00:08:07.290 and then it's going to move five steps towards me. 00:08:07.290 --> 00:08:08.498 So that works well. 00:08:08.498 --> 00:08:09.790 But let's now make this a game. 00:08:09.790 --> 00:08:11.340 What is the hedgehog trying to do? 00:08:11.340 --> 00:08:13.390 Well, maybe it's trying to chase after something. 00:08:13.390 --> 00:08:15.210 What's it going to chase after? 00:08:15.210 --> 00:08:17.280 Let me choose a new sprite. 00:08:17.280 --> 00:08:23.740 Let's go ahead and pick the star. 00:08:23.740 --> 00:08:28.100 We'll have the hedgehog chasing after this star here. 00:08:28.100 --> 00:08:30.410 And how is the star going to work? 00:08:30.410 --> 00:08:34.429 Well, the star is going to work where if the hedgehog is ever touching the star, 00:08:34.429 --> 00:08:37.070 then we're going to increase our score by one. 00:08:37.070 --> 00:08:39.289 We're keeping track of how many points we've earned. 00:08:39.289 --> 00:08:41.240 So to do that, I need a new variable. 00:08:41.240 --> 00:08:46.010 I'll go into Variables, I'll make a new variable that I will call Score. 00:08:46.010 --> 00:08:47.120 And press OK. 00:08:47.120 --> 00:08:50.810 So I now have this new variable called Score. 00:08:50.810 --> 00:08:55.230 And for the star I'm going to say, when the green flag is clicked, 00:08:55.230 --> 00:09:01.690 I want the star to forever be checking if we're touching the hedgehog. 00:09:01.690 --> 00:09:03.280 Side add an if statement. 00:09:03.280 --> 00:09:07.760 And then under sensing, check not if we're touching the mouse pointer, 00:09:07.760 --> 00:09:10.430 but if we're touching the hedgehog. 00:09:10.430 --> 00:09:13.430 So the star is going to constantly check if we're touching the hedgehog. 00:09:13.430 --> 00:09:17.120 And if we are touching the hedgehog, then under variables, 00:09:17.120 --> 00:09:19.598 I'm going to change not my variable, which 00:09:19.598 --> 00:09:21.890 is a variable that's created for you automatically when 00:09:21.890 --> 00:09:28.000 you first create your Scratch program, but I want to change the score by one. 00:09:28.000 --> 00:09:33.430 And after you change the score by one, let's go to a random position. 00:09:33.430 --> 00:09:35.890 To keep things interesting, the star will just move around 00:09:35.890 --> 00:09:39.390 after we increase the score by one. 00:09:39.390 --> 00:09:41.640 So now we can try playing the game. 00:09:41.640 --> 00:09:42.840 I'll play the game. 00:09:42.840 --> 00:09:44.790 The hedgehog's following me around. 00:09:44.790 --> 00:09:49.560 And watch what happens when I end up going to the star. 00:09:49.560 --> 00:09:52.770 You'll notice that immediately the score went up by one. 00:09:52.770 --> 00:09:56.910 And you'll also notice that the star moved to a different random location. 00:09:56.910 --> 00:09:59.610 Now when I get to the star again, the score goes up to two. 00:09:59.610 --> 00:10:01.320 And the star moves. 00:10:01.320 --> 00:10:02.820 And I have a little game here. 00:10:02.820 --> 00:10:10.010 Every time I move around, we end up going to the star 00:10:10.010 --> 00:10:13.220 and increasing the number of points. 00:10:13.220 --> 00:10:14.650 So what do I want to add to this? 00:10:14.650 --> 00:10:16.580 What should I change about this? 00:10:16.580 --> 00:10:18.670 Well, one thing I should probably change is 00:10:18.670 --> 00:10:20.890 that when the program begins, when I press 00:10:20.890 --> 00:10:23.560 the green flag for the very first time, I probably 00:10:23.560 --> 00:10:25.900 want to reset the score back to 0. 00:10:25.900 --> 00:10:29.260 In most games you play when you play it again, the score goes back to 0, 00:10:29.260 --> 00:10:32.000 and you have to start earning points from the beginning again. 00:10:32.000 --> 00:10:34.450 So I can say when the green flag is clicked, 00:10:34.450 --> 00:10:40.090 before the forever loop happens I want to set the score to 0. 00:10:40.090 --> 00:10:43.160 Notice this line should not be inside of the forever loop. 00:10:43.160 --> 00:10:46.300 Otherwise, it's going to forever be resetting the score back to 0, 00:10:46.300 --> 00:10:47.540 which is not what I want. 00:10:47.540 --> 00:10:51.040 I want the score to be set to 0 at the very beginning of the program. 00:10:51.040 --> 00:10:54.670 But after that, then I want to go into this forever loop 00:10:54.670 --> 00:10:56.830 where the hedgehog is going to be following me. 00:10:56.830 --> 00:10:59.980 So now the score goes back to 0 when I press the green flag. 00:10:59.980 --> 00:11:04.650 And I can start earning points again. 00:11:04.650 --> 00:11:06.002 Now how do I win this game? 00:11:06.002 --> 00:11:08.460 Now I'm just earning points and nothing's really happening. 00:11:08.460 --> 00:11:12.082 Well, maybe I win the game once I get to a certain number of points. 00:11:12.082 --> 00:11:13.290 That sounds like a condition. 00:11:13.290 --> 00:11:17.310 Once I get to a situation where I have maybe 10 points, 00:11:17.310 --> 00:11:19.980 we can call that winning the game. 00:11:19.980 --> 00:11:21.570 And what happens when I win the game? 00:11:21.570 --> 00:11:22.920 I have to decide. 00:11:22.920 --> 00:11:25.110 Maybe the backdrop changes. 00:11:25.110 --> 00:11:26.760 I can take a backdrop. 00:11:26.760 --> 00:11:29.250 Add a new backdrop. 00:11:29.250 --> 00:11:31.680 Well, instead of picking an existing backdrop actually, 00:11:31.680 --> 00:11:33.860 let me paint a new backdrop. 00:11:33.860 --> 00:11:35.330 Paint a new backdrop. 00:11:35.330 --> 00:11:41.880 We'll go ahead and just create a green background 00:11:41.880 --> 00:11:44.960 by drawing a green rectangle. 00:11:44.960 --> 00:11:47.030 And we'll add some text. 00:11:47.030 --> 00:11:48.350 The text will say, you win. 00:11:48.350 --> 00:11:50.850 I need to change the color of that. 00:11:50.850 --> 00:11:53.310 Make it black. 00:11:53.310 --> 00:11:54.510 And make the text bigger. 00:11:58.420 --> 00:12:01.090 So that'll be the backdrop that shows up when we win. 00:12:01.090 --> 00:12:02.780 I'll give you the backdrop a name. 00:12:02.780 --> 00:12:05.200 I'll call it Win. . 00:12:05.200 --> 00:12:08.450 And the other backdrop is just backdrop one for now. 00:12:08.450 --> 00:12:10.480 And so what do I need to change here? 00:12:10.480 --> 00:12:14.140 Well, when the program first starts, I want to set the score to 0. 00:12:14.140 --> 00:12:19.640 But I also want to make sure that the backdrop is backdrop one. 00:12:19.640 --> 00:12:23.080 The default plain white backdrop to begin with. 00:12:23.080 --> 00:12:25.830 But now let's add some code. 00:12:25.830 --> 00:12:31.630 And I would like to say maybe when we change 00:12:31.630 --> 00:12:36.040 the score I want to ask the question, have we won the game yet? 00:12:36.040 --> 00:12:43.730 I can add another condition by going to if here after we change the score. 00:12:43.730 --> 00:12:46.940 And random position that's going to be outside of this if statement. 00:12:46.940 --> 00:12:53.000 But if the score is equal to 10-- 00:12:53.000 --> 00:12:54.190 so something is equal to 10. 00:12:54.190 --> 00:12:55.060 And how do I get the score? 00:12:55.060 --> 00:12:55.970 That's a variable. 00:12:55.970 --> 00:12:57.890 So I go into variables. 00:12:57.890 --> 00:13:01.880 If the score is equal to 10, well, then I want to display this backdrop. 00:13:01.880 --> 00:13:05.230 The backdrop that says that I've now won the game. 00:13:05.230 --> 00:13:06.650 So we'll go into looks. 00:13:06.650 --> 00:13:08.880 We'll switch the backdrop to Win. 00:13:08.880 --> 00:13:12.230 But at this point, I also just want to stop the entire game. 00:13:12.230 --> 00:13:13.980 I don't want the hedgehog to move anymore. 00:13:13.980 --> 00:13:16.670 I don't want to have the star keep going to random positions. 00:13:16.670 --> 00:13:19.820 And it turns out that under control, there's one block we haven't used yet 00:13:19.820 --> 00:13:23.120 which is just called stop all that has the effect of stopping 00:13:23.120 --> 00:13:27.260 all of the sprites that are in this program. 00:13:27.260 --> 00:13:28.962 So we'll switch the backdrop to Win. 00:13:28.962 --> 00:13:30.170 And then we'll just stop all. 00:13:30.170 --> 00:13:32.500 We'll stop everything. 00:13:32.500 --> 00:13:34.500 So this program's getting a little more complex. 00:13:34.500 --> 00:13:36.542 But let's try and understand now what's happening 00:13:36.542 --> 00:13:38.360 inside the logic for the star. 00:13:38.360 --> 00:13:41.540 We're constantly going to be checking are we touching the hedgehog. 00:13:41.540 --> 00:13:44.550 If we're touching the hedgehog, we change the score by one. 00:13:44.550 --> 00:13:47.170 And if now the score is 10, well, now we've won the game. 00:13:47.170 --> 00:13:50.730 So we switch the backdrop, and then we stop all the sprites. 00:13:50.730 --> 00:13:54.860 But otherwise, the star just goes to a new random position 00:13:54.860 --> 00:13:58.100 to let the game keep going. 00:13:58.100 --> 00:14:02.200 So we can try the game now, and see what happens when I get to 10 points. 00:14:02.200 --> 00:14:03.790 I'll press the flag. 00:14:03.790 --> 00:14:04.660 The scores of 0. 00:14:04.660 --> 00:14:07.630 The backdrops gone back to this plain white background. 00:14:07.630 --> 00:14:10.810 And now every time I touch the star, it goes to a new random position. 00:14:10.810 --> 00:14:13.810 And you can watch my score in the upper left increase. 00:14:13.810 --> 00:14:17.740 I'm at 6.7 points, 8 points, 9 points. 00:14:17.740 --> 00:14:20.050 And watch what happens now as I get the 10th star. 00:14:22.760 --> 00:14:24.020 Everything freezes. 00:14:24.020 --> 00:14:25.760 The hedgehog's no longer following me. 00:14:25.760 --> 00:14:28.970 But we change the backdrop to this green backdrop 00:14:28.970 --> 00:14:31.850 that now just says that we win. 00:14:31.850 --> 00:14:35.210 So one common use of variables is to keep track of your score 00:14:35.210 --> 00:14:38.840 in a game in something like this for example. 00:14:38.840 --> 00:14:41.840 Let's take a look at another use that we might use for variables. 00:14:41.840 --> 00:14:44.330 I'll go ahead and get rid of these sprites for now. 00:14:44.330 --> 00:14:46.130 And I'll get rid of the you win backdrop. 00:14:46.130 --> 00:14:49.670 And we'll just go back to the plain white backdrop. 00:14:49.670 --> 00:14:55.110 And I'll also delete that score variable, which I don't want any more. 00:14:55.110 --> 00:14:56.640 Let's choose a new backdrop. 00:14:56.640 --> 00:14:59.040 Let's choose Blue Sky, which is nice. 00:14:59.040 --> 00:15:01.510 We've got the sky and we've got the ground for example. 00:15:01.510 --> 00:15:03.960 And let's imagine that we wanted a ball, for example, 00:15:03.960 --> 00:15:07.600 to be bouncing on the stage. 00:15:07.600 --> 00:15:10.200 Well, let's add a sprite. 00:15:10.200 --> 00:15:12.910 And let's add the ball. 00:15:12.910 --> 00:15:14.280 Here's the ball. 00:15:14.280 --> 00:15:15.998 And what do I want the ball to do? 00:15:15.998 --> 00:15:17.790 Well, if it's in the air, the ball is going 00:15:17.790 --> 00:15:21.190 to start falling until it hits the ground. 00:15:21.190 --> 00:15:22.440 So how do I achieve that idea? 00:15:22.440 --> 00:15:25.920 The ball is going to keep falling until it hits the ground. 00:15:25.920 --> 00:15:29.070 Well, when the green flag is clicked, I would like 00:15:29.070 --> 00:15:32.811 to forever keep repeating something. 00:15:35.630 --> 00:15:37.380 And what do I want to have happen forever? 00:15:37.380 --> 00:15:46.452 Well, I want to have happen for motion to change the y value by negative 5. 00:15:46.452 --> 00:15:48.910 Negative 5 is going to mean the ball is going to move down, 00:15:48.910 --> 00:15:51.590 and we're forever going to keep repeating that process. 00:15:51.590 --> 00:15:55.610 So now when I press the flag, the ball falls 00:15:55.610 --> 00:15:57.940 and eventually it hits the ground. 00:15:57.940 --> 00:16:00.230 And if I bring it back up again, it keeps falling 00:16:00.230 --> 00:16:02.716 because it's inside of a forever loop. 00:16:02.716 --> 00:16:04.270 It's inside of a forever loop. 00:16:04.270 --> 00:16:07.793 So every time it's going to keep falling until it hits the ground. 00:16:07.793 --> 00:16:09.960 And right now, it's kind of getting past the ground. 00:16:09.960 --> 00:16:13.900 So maybe I want it to stop if it ever hits the ground itself. 00:16:13.900 --> 00:16:17.443 So how can I detect when the ball is touching the ground? 00:16:17.443 --> 00:16:19.860 Well, you'll notice that the ground is a particular color. 00:16:19.860 --> 00:16:21.450 It's this brown color here. 00:16:21.450 --> 00:16:29.430 And I can check for that color by saying if we're touching that color. 00:16:29.430 --> 00:16:32.070 Using if and touching color, which we've used before, 00:16:32.070 --> 00:16:34.260 I can check to see if we're touching the ground. 00:16:34.260 --> 00:16:36.630 I'll grab a color from the stage. 00:16:36.630 --> 00:16:39.240 Let's grab this brown for the ground. 00:16:39.240 --> 00:16:46.110 And if we're touching brown, let's go ahead and stop everything. 00:16:46.110 --> 00:16:49.130 The ball is going to stop moving. 00:16:49.130 --> 00:16:50.990 So now I press the flag. 00:16:50.990 --> 00:16:51.950 The ball falls. 00:16:51.950 --> 00:16:53.690 And now as soon as it touches the ground, 00:16:53.690 --> 00:16:57.500 as soon as it just reaches the beginning of that brown section, 00:16:57.500 --> 00:16:59.210 the ball is going to stop moving. 00:16:59.210 --> 00:17:02.060 And if I wanted to go again, I press the green flag. 00:17:02.060 --> 00:17:07.395 And you notice the ball fall until it hits the ground, and then it stops. 00:17:07.395 --> 00:17:09.520 And as we're watching this, I can drag the ball out 00:17:09.520 --> 00:17:11.510 and let it fall over and over again. 00:17:11.510 --> 00:17:14.319 You might notice that it doesn't look very realistic. 00:17:14.319 --> 00:17:16.730 And why isn't this falling very realistic? 00:17:16.730 --> 00:17:18.650 Well, I have a ball here with me now. 00:17:18.650 --> 00:17:21.310 And what happens if I toss the ball, and let it fall? 00:17:21.310 --> 00:17:23.140 How quickly does it fall? 00:17:23.140 --> 00:17:26.920 Well, you'll notice as I let that ball fall, that it actually 00:17:26.920 --> 00:17:28.420 starts a little more slowly. 00:17:28.420 --> 00:17:30.250 At the top, it's more slow. 00:17:30.250 --> 00:17:33.370 And then as it falls, over time, it gets faster and faster. 00:17:33.370 --> 00:17:36.160 And it falls faster as it gets closer to the ground. 00:17:36.160 --> 00:17:38.650 It's slow, and then it gets faster. 00:17:38.650 --> 00:17:41.950 And right now, that's not what my ball here is doing. 00:17:41.950 --> 00:17:46.300 Right now, my ball is just moving by five units every time 00:17:46.300 --> 00:17:50.300 we run through an iteration of this loop. 00:17:50.300 --> 00:17:54.430 And so if I really wanted for the ball to be moving realistically, 00:17:54.430 --> 00:17:57.460 it should be moving slower at first, and then 00:17:57.460 --> 00:18:01.660 get faster as it gets closer to the ground. 00:18:01.660 --> 00:18:03.110 So how could we achieve that? 00:18:03.110 --> 00:18:06.250 Well, rather than move by five steps every time, 00:18:06.250 --> 00:18:09.220 we could move by a variable number of steps every time. 00:18:09.220 --> 00:18:13.720 A variable that's keeping track of how many steps should we be moving. 00:18:13.720 --> 00:18:16.450 And then we can update that variable so that the ball moves 00:18:16.450 --> 00:18:20.560 faster as it gets closer to the ground. 00:18:20.560 --> 00:18:21.950 So how do we achieve that? 00:18:21.950 --> 00:18:25.070 Well, the first thing we need is we need a new variable. 00:18:25.070 --> 00:18:28.870 So I'm going to go into variables here, and create a new variable. 00:18:28.870 --> 00:18:31.300 And I'll just call the variable, speed. 00:18:31.300 --> 00:18:33.640 And now I have a decision to make as I usually do. 00:18:33.640 --> 00:18:35.440 Is this for all sprites? 00:18:35.440 --> 00:18:37.390 Or for this sprite only? 00:18:37.390 --> 00:18:40.570 And for this variable, I'm actually going to make it for this sprite only. 00:18:40.570 --> 00:18:42.580 This speed is only going to be a variable 00:18:42.580 --> 00:18:46.150 that this ball is going to get to use, because no other sprite needs 00:18:46.150 --> 00:18:49.060 to use or access the speed of the ball. 00:18:49.060 --> 00:18:51.400 And that's going to be helpful because maybe later I 00:18:51.400 --> 00:18:54.350 might want to have a second ball that's bouncing up and down too. 00:18:54.350 --> 00:18:56.953 And then each ball should have its own speed. 00:18:56.953 --> 00:18:58.870 I don't want them to be sharing the same speed 00:18:58.870 --> 00:19:03.500 because one ball might be moving more slowly or more quickly than the other. 00:19:03.500 --> 00:19:06.250 So this variable is going to be a local variable. 00:19:06.250 --> 00:19:10.793 Only this ball is going to get to modify this speed variable. 00:19:10.793 --> 00:19:13.210 And you'll notice that now, in this reporting block that's 00:19:13.210 --> 00:19:15.640 telling me what the speed of the ball is, it's telling me 00:19:15.640 --> 00:19:19.600 it's the speed variable that is associated with the ball sprite. 00:19:19.600 --> 00:19:24.410 It's telling me what sprite the variable belongs to. 00:19:24.410 --> 00:19:27.300 And so now, what do I do here? 00:19:27.300 --> 00:19:30.350 Well, initially, when I press the green flag for the first time, 00:19:30.350 --> 00:19:33.670 let's set the speed to 0. 00:19:33.670 --> 00:19:41.110 Then instead of changing y by negative 5, let's change y by the speed. 00:19:41.110 --> 00:19:43.175 Changing it by a variable amount. 00:19:43.175 --> 00:19:44.800 And then what do I want to have happen? 00:19:44.800 --> 00:19:48.430 Every time the loop goes through, every time time passes, 00:19:48.430 --> 00:19:53.410 I want to move faster down the stage, which means 00:19:53.410 --> 00:19:55.480 I want this value to be more negative. 00:19:55.480 --> 00:20:01.140 So I'm going to change the speed by negative 1. 00:20:01.140 --> 00:20:02.160 What does that mean? 00:20:02.160 --> 00:20:04.670 That means the speed is going to start at 0. 00:20:04.670 --> 00:20:07.760 And the first time we run through the loop, we're going to change y by 0. 00:20:07.760 --> 00:20:09.325 We're not changing it at all. 00:20:09.325 --> 00:20:11.450 Then we're going to change the speed by negative 1. 00:20:11.450 --> 00:20:13.190 Now the speed is negative 1. 00:20:13.190 --> 00:20:15.245 We're going to change y by negative 1. 00:20:15.245 --> 00:20:17.120 Then we change the speed by negative 1 again. 00:20:17.120 --> 00:20:18.650 Now it's negative 2. 00:20:18.650 --> 00:20:21.920 And the next time the loop runs we change y by negative 2, 00:20:21.920 --> 00:20:22.850 and then negative 3. 00:20:22.850 --> 00:20:25.125 And every time we run through the loop, the ball 00:20:25.125 --> 00:20:27.500 is going to be moving more, and more, and more each time. 00:20:27.500 --> 00:20:34.290 Effectively, moving faster as time goes on until it's touching the ground. 00:20:34.290 --> 00:20:40.460 And so let's give that a try now, and see what happens. 00:20:40.460 --> 00:20:42.730 Bring the ball up. 00:20:42.730 --> 00:20:43.300 And it falls. 00:20:43.300 --> 00:20:45.670 And you'll notice that it does exactly what I want. 00:20:45.670 --> 00:20:49.722 At the very beginning, it's falling fairly slowly. 00:20:49.722 --> 00:20:51.180 But then it speeds up near the end. 00:20:51.180 --> 00:20:54.300 You notice near the end the ball speed is all the way up to negative 24, 00:20:54.300 --> 00:20:55.140 for example. 00:20:55.140 --> 00:20:58.800 It's getting faster and faster. 00:20:58.800 --> 00:21:00.470 And so that's working pretty well. 00:21:00.470 --> 00:21:04.430 It's more realistic now because at the very beginning, 00:21:04.430 --> 00:21:05.810 the ball is moving slowly. 00:21:05.810 --> 00:21:08.010 And then over time it's getting faster and faster. 00:21:08.010 --> 00:21:10.760 Of course, the thing that it's not doing that a real ball would do 00:21:10.760 --> 00:21:12.110 is it's not bouncing. 00:21:12.110 --> 00:21:14.270 Normally, when I bounce a ball, it hits the ground 00:21:14.270 --> 00:21:16.070 and then it bounces back up to me. 00:21:16.070 --> 00:21:17.270 So how could I do that? 00:21:17.270 --> 00:21:19.070 What do I need to change? 00:21:19.070 --> 00:21:23.190 Well, this variable speed, that's controlling 00:21:23.190 --> 00:21:28.420 how many steps the ball is moving every time I run through this loop. 00:21:28.420 --> 00:21:32.760 And so when the speed is negative, that means the y value is going to decrease. 00:21:32.760 --> 00:21:36.270 Meaning we're going to be moving down on the stage. 00:21:36.270 --> 00:21:39.900 If I instead wanted the ball to start moving up once it reached the bottom, 00:21:39.900 --> 00:21:43.890 then I want the speed to not be negative, but to instead be positive. 00:21:43.890 --> 00:21:47.980 And how do I change the speed from a negative number into a positive number? 00:21:47.980 --> 00:21:51.000 Well, I can multiply the speed by negative 1. 00:21:51.000 --> 00:21:54.270 Then the speed will go from being negative moving down quickly to being 00:21:54.270 --> 00:21:57.180 a positive number moving up quickly. 00:21:57.180 --> 00:22:01.020 And so let's give that a try now as well. 00:22:01.020 --> 00:22:05.310 Once I'm touching the ground, rather than stopping everything, 00:22:05.310 --> 00:22:07.330 let's do something else. 00:22:07.330 --> 00:22:12.040 Let's set the speed to a particular value. 00:22:12.040 --> 00:22:15.640 And I want it to be the speed multiplied by negative 1. 00:22:15.640 --> 00:22:16.750 So going to operations. 00:22:16.750 --> 00:22:18.510 We'll do multiply. 00:22:18.510 --> 00:22:24.350 And we'll calculate what a speed times negative 1. 00:22:24.350 --> 00:22:28.970 And let's set the speed to that. 00:22:28.970 --> 00:22:34.365 So now every time we change the speed we check are we touching the ground. 00:22:34.365 --> 00:22:36.990 And if we are touching the ground, the speed's going to invert. 00:22:36.990 --> 00:22:41.135 Moving the opposite direction and start moving up now instead. 00:22:41.135 --> 00:22:44.650 So if I drag the ball up and let it go, watch what happens. 00:22:44.650 --> 00:22:47.490 It falls and then it bounces. 00:22:47.490 --> 00:22:48.750 And it bounces. 00:22:48.750 --> 00:22:51.900 And it keeps bouncing. 00:22:51.900 --> 00:22:54.990 And the reason that's happening is because it's getting negative speed 00:22:54.990 --> 00:22:56.280 as it's going down. 00:22:56.280 --> 00:22:59.410 And then as soon as it touches the ground, the speed becomes positive. 00:22:59.410 --> 00:23:02.040 And then it goes back up again. 00:23:02.040 --> 00:23:04.160 Now the one thing this isn't doing if we really 00:23:04.160 --> 00:23:06.035 wanted to make this even more realistic, just 00:23:06.035 --> 00:23:08.210 to add one final touch to this program, is 00:23:08.210 --> 00:23:11.250 that when I throw the ball on the ground, 00:23:11.250 --> 00:23:13.040 it doesn't come up to the same place. 00:23:13.040 --> 00:23:14.720 It's a little bit lower every time. 00:23:14.720 --> 00:23:16.797 Every time the ball bounces it starts high. 00:23:16.797 --> 00:23:19.380 Then it might be a little lower then a little lower than that. 00:23:19.380 --> 00:23:22.847 It loses a little bit of speed every time I bounce the ball. 00:23:22.847 --> 00:23:24.680 But this is the great thing about variables. 00:23:24.680 --> 00:23:27.320 I can set this variable to be whatever I want. 00:23:27.320 --> 00:23:30.060 And I can use these operators-- adding, and subtracting, 00:23:30.060 --> 00:23:34.070 and multiplying, and dividing to figure out exactly what I want for a variable 00:23:34.070 --> 00:23:34.740 to be. 00:23:34.740 --> 00:23:38.850 So maybe I want the speed to decrease by a little every time. 00:23:38.850 --> 00:23:43.790 Don't just make the speed positive, but subtract 1 or subtract 2 from the speed 00:23:43.790 --> 00:23:48.980 so that now it's moving a little more slowly every time the ball bounces. 00:23:48.980 --> 00:23:51.800 So I can go back into operators, and let's 00:23:51.800 --> 00:23:57.740 subtract 2 from whatever that new speed was supposed to be. 00:23:57.740 --> 00:23:58.790 We invert the speed. 00:23:58.790 --> 00:23:59.930 We subtract 2. 00:23:59.930 --> 00:24:04.670 And now it's going to go from a higher bounce to a lower bounce. 00:24:04.670 --> 00:24:08.210 And every time you'll notice that it decreases a little until it 00:24:08.210 --> 00:24:10.750 kind of gets stuck at the bottom there. 00:24:10.750 --> 00:24:11.750 But we can try it again. 00:24:15.130 --> 00:24:17.635 It's going lower and lower each time. 00:24:17.635 --> 00:24:19.510 And eventually, it's going to hit the bottom. 00:24:19.510 --> 00:24:21.820 And you might have to play around with it a little bit. 00:24:21.820 --> 00:24:23.710 Once it gets to a speed that's low enough, 00:24:23.710 --> 00:24:25.720 the ball should eventually just stop moving. 00:24:25.720 --> 00:24:29.770 But this is approximating that idea-- of a ball that's bouncing again and again. 00:24:29.770 --> 00:24:32.410 And we're able to use variables to control the speed 00:24:32.410 --> 00:24:36.990 to make this much more realistic. 00:24:36.990 --> 00:24:37.490 All right. 00:24:37.490 --> 00:24:38.948 What else can we do with variables? 00:24:38.948 --> 00:24:41.610 We'll take a look at a couple other final examples. 00:24:41.610 --> 00:24:45.740 One is we can let the user have control over the variable itself. 00:24:45.740 --> 00:24:46.700 What you'll notice-- 00:24:46.700 --> 00:24:49.220 I'll go ahead and get rid of the ball, and go back 00:24:49.220 --> 00:24:51.860 to the plain white backdrop. 00:24:51.860 --> 00:24:55.040 Let's go back to the balloon example that we've seen a couple of times 00:24:55.040 --> 00:24:56.840 now where the balloon was inflating. 00:24:56.840 --> 00:24:59.600 And it was inflating either when we blew at the microphone, 00:24:59.600 --> 00:25:04.410 or press the spacebar, or we just let it go automatically via a loop. 00:25:04.410 --> 00:25:08.840 Let's let the user now control how big or small the balloon should be. 00:25:08.840 --> 00:25:13.170 Let the user control how much air is inside of the balloon. 00:25:13.170 --> 00:25:17.240 Let's create a variable that I'm just going to call, air. 00:25:17.240 --> 00:25:20.510 And now what is this air variable going to do? 00:25:20.510 --> 00:25:25.010 Well, if I Control click on this area here where 00:25:25.010 --> 00:25:27.410 I can see what the value of a variable is, 00:25:27.410 --> 00:25:30.170 I can change what the readout looks like. 00:25:30.170 --> 00:25:31.520 This is a normal readout. 00:25:31.520 --> 00:25:34.100 If I change it to a large readout, you just 00:25:34.100 --> 00:25:36.110 see the number a little bit bigger. 00:25:36.110 --> 00:25:38.420 But I can also change it to a slider. 00:25:38.420 --> 00:25:41.510 And when it's a slider, the user of the program 00:25:41.510 --> 00:25:45.350 can just move the slider to control what the value of the variable 00:25:45.350 --> 00:25:46.310 is going to be. 00:25:46.310 --> 00:25:50.580 I can change air to be 0 all the way up to 100 for example. 00:25:50.580 --> 00:25:55.310 And that lets the user have some control over the variables in the program. 00:25:55.310 --> 00:25:57.440 And how big was this balloon before? 00:25:57.440 --> 00:26:01.790 Well, usually, it was somewhere between like size 100 and 200. 00:26:01.790 --> 00:26:04.550 So let me edit the slider range. 00:26:04.550 --> 00:26:06.590 Set the minimum value to 100. 00:26:06.590 --> 00:26:08.310 And the maximum value to 200. 00:26:08.310 --> 00:26:11.210 I did that by Control clicking on the slider. 00:26:11.210 --> 00:26:15.050 And then changing the slider range to now range between 100 00:26:15.050 --> 00:26:18.560 at a minimum and 200 at a maximum. 00:26:18.560 --> 00:26:21.570 So I can go back and forth between those two values. 00:26:21.570 --> 00:26:24.140 And now what do I want the balloon to do? 00:26:24.140 --> 00:26:27.590 Well, when the flag is clicked, we'll just 00:26:27.590 --> 00:26:36.290 add a few blocks that say forever I want the balloon to set it size not to 100%, 00:26:36.290 --> 00:26:38.720 but to air percent. 00:26:38.720 --> 00:26:42.980 Whatever the value of the air variable is. 00:26:42.980 --> 00:26:45.860 That is what I want the size of the balloon to be. 00:26:45.860 --> 00:26:47.990 I press the flag to start the program. 00:26:47.990 --> 00:26:50.330 And so now this balloon is constantly going 00:26:50.330 --> 00:26:53.150 to be checking what is the value of the air variable. 00:26:53.150 --> 00:26:55.570 And depending upon the value of the air variable, 00:26:55.570 --> 00:26:57.320 that's how big the balloon is going to be. 00:26:57.320 --> 00:27:00.170 So I can now just drag along the slider. 00:27:00.170 --> 00:27:03.680 And as I drag along the slider, you'll see the balloon grow and shrink. 00:27:03.680 --> 00:27:06.170 I'm changing the value of the air variable, 00:27:06.170 --> 00:27:10.010 and constantly forever the balloon is updating its size 00:27:10.010 --> 00:27:13.700 to be whatever the value of that variable should be. 00:27:13.700 --> 00:27:17.450 And so variables don't just have to be set by these like set variable to, 00:27:17.450 --> 00:27:19.790 or change variable by values. 00:27:19.790 --> 00:27:22.790 You can also just let the user control a variable directly 00:27:22.790 --> 00:27:25.410 to let them interact with your Scratch project. 00:27:25.410 --> 00:27:30.110 Let them decide how things should behave or what a particular sprite should 00:27:30.110 --> 00:27:32.760 look like for example. 00:27:32.760 --> 00:27:35.090 And let's do one final example with variables. 00:27:35.090 --> 00:27:39.050 This time taking advantage of the Pen tool to draw some shapes. 00:27:39.050 --> 00:27:41.210 And so I'll bring back the cat. 00:27:44.540 --> 00:27:46.100 Here's our cat again. 00:27:46.100 --> 00:27:50.120 And you might recall from before that we could get the cat to move in a circle 00:27:50.120 --> 00:27:55.170 by doing something like when the green flag is clicked, then 00:27:55.170 --> 00:28:01.350 forever have the cat move a certain number of steps 00:28:01.350 --> 00:28:04.030 and then turn a certain number of degrees. 00:28:04.030 --> 00:28:06.630 And that had the effect of moving the cat in a circle 00:28:06.630 --> 00:28:11.810 over and over just by moving, and then turning a little bit every time. 00:28:11.810 --> 00:28:15.770 And if we wanted to draw that, we could use the Pen tool to try and draw that. 00:28:15.770 --> 00:28:18.580 I'll have the Scratch cat start in a particular place 00:28:18.580 --> 00:28:19.960 when the green flag is clicked. 00:28:19.960 --> 00:28:22.210 Let's go ahead and go to 0, 0. 00:28:22.210 --> 00:28:25.405 And be sure you're pointing 90 degrees-- meaning to the right. 00:28:25.405 --> 00:28:28.030 And that's going to start the Scratch cut off in the same place 00:28:28.030 --> 00:28:32.060 every time so we get a consistent circle. 00:28:32.060 --> 00:28:35.900 But what I can do is add the pen extension, which we've seen before, 00:28:35.900 --> 00:28:38.140 to do a little bit of drawing. 00:28:38.140 --> 00:28:41.250 We're going to erase everything. 00:28:41.250 --> 00:28:47.360 And then put the pen down to let the cat start drawing. 00:28:47.360 --> 00:28:50.730 And now what you're noticing is the cat's moving in a circle. 00:28:50.730 --> 00:28:53.120 And as it moves in that circle, it's drawing. 00:28:53.120 --> 00:28:56.680 It's using the pen to draw the circle that it's moving in. 00:28:56.680 --> 00:28:59.210 And if I want to make the cat move a little bit more slowly, 00:28:59.210 --> 00:29:01.040 I might have the cat wait a little bit. 00:29:01.040 --> 00:29:02.998 Let's just have it wait a fraction of a second. 00:29:02.998 --> 00:29:04.940 Maybe 0.05 seconds. 00:29:04.940 --> 00:29:07.880 And now the cat's moving a little more slowly. 00:29:07.880 --> 00:29:13.073 And you can actually see it drawing that circle just by drawing it like that. 00:29:13.073 --> 00:29:14.990 But we're not really using any variables here. 00:29:14.990 --> 00:29:17.690 The reason why variables can be helpful is because we 00:29:17.690 --> 00:29:19.520 can change the cat's behavior. 00:29:19.520 --> 00:29:22.460 Maybe not have it move by 10 steps every time. 00:29:22.460 --> 00:29:26.120 But have it move by a different number of steps every time. 00:29:26.120 --> 00:29:28.200 So I'll create a new variable. 00:29:28.200 --> 00:29:30.420 I'll call it steps. 00:29:30.420 --> 00:29:35.310 And we'll start by setting steps equal to 0. 00:29:35.310 --> 00:29:39.880 And instead of moving 10 steps, let's move steps steps. 00:29:39.880 --> 00:29:43.560 Whatever the value of that variable is, that's how far I would like to move. 00:29:43.560 --> 00:29:47.400 But then every time you move, we're going to change the number of steps 00:29:47.400 --> 00:29:50.190 by something like 0.5. 00:29:50.190 --> 00:29:53.740 A small number just to make a very small change. 00:29:53.740 --> 00:29:56.190 So what's going on now with all of these blocks? 00:29:56.190 --> 00:29:57.390 We'll try and recap. 00:29:57.390 --> 00:29:59.753 At the very beginning, when we first start the program, 00:29:59.753 --> 00:30:01.170 we're doing a little bit of setup. 00:30:01.170 --> 00:30:03.210 We're saying have the cat go back to 0, 0. 00:30:03.210 --> 00:30:04.920 Just to the center of the stage. 00:30:04.920 --> 00:30:06.300 Have it point in 90 degrees. 00:30:06.300 --> 00:30:07.620 Meaning point to the right. 00:30:07.620 --> 00:30:09.125 And erase everything. 00:30:09.125 --> 00:30:11.250 So if there were already things drawn on the stage, 00:30:11.250 --> 00:30:13.650 just erase them so that we can start fresh. 00:30:13.650 --> 00:30:15.690 And now put the pen down. 00:30:15.690 --> 00:30:18.960 Meaning wherever the Scratch cat moves, the pen is going to follow. 00:30:18.960 --> 00:30:21.210 And it's going to trace those shapes. 00:30:21.210 --> 00:30:24.030 And we have a variable keeping track of how far 00:30:24.030 --> 00:30:26.790 the cat's going to move every time. 00:30:26.790 --> 00:30:28.470 Right now, it's starts at 0. 00:30:28.470 --> 00:30:30.120 So we move that number of steps. 00:30:30.120 --> 00:30:33.420 But over time, we're going to increase the number of steps the cats moving. 00:30:33.420 --> 00:30:36.220 Increase it by a little bit, and then rotate. 00:30:36.220 --> 00:30:39.702 And if we keep increasing how much the cat's moving and then rotating, 00:30:39.702 --> 00:30:41.910 what you're going to see is a more interesting shape. 00:30:41.910 --> 00:30:44.730 It's not going to draw a perfect circle. 00:30:44.730 --> 00:30:49.485 But it's instead going to draw something like this spiral. 00:30:49.485 --> 00:30:52.410 Notice it's moving by more and more every time. 00:30:52.410 --> 00:30:54.750 And as it moves more and more with the pen down, 00:30:54.750 --> 00:30:58.380 we're able to see this interesting spiral result from it. 00:30:58.380 --> 00:31:01.050 Because it started by moving very little every single time. 00:31:01.050 --> 00:31:02.910 Just moving by a few steps. 00:31:02.910 --> 00:31:06.300 And over time it's moving more, and more, and more every time it rotates. 00:31:06.300 --> 00:31:09.932 And that's creating the shape that you're able to see here. 00:31:09.932 --> 00:31:12.390 And so by taking advantage of the pen, and taking advantage 00:31:12.390 --> 00:31:14.580 of variables and loops, you're able to create 00:31:14.580 --> 00:31:16.200 some really interesting works of art. 00:31:16.200 --> 00:31:19.530 Shapes that can be drawn just by sprites on the stage 00:31:19.530 --> 00:31:22.020 by calculating, by modifying some variables 00:31:22.020 --> 00:31:25.650 and adjusting what those variables should do in order to create 00:31:25.650 --> 00:31:27.880 more and more interesting programs. 00:31:27.880 --> 00:31:30.330 And you can see up here in the upper left 00:31:30.330 --> 00:31:34.350 this keeping track of how many steps it is that we've 00:31:34.350 --> 00:31:37.750 taken so far inside of this program. 00:31:37.750 --> 00:31:40.380 So variables add a lot of power to the programs 00:31:40.380 --> 00:31:42.330 that we can create inside of Scratch. 00:31:42.330 --> 00:31:45.480 They give us the ability to keep track of whatever information we want. 00:31:45.480 --> 00:31:48.870 And then to use that information later on in our programs 00:31:48.870 --> 00:31:52.830 to create even more exciting games, and animations, and stories 00:31:52.830 --> 00:31:55.590 all just through the use of the Scratch box. 00:31:55.590 --> 00:31:58.660 That's it for an Introduction to Programming with Scratch for today. 00:31:58.660 --> 00:32:00.680 We'll see you next time.