Reference stroke()

stroke()

Sets the color used to draw points, lines, and the outlines of shapes.

Calling stroke(255, 165, 0) or stroke('orange') means all shapes drawn after calling stroke() will be filled with the color orange. The way these parameters are interpreted may be changed with the colorMode() function.

The version of stroke() with one parameter interprets the value one of three ways. If the parameter is a Number, it's interpreted as a grayscale value. If the parameter is a String, it's interpreted as a CSS color string. A p5.Color object can also be provided to set the stroke color.

The version of stroke() with two parameters interprets the first one as a grayscale value. The second parameter sets the alpha (transparency) value.

The version of stroke() with three parameters interprets them as RGB, HSB, or HSL colors, depending on the current colorMode().

The version of stroke() with four parameters interprets them as RGBA, HSBA, or HSLA colors, depending on the current colorMode(). The last parameter sets the alpha (transparency) value.

Examples

Syntax

stroke(v1, v2, v3, [alpha])
stroke(value)
stroke(gray, [alpha])
stroke(values)
stroke(color)

Parameters

v1
Number:

red value if color mode is RGB or hue value if color mode is HSB.

v2
Number:

green value if color mode is RGB or saturation value if color mode is HSB.

v3
Number:

blue value if color mode is RGB or brightness value if color mode is HSB.

alpha
Number:
value
String:

a color string.

gray
Number:

a grayscale value.

values
Number[]:

an array containing the red, green, blue, and alpha components of the color.

color
p5.Color:

the stroke color.

Notice any errors or typos? Please let us know. Please feel free to edit src/color/setting.js and open a pull request!

Related References