Lesson 9

Fill, Stroke, and Background

We’ve been able to change the color of our shapes, but did you notice that they always have a black border around them? What if we want to change that?

Luckily, there’s another function that can help us with this. It’s called stroke, and it works a lot like fill; the only difference is that it changes the color of the border instead of the center:

stroke(red, green, blue);
stroke()

Sets the color used to draw lines and borders around shapes

Learn More

So, if we wanted to make a face with red lines we might type something like this:

Code:
stroke(255,0,0);
ellipse(25,30,30,30);
ellipse(75,30,30,30);
rect(20,60,60,20);
Preview:

What if we want to change the background? Turns out there is another function for that as well, called background. It also works just like fill and stroke, but it changes the color of the entire background.

background()

The background() function sets the color used for the background of the Processing window

Learn More

So, if we wanted to make a face with a purple background, we might type something like this:

Code:
background(255,0,255);
ellipse(25,30,30,30);
ellipse(75,30,30,30);
rect(20,60,60,20);
Preview:
Next lesson Variables