IntroToDrawingFixed
-
0:01 - 0:03Let's start programming.
-
0:03 - 0:05We need to begin
with understanding shapes, the basics. -
0:05 - 0:06But don't worry, soon enough,
-
0:06 - 0:08your shapes will be
flying around the screen, -
0:08 - 0:11and changing colors, and all kinds
of other cool programming things. -
0:11 - 0:13Just stay with us!
-
0:13 - 0:15So let's start with drawing rectangles.
-
0:15 - 0:17We type rect for rectangle,
-
0:17 - 0:19then (, and then four numbers
10, 20, 100, 200-- -
0:19 - 0:21and I'll explain what these mean
in a moment-- -
0:21 - 0:24then ), and at the end,
we'll just put a ; -
0:24 - 0:26Look, amazing, a rectangle!
-
0:26 - 0:28And that was so neat,
so let's do that again. -
0:28 - 0:30We can try different numbers this time.
-
0:30 - 0:32Maybe bigger numbers,
(300, 240 -
0:32 - 0:34and then smaller numbers at the end,
10, 20) -
0:34 - 0:36and hey look, another rectangle!
-
0:36 - 0:39In fact, if we try changing
this first number to make it smaller, -
0:39 - 0:41it'll start moving.
-
0:41 - 0:44If we change this last number
to make it bigger and then smaller, -
0:44 - 0:46then it's just going to grow
and then shrink. -
0:46 - 0:48Interesting!
-
0:48 - 0:51So, how is all this magic happening,
you might wonder? -
0:51 - 0:53Well, remember that your computer
-
0:53 - 0:56is just like a really intelligent
and obedient dog. -
0:56 - 1:00With a dog, maybe we could tell it
to sit, stay, even roll over. -
1:00 - 1:02You would just have to give the command.
-
1:02 - 1:05So in code, how would you tell
your computer dog to sit? -
1:06 - 1:08Well, the way you would do that
-
1:08 - 1:11is you would write
the command name, say sit, -
1:11 - 1:13and then you would put
( ) afterwards -
1:13 - 1:15to tell it to go do that command
you just said, -
1:15 - 1:18and then you put a ;
at the end just to say, -
1:18 - 1:20"Yeah, this command is over."
-
1:20 - 1:22Then your computer dog would sit down.
-
1:22 - 1:25Well of course, your computer
on Khan Academy isn't a dog, -
1:25 - 1:27so it doesn't know how
to sit or roll over, -
1:27 - 1:30but it does know how to draw rectangles
when you tell it rect, -
1:30 - 1:32and that's kind of neat too, right?
-
1:32 - 1:34So, that's what
we're going to do on this line. -
1:34 - 1:37We'll say the command rect,
which is just the name, -
1:37 - 1:40and then we'll put the ( and the )
-
1:40 - 1:41to say "go do that",
-
1:41 - 1:43and then we'll put the ; at the end.
-
1:44 - 1:47That's how your computer knows
to go do this special ability, rect. -
1:47 - 1:50Okay, so now let's go back to our rect.
-
1:50 - 1:54We have the command name right here
and we have those parentheses. -
1:54 - 1:56But what about all these crazy numbers?
-
1:56 - 2:00Well, the idea is that the computer
really doesn't know enough -
2:00 - 2:01if you just tell it rect.
-
2:02 - 2:05To see this, imagine if I gave you
a piece of paper, -
2:05 - 2:07and I said I wanted you
to draw a rectangle -
2:07 - 2:09exactly the way I wanted it to be.
-
2:10 - 2:11Unless you can read my mind,
-
2:11 - 2:13you're going to have
some questions right away. -
2:15 - 2:16First, you might wonder,
-
2:16 - 2:19"Where do you want me
to draw the rectangle?" -
2:19 - 2:21And then, what I would say is,
-
2:21 - 2:23"How about we just agree
-
2:23 - 2:26that this left side of the paper
that I just gave you, -
2:26 - 2:27let's just call that zero.
-
2:27 - 2:30And let's just agree that this right side
is going to be 400." -
2:30 - 2:33Then I could give you a number,
say like 100, -
2:33 - 2:36and you would know that that's
going to be right about there, maybe, -
2:36 - 2:37roughly.
-
2:37 - 2:40Except that will satisfy you for a moment,
but then you'd think, -
2:40 - 2:43"Okay, that tells me how far across,
but how about how far up and down?" -
2:44 - 2:47Then I could give you another number,
let's say maybe 200, -
2:47 - 2:50and I would say,
"This is the top, this is 0, -
2:50 - 2:53and again we'll just say that the bottom,
that's going to be 400." -
2:53 - 2:54And you would think,
-
2:54 - 2:57"200, that's going to be
right in the middle here." -
2:57 - 3:00And that's perfect,
because now you think, and you say, -
3:00 - 3:03"Okay great, I'm going to draw
your rectangle right here -
3:03 - 3:06because it's 100 across,
and it's 200 down." -
3:06 - 3:09Except that's still not enough,
because now what are you asking? -
3:09 - 3:12Right, you're wondering,
"How big do you want the rectangle?" -
3:12 - 3:17And I would say,
"How about like, 150 wide?" -
3:17 - 3:21And you'd think,
"Well, this is 100, and this is 400, -
3:21 - 3:25so if we want it to be 150 wide,
maybe we're gonna go to here?" -
3:26 - 3:29And you think,
"Okay, cool, 150 wide, about." -
3:29 - 3:31Then you'd say,
"How tall do you want it?" -
3:31 - 3:33I would say, "Not very tall.
How about 50 tall?" -
3:34 - 3:37You'll say, "Okay, well 50,
maybe that's going to be about that tall?" -
3:38 - 3:39Then you would say, "Awesome!
-
3:39 - 3:41I know exactly where you want
your rectangle, -
3:41 - 3:42exactly what it should look like.
-
3:42 - 3:44I'll go ahead and draw it."
-
3:45 - 3:48That's a lot of work
for a rectangle, isn't it? -
3:48 - 3:50But the idea is just by giving you
those four numbers-- -
3:50 - 3:54remember we said 100 across, 200 down,
-
3:54 - 3:58150 wide, and then just 50 tall--
-
3:58 - 4:00we now are exactly on the same page
-
4:00 - 4:02about what this rectangle
should look like. -
4:02 - 4:04That's how the computer works too.
-
4:04 - 4:07You can just write the command name
like we said earlier, -
4:07 - 4:10write the ( and then
add in these four numbers, -
4:10 - 4:14100, 200, 150, and then 50,
-
4:14 - 4:16) and then a ;
-
4:16 - 4:19And it will draw a rectangle
exactly where we wanted it to be. -
4:21 - 4:22I guess if we're honest with ourselves,
-
4:22 - 4:24that's not really where
we wanted the rectangle. -
4:24 - 4:26It's not where we drew it, right?
-
4:26 - 4:27So our numbers are a little bit off.
-
4:27 - 4:31Let's go ahead and say we want it
to really match exactly what we drew. -
4:31 - 4:34We'll move this
so it's a little bit further over, -
4:34 - 4:37a little bit less up and down,
-
4:38 - 4:42a little bit skinnier,
and maybe a tiny bit less tall. -
4:43 - 4:46Now we have it that our rectangle
pretty much exactly matches what we drew, -
4:46 - 4:49because we understood
what each of these numbers meant, -
4:49 - 4:52and we could change it
so it looks like we want it to. -
4:53 - 4:55Now let's think about drawing
another rectangle. -
4:55 - 4:56Because the beauty of this is,
-
4:56 - 4:59we can draw rectangles
wherever we want now. -
5:00 - 5:02How about we draw it
all the way in this upper corner, -
5:02 - 5:03all the way up there?
-
5:04 - 5:06Let's think of where that would be.
-
5:06 - 5:10I guess that would be like 0 across,
0 up and down, -
5:10 - 5:13and maybe pretty small,
let's say just 50 wide -
5:13 - 5:16and maybe just 10 tall,
like a pretty small rectangle. -
5:17 - 5:18We can go ahead and do that.
-
5:18 - 5:19We'll type rect,
-
5:19 - 5:22and then separating
these parameters with , , , -
5:23 - 5:26we'll go ahead and say,
"Alright, cool". -
5:26 - 5:29Well, not so cool because we have
this error message that's saying, -
5:29 - 5:31"Oh no!
It looks like you're missing a )" -
5:31 - 5:33And we say, "Oh yeah, we are."
-
5:33 - 5:35So phew, we'll put it back in.
It looks great, right? -
5:35 - 5:37Well, not so great because now
we have another message -
5:37 - 5:38saying we have a missing semicolon.
-
5:38 - 5:41This one is also correct;
we could just press "Show Me Where" -
5:41 - 5:43and it would point
to the line we just wrote. -
5:43 - 5:44And we just remember,
-
5:44 - 5:46"Oh yeah, semicolons are like periods
at the ends of the sentences -
5:46 - 5:49to end our lines, and we forgot one!"
-
5:49 - 5:52But we can just put it back, no big deal,
and everything is good again. -
5:52 - 5:55Check it out, a tiny little rectangle,
exactly like we wanted. -
5:56 - 5:58Just like before, we can grow it
so that it's bigger, -
5:59 - 6:00we can move it around,
-
6:01 - 6:03and we can position it
exactly where we want it to be. -
6:03 - 6:06So now you know in detail
exactly how this rect thing works. -
6:07 - 6:09We covered what these numbers mean,
-
6:09 - 6:12and how you always need to put
the command name, the parentheses, -
6:12 - 6:15have a comma separate the numbers,
and put the semicolon at the end. -
6:15 - 6:16It seems like a lot,
-
6:16 - 6:19but you can go ahead and try it
for yourself and get a feel for it. -
6:19 - 6:21Next time, we'll learn about
making more shapes, -
6:21 - 6:23and then we'll move on to awesome things
-
6:23 - 6:26like making them colorful
and having them fly around the screen.
- Title:
- IntroToDrawingFixed
- Description:
-
This is just a screen grab of our interactive coding talk-through, prepared to make captioning and translation easier. It is better to watch our talk-throughs here:
https://www.khanacademy.org/cs/programming/ - Video Language:
- English
- Duration:
- 06:27
April Porter edited English subtitles for IntroToDrawingFixed | ||
April Porter edited English subtitles for IntroToDrawingFixed | ||
Mary Beth Strawn edited English subtitles for IntroToDrawingFixed | ||
Mary Beth Strawn edited English subtitles for IntroToDrawingFixed | ||
Mary Beth Strawn edited English subtitles for IntroToDrawingFixed | ||
Mary Beth Strawn edited English subtitles for IntroToDrawingFixed | ||
pamela-from-khan edited English subtitles for IntroToDrawingFixed | ||
pamela-from-khan edited English subtitles for IntroToDrawingFixed |