Colours

coloured pattern of star shape

Color Formats :

1 - Monochrome : "0" being black and "255" being white. Anything in between are the shades of grey.

fill (Monochrome(0-255))

grayscale
Example: fill (130);

2 - RGB : RGB stands for Red, Green and Blue. Red takes 0 as minimum value and 255 as maximum value anything in between are the shades of red, same is for Green(0-255) and Blue (0-255).

fill (Red(0-255), Green(0-255), Blue(0-255))

rgb colour wheel

Example: fill (255, 100, 50);

3 - Hex : Hex values are represented with a hash sign with six digits which are the combination numbers(0-7) and letters(a-f). The first set of two digits is for Red colour , second set of two digits is for Green and the third set of two digits is for Blue colour.

coloured background

Example: fill ("#f70ce5");

Three functions take in colours as their parameter background(), fill() and stroke().

Background :

coloured background coloured background coloured background

Fill :

coloured background coloured background coloured background

Alpha : value creates transparency effect when added as the fourth parameter when using RGB values for creating colour.Alpha values ranges from 0 - 255.

fill ( R, G, B, Alpha(0 - 255))

Example: fill (175, 50, 125, 10);

coloured background

Stroke :

coloured background

3D colour : For the 3D shapes in p5.js have the normalMaterial() function to give 3D colour to the shape.

coloured background

Alternative ways to give colour to a 3D shape : Use fill() and stroke() functions to give colour to the 3D shape.

coloured background coloured background

Continue Reading

Canvases

Learn More

2D shapes

Learn More

3D Shapes

Learn More