3.4 Principle 4: Colour
Knowing how to set colours is an important part of creative coding and will be crucial for your wallpaper project. On this page, you will learn how to use the fill and stroke commands to use the full colour spectrum.
By default, p5.js defines colour values using RGB (Red, Green, and Blue) as a value ranging from 0 to 255, where 0 signifies the absence of the colour and 255 represents the highest intensity of that colour. These three colours are the primary colours, from which additional colours can be created by blending these colours in varying ratios. For example, a yellow colour in RGB is created using a mix of red and green using the RGB values: 255,255,0.

In Program 4 below, click on the small rectangular box on the canvas and you should see a colour picker appear. It allows you to pick different colours and see their RGB values at the same time.
Use the colour picker to change the colour of the square a few times. Notice how the numerical RGB values change as you select different colours.
Filled colour
The fill() command allows you to set the fill colour inside shapes. You are defining three values because you are mixing the three RGB colours together to create a single fill colour fill(R, G, B):
R = red value between 0 and 255
G = green value between 0 and 255
B = blue value between 0 and 255.
(p5.js reference: fill [Tip: hold Ctrl and click a link to open it in a new tab. (Hide tip)] )
Outline colour
The stroke() command controls the outline colour of any shape, for example stroke(R, G, B) (p5.js reference: stroke).
Note that you can also use the noStroke() command to disable any stroke being drawn (p5.js reference: noStroke).

Transcript: Video 6 Changing and playing with colour
Activity 4 Recolour the squares
Use Program 5 Recolour the squares to tweak the numerical RGB colour values for the fill and outline of the squares.
Experiment with inserting mouseX or mouseY in place of the numerical RGB values as well as parameters of the squares, as shown in Video 6.