Rasterize

rasterize() #

Rasterize quadrille according to upper-left corner vertex array0, bottom-left corner vertex array1, upper-right corner vertex array2, and bottom-right corner vertex array3, using (fragment) shader. Call rasterizeTriangle() on the two non-overlapping triangles entirely covering the quadrille.

Example #

code
const ROWS = 20;
const COLS = 20;
const LENGTH = 20;
let quadrille;

function setup() {
  createCanvas(COLS * LENGTH, ROWS * LENGTH);
  quadrille = createQuadrille(20, 20);
  quadrille.rasterize(colorizeShader,
                      [255, 0, 0],
                      [0, 255, 0],
                      [0, 0, 255],
                      [255, 255, 0]);
}

function draw() {
  drawQuadrille(quadrille, { cellLength: LENGTH, outline: 'green' });
}

function colorizeShader({ array: rgb }) {
  return color(rgb);
}

Syntax #

rasterize(shader, array0, [array1], [array2], [array3])

Parameters #

parameterdescription
shaderFunction: taking { array: interpolated_data_array, row: i, col: j } params and returning a p5.Color
array0Array: corner0 attributes to be interpolated
array1Array: corner1 attributes to be interpolated default is array0
array2Array: corner2 attributes to be interpolated default is array0
array3Array: corner3 attributes to be interpolated default is array0