[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.88,0:00:06.00,Default,,0000,0000,0000,,We're back to our Winston drawing program,\Nbut I've added some text to it. Dialogue: 0,0:00:06.00,0:00:11.07,Default,,0000,0000,0000,,See, what I wanna do is position a Winston\Nunderneath each of these labels, Dialogue: 0,0:00:11.07,0:00:13.21,Default,,0000,0000,0000,,to show him at each point in life. Dialogue: 0,0:00:13.21,0:00:16.44,Default,,0000,0000,0000,,Right now he's all over the place.\NThat's because we are setting the Dialogue: 0,0:00:16.44,0:00:20.45,Default,,0000,0000,0000,,faceX and the faceY to \Nrandom numbers inside the function. Dialogue: 0,0:00:20.45,0:00:26.71,Default,,0000,0000,0000,,What we wanna say is, "Here's the exact \Nposition I want you to draw this Winston" Dialogue: 0,0:00:26.71,0:00:30.32,Default,,0000,0000,0000,,I wanna be able to specify that position \Nevery time I call the function, \N Dialogue: 0,0:00:30.32,0:00:32.65,Default,,0000,0000,0000,,the same way we do with ellipse() and rect(). Dialogue: 0,0:00:34.05,0:00:40.46,Default,,0000,0000,0000,,I wanna put a Winston here,here, \Nand a Winston here, and a Winston here, Dialogue: 0,0:00:40.46,0:00:43.62,Default,,0000,0000,0000,,and I don't want just random places\Nevery time I call the function. Dialogue: 0,0:00:43.62,0:00:48.88,Default,,0000,0000,0000,,In order to do that, we have to specify \N"parameters" for the function, Dialogue: 0,0:00:48.88,0:00:52.81,Default,,0000,0000,0000,,both in our function definition\N-- at the top here -- Dialogue: 0,0:00:52.81,0:00:57.30,Default,,0000,0000,0000,,and in our function call, down here,\Nwhen we actually call it. Dialogue: 0,0:00:57.30,0:01:02.21,Default,,0000,0000,0000,,For drawWinston(), \Nwe pass it faceX and faceY, Dialogue: 0,0:01:02.21,0:01:09.06,Default,,0000,0000,0000,,and have it use those values that we pass\Nin instead of generating them randomly. Dialogue: 0,0:01:09.06,0:01:14.66,Default,,0000,0000,0000,,Let's by thinking about what we'd \Npass into these function calls down here. Dialogue: 0,0:01:14.66,0:01:20.07,Default,,0000,0000,0000,,We position the Winstons under each text, \Nso we'd probably want the x and y of each Dialogue: 0,0:01:20.07,0:01:24.49,Default,,0000,0000,0000,,Winston to be similar to the numbers \Nwe passed into the text() functions. Dialogue: 0,0:01:24.49,0:01:32.17,Default,,0000,0000,0000,,Maybe,10 pixels lower in the y. \NThe first one would be 10 and 30, Dialogue: 0,0:01:32.17,0:01:40.89,Default,,0000,0000,0000,,and then maybe 200, 230...\N10, 230... 200, 230. Dialogue: 0,0:01:40.89,0:01:44.86,Default,,0000,0000,0000,,It's the same as the text coordinates,\NI'm just adding 10 to each y, ' Dialogue: 0,0:01:44.86,0:01:47.40,Default,,0000,0000,0000,,cause I want it just a little bit lower. Dialogue: 0,0:01:49.98,0:01:55.30,Default,,0000,0000,0000,,Winston hasn't moved. \NWe haven't told our function up here that Dialogue: 0,0:01:55.30,0:01:59.18,Default,,0000,0000,0000,,we're passing it parameters,\Nso it's still using these random values. Dialogue: 0,0:01:59.18,0:02:03.60,Default,,0000,0000,0000,,In order to tell this function,"We're \Ngonna give you this information instead," Dialogue: 0,0:02:03.60,0:02:08.40,Default,,0000,0000,0000,,we have to give the parameters\Nnames inside these parentheses. Dialogue: 0,0:02:08.40,0:02:14.11,Default,,0000,0000,0000,,We'll call it faceX and faceY,\Nseparate them by a comma, Dialogue: 0,0:02:14.11,0:02:20.70,Default,,0000,0000,0000,,We're calling it that since we're using \Nit to refer to them inside the function Dialogue: 0,0:02:20.70,0:02:23.47,Default,,0000,0000,0000,,That way we don't have to \Nrewrite the rest of our code. Dialogue: 0,0:02:23.47,0:02:28.81,Default,,0000,0000,0000,,But still, nothing has happened; \NWinston is still all over the place. Dialogue: 0,0:02:28.81,0:02:31.35,Default,,0000,0000,0000,,If you look at the very top \Nof our function, Dialogue: 0,0:02:31.35,0:02:35.26,Default,,0000,0000,0000,,we're overwriting faceX and faceY \Nwith random values, still. Dialogue: 0,0:02:35.26,0:02:38.79,Default,,0000,0000,0000,,So, all we have to do\Nis delete these lines... Dialogue: 0,0:02:38.79,0:02:45.46,Default,,0000,0000,0000,,Now, faceX and faceY are getting\Npassed into the function, Dialogue: 0,0:02:45.46,0:02:49.58,Default,,0000,0000,0000,,and it's using the values \Nthat we're calling it with here. Dialogue: 0,0:02:49.58,0:02:55.31,Default,,0000,0000,0000,,I didn't quite position Winston correctly,\Nbecause I forgot that text gets positioned Dialogue: 0,0:02:55.31,0:03:01.04,Default,,0000,0000,0000,,according to the upper left,and the face \Ngets positioned according to the center. Dialogue: 0,0:03:01.04,0:03:06.38,Default,,0000,0000,0000,,I need to go and tinker with my \Nnumbers a little bit here, right? Dialogue: 0,0:03:06.38,0:03:12.61,Default,,0000,0000,0000,,I need to move the x over a lot, and move \Nthis over, okay... so that's our toddler.. Dialogue: 0,0:03:12.61,0:03:18.03,Default,,0000,0000,0000,,We'll go through, and change \Nwhat I'm passing into the function,\N Dialogue: 0,0:03:18.03,0:03:22.52,Default,,0000,0000,0000,,I don't have to change \Nthe function definition at all, Dialogue: 0,0:03:22.52,0:03:25.76,Default,,0000,0000,0000,,It's always gonna take \Nwhatever values we pass in. Dialogue: 0,0:03:25.76,0:03:28.39,Default,,0000,0000,0000,,Just like with ellipse() and rect(). Dialogue: 0,0:03:28.39,0:03:33.35,Default,,0000,0000,0000,,I've positioned it, but\NI've noticed is that Winston is too big. Dialogue: 0,0:03:33.35,0:03:35.76,Default,,0000,0000,0000,,He's overlapping, he doesn't fit. Dialogue: 0,0:03:35.76,0:03:39.02,Default,,0000,0000,0000,,I've put the code to \Ndraw him in a function, Dialogue: 0,0:03:39.02,0:03:42.37,Default,,0000,0000,0000,,I can change the size \Nof all of them at once Dialogue: 0,0:03:42.37,0:03:45.44,Default,,0000,0000,0000,,by changing one line \Nof code that draws the ellipse. Dialogue: 0,0:03:45.44,0:03:50.63,Default,,0000,0000,0000,,If we make him like 190, \NWinston's going on a diet, by 190. Dialogue: 0,0:03:50.63,0:03:55.96,Default,,0000,0000,0000,,Now he's gonna fit better and \Nthen ya know I could keep tweaking Dialogue: 0,0:03:55.96,0:04:01.90,Default,,0000,0000,0000,,so I could actually get him\Ninside there, right? Cool. Dialogue: 0,0:04:01.90,0:04:08.53,Default,,0000,0000,0000,,Let's do a review of what this code does.\NIt defines a function called drawWinston() Dialogue: 0,0:04:08.53,0:04:14.67,Default,,0000,0000,0000,,and says this function takes two values, \Nand it labels them faceX and faceY, Dialogue: 0,0:04:14.67,0:04:19.95,Default,,0000,0000,0000,,these values come in as variables that\Nwe can use anywhere inside our function, Dialogue: 0,0:04:19.95,0:04:23.06,Default,,0000,0000,0000,,just like we used to use the variables \Nthat we declared at the top Dialogue: 0,0:04:23.06,0:04:29.11,Default,,0000,0000,0000,,And then we can call this function \Nwhenever we want after we declare it, Dialogue: 0,0:04:29.11,0:04:33.71,Default,,0000,0000,0000,,we can pass in different values, \Nso it'll use those new values each time. Dialogue: 0,0:04:33.71,0:04:38.11,Default,,0000,0000,0000,,You've seen what's cool about functions. \NWe can come up with code that Dialogue: 0,0:04:38.11,0:04:42.51,Default,,0000,0000,0000,,we think would be really useful to reuse,\Nbut we can also use parameters to say Dialogue: 0,0:04:42.51,0:04:46.46,Default,,0000,0000,0000,,"Hey, here's a little something you can \Nchange about this code, to customize it." Dialogue: 0,0:04:46.46,0:04:49.40,Default,,0000,0000,0000,,It's like a recipe. \NYou write down the general instructions, Dialogue: 0,0:04:49.40,0:04:52.81,Default,,0000,0000,0000,,and if you realize you suddenly \Nneed to feed 4 Winstons instead of 1, Dialogue: 0,0:04:52.81,0:04:55.94,Default,,0000,0000,0000,,you don't have to start all over, \Nyou just modify the original instructions Dialogue: 0,0:04:55.94,0:04:57.63,Default,,0000,0000,0000,,and multiply everything by 4. Dialogue: 0,0:04:57.63,0:05:02.20,Default,,0000,0000,0000,,Now you can start thinking about the\Nrecipes in your code! Yummy.