Reference set()

set()

Sets the color of a pixel or draws an image to the canvas.

set() is easy to use but it's not as fast as pixels. Use pixels to set many pixel values.

set() interprets the first two parameters as x- and y-coordinates. It interprets the last parameter as a grayscale value, a [R, G, B, A] pixel array, a p5.Color object, or a p5.Image object. If an image is passed, the first two parameters set the coordinates for the image's upper-left corner, regardless of the current imageMode().

updatePixels() must be called after using set() for changes to appear.

Examples

Syntax

set(x, y, c)

Parameters

x
Number:

x-coordinate of the pixel.

y
Number:

y-coordinate of the pixel.

c
Number|Number[]|Object:

grayscale value | pixel array | p5.Color object | p5.Image to copy.

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

Related References