Skip to docs navigation

04.03 Pixel Arrays

On this page

p5.js stores all of the pixels for the canvas in an array called pixels. Each pixel is represented by 4 index locations in the array for its red, blue, green, and alpha values. 1

The pixel number = (x + y * width) 2

Lets try from pixel #28.

  • x = 4
  • y = 3
  • width = 8
  • 4 + 3 * 8 _remember order of operations so this is 4 + (3*8)_
  • 4 + 24
  • 28
Index01234567
001234567
189101112131415
21617181920212223
32425262728293031
43233343536373839
54041424344454647
64849505152535455

References