< Return to Video

3. COLOR

  • 0:01 - 0:06
    Hi! Welcome back! You came back, which I'm very thankful for — thank you very much.
  • 0:06 - 0:10
    So, hopefully you enjoyed the last exercise you did, and your code is still sitting down there.
  • 0:10 - 0:14
    Now, by the way, during this section of the tutorial, I am going to start doing stuff,
  • 0:14 - 0:16
    and the code that you wrote is going to disappear.
  • 0:16 - 0:18
    But don't worry; there's going to be an option for you to restore it again later.
  • 0:19 - 0:23
    OK, so what are we missing? We've got shapes: we've got circles, we've got rectangles.
  • 0:23 - 0:27
    But obviously we're missing something really important in terms of art and design.
  • 0:27 - 0:28
    We're missing color.
  • 0:28 - 0:30
    So let's think about that rectangle again.
  • 0:30 - 0:32
    We have this rectangle.
  • 0:34 - 0:35
    We have this circle.
  • 0:36 - 0:43
    What do these shapes have? They have both an outline, which is tracing this rectangle,
  • 0:43 - 0:49
    which we're going to call — sorry — the "stroke." We also have the interior of the shape,
  • 0:49 - 0:52
    the interior of the shape which we're going to call the "fill."
  • 0:52 - 0:56
    So we have two colors that we have to set for every shape.
  • 0:56 - 1:00
    We have the stroke, which is the outline, and we have the fill, which is the interior.
  • 1:00 - 1:03
    And just like we learnd these function calls, these commands —
  • 1:03 - 1:09
    "rect" for rectangle, "ellipse" for ellipse — we're going to have functions for stroke and fill.
  • 1:09 - 1:10
    So it's going to look like this.
  • 1:10 - 1:16
    Let's say we're drawing a rectangle, and that rectangle is being drawn at some location.
  • 1:16 - 1:19
    Uh, I think this is something we had previously.
  • 1:19 - 1:30
    What we need to do now, before we say "rectangle" is we need to say "stroke" and we need to say "fill."
  • 1:33 - 1:36
    Every single time that we draw a shape, if we want to color it,
  • 1:36 - 1:39
    we need to set the stroke and fill before we call that shape function.
  • 1:40 - 1:42
    This is, again, a moment when order of operations matter.
  • 1:42 - 1:46
    We don't say, "draw a rectangle — hey it's blue, and it's red on the outside."
  • 1:46 - 1:48
    We say, "set a pen color..." (in a way it's like a pen)....
  • 1:48 - 1:52
    "Go and find my red pen and go and find my blue marker.
  • 1:53 - 1:57
    You use the red pen for the outside and the blue marker for the inside" when I draw that rectangle.
  • 1:57 - 2:01
    But there's a big question here, right? We know that when we draw a rectangle we give it an x, a y,
  • 2:01 - 2:05
    a width, and height: those are the values that define what it is to be a rectangle.
  • 2:06 - 2:10
    What values do we give a stroke or a fill? How do we tie numbers to color?
  • 2:10 - 2:15
    Let's say we have the number 0, and we say the number 0 means black.
  • 2:16 - 2:22
    And let's say we have the number 255, and the number 255 means white.
  • 2:22 - 2:26
    So any value in between, any value in between is some gray.
  • 2:27 - 2:31
    127 would be, like, half the way between white and black.
  • 2:31 - 2:34
    253 would be really white, but not all the way white.
  • 2:34 - 2:38
    Right? So can really imagine this and obviously just trying out these numbers would make much more sense.
  • 2:38 - 2:44
    So we could say something like "stroke (0)" and we would have a black outline.
  • 2:44 - 2:46
    Let's actually bring up the code editor below,
  • 2:46 - 2:52
    and let's add a stroke (0) and a fill for one of our shapes down there, for the rectangle below.
  • 2:52 - 3:00
    OK, see how the stroke and fill are placed before we call rect, and that they are setting the colors that you're seeing in the canvas on the left.
  • 3:00 - 3:01
    Great.
  • 3:01 - 3:04
    So, I want to move on quickly though, however, to … even though this is nice,
  • 3:04 - 3:08
    and we can see that we can do grayscale colors, really,
  • 3:08 - 3:11
    what you probably want to do is make all sorts of … you know, what's your favorite color?
  • 3:11 - 3:15
    Pink? Purple? Green? Blue? You want to make "color" color, how do we do that?
  • 3:15 - 3:21
    So, with one number — if we put one number here in stroke, we have a grayscale color,
  • 3:21 - 3:28
    but if we put three numbers in, like if I put numbers like this (255, 0, 0),
  • 3:28 - 3:32
    what we now have done is we've created an RGB color.
  • 3:32 - 3:40
    RGB: we have a little bit of red, we have some amount of green, and we have some amount of blue.
  • 3:40 - 3:43
    The arguments are red, green, and blue.
  • 3:43 - 3:46
    And it has the same … it follows the same scale as grayscale.
  • 3:46 - 3:53
    In the case of red, 255 is all the red you could imagine; 0 is no red.
  • 3:53 - 3:54
    So it's like mixing colors.
  • 3:54 - 3:57
    I mean, it's something you might have done, um, you know, fingerpainting, or mixing colors,
  • 3:57 - 4:00
    and you get a little red, you get a little blue, and you put them together,
  • 4:00 - 4:03
    and I think maybe you get purple, something like that.
  • 4:03 - 4:05
    Um, this same principle is happening here.
  • 4:05 - 4:09
    You're adding a variable amount of red, a variable amount of blue and mixing colors.
  • 4:09 - 4:12
    The thing that you should realize, though, is it's not like mixing paints,
  • 4:12 - 4:16
    that what color actually does on the computer is really like mixing light.
  • 4:16 - 4:20
    It's more like imagining that you had three flashlights — a red flashlight, a green flashlight,
  • 4:20 - 4:25
    and a blue flashlight — and you could turn them up or down and shine them on the same point.
  • 4:25 - 4:30
    So let's switch over again and open up the code editor below, and let's add a stroke and a fill.
  • 4:30 - 4:33
    The stroke and the fill are still there from rectangle.
  • 4:33 - 4:39
    Let's make the stroke red, which would be all red, (255, 0, 0),
  • 4:39 - 4:44
    and let's make a fill that's all blue, (0, 0, 255).
  • 4:44 - 4:47
    Let's run that, and now we see a red outline with a blue interior.
  • 4:48 - 4:52
    You probably want lots of other colors, and it might be hard to figure out what color do I want?
  • 4:52 - 4:57
    Well, if you notice, if you click on fill, and I'm going to do this for you, a wheel (a color picker)
  • 4:57 - 5:01
    pops up where you could move the mouse around and you can select the color you want,
  • 5:01 - 5:05
    and it shows you what are the red, what are the green, and what are the blue values for that color.
  • 5:05 - 5:11
    So, you can type in your values manually or you can use the color picker to set values.
  • 5:12 - 5:17
    We know now how to set the outline or the fill, the stroke or the fill of these shapes.
  • 5:17 - 5:20
    But remember, there is this canvas that we're drawing into.
  • 5:20 - 5:25
    But what if you want, actually, to fill in a color in the background?
  • 5:25 - 5:30
    So there is one more function that we are going to learn as part of this little tutorial,
  • 5:30 - 5:32
    which is "background ()".
  • 5:32 - 5:35
    So, I'm going to add that now to the code editor below, background (),
  • 5:35 - 5:39
    and I'm going to put a color in there that's a nice, soft yellow.
  • 5:39 - 5:41
    And then now we're going to run it.
  • 5:41 - 5:43
    We're going to see that yellow is the background.
  • 5:43 - 5:44
    So, why don't you take a minute, actually.
  • 5:44 - 5:48
    Try the color picker on the background, and pick a different color.
  • 5:51 - 5:53
    You're going to have to press "run your code" when you're ready.
  • 5:54 - 5:58
    Did the color you picked appear in the background? Hopefully it did.
  • 5:58 - 6:01
    OK, so this really wraps up the end of this section about color.
  • 6:01 - 6:06
    You know, what did we first do? We first learned we could put rectangles and ellipses of any size
  • 6:06 - 6:08
    anywhere on the screen.
  • 6:09 - 6:14
    Now we can assign any of them different strokes, different fills, and we can put a background color.
  • 6:14 - 6:16
    I'm going to put below an example for you to start with.
  • 6:16 - 6:19
    It's a nice design that has a bunch of shapes and a bunch of colors in it.
  • 6:19 - 6:24
    You can use this, tweak it to make your own design, or — you'll also see when this video ends —
  • 6:24 - 6:30
    there will be an option for you to revert back to your previous code that you had at the end of lesson 1.
  • 6:30 - 6:33
    So if you want to go find that creature or alien you made and start adding color to it,
  • 6:33 - 6:35
    that's what you could do for this exercise.
  • 6:35 - 6:38
    I'll talk to you later, and enjoy this exercise.
Title:
3. COLOR
Description:

These videos are designed to be viewed as part of "Hello Processing" a tutorial for code.org's Hour of Code.

http://hello.processing.org/

more » « less
Video Language:
English
odsosu edited English subtitles for 3. COLOR
odsosu edited English subtitles for 3. COLOR

English subtitles

Revisions