Return to Video

IntroToDrawingFixed

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

more » « less
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
Show all

English subtitles

Revisions