Sample

sample() #

Sample cell as the {r, g, b, a, total} object literal. Used by the sort algorithm. For instance LUMA sorting is implemented as follows:

// excerpt from sort
let memory1D = this.toArray();
// ...
memory1D.sort((valueA, valueB) => {
  let sa = Quadrille.sample({ value: valueA, background,
                              cellLength, textColor, textZoom });
  let sb = Quadrille.sample({ value: valueB, background,
                              cellLength, textColor, textZoom });
  let wa = 0.299 * sa.r + 0.587 * sa.g + 0.114 * sa.b;
  let wb = 0.299 * sb.r + 0.587 * sb.g + 0.114 * sb.b;
  return wa - wb;
});

Use this method to implementing other sorting criteria of the quadrille cells.

Syntax #

sample([{value, imageDisplay, colorDisplay, stringDisplay, numberDisplay, arrayDisplay, objectDisplay, background, cellLength, outlineWeight, outline, textColor, textZoom}])

Parameters #

parameterdescription
valuep5.Image | p5.Graphics | p5.Color | array | object | string | number | null: empty cells
imageDisplayFunction: image filled cell drawing custom procedure default is Quadrille.imageDisplay
colorDisplayFunction: color filled cell drawing custom procedure default is Quadrille.colorDisplay
stringDisplayFunction: string filled cell drawing custom procedure default is Quadrille.stringDisplay
numberDisplayFunction: number filled cell drawing custom procedure default is Quadrille.numberDisplay
arrayDisplayFunction: array filled cell drawing custom procedure
objectDisplayFunction: object filled cell drawing custom procedure
backgroundp5.Color: background sampling default is Quadrille.background
cellLengthNumber: cell sampling length default is quadrille width
outlineWeightNumber: edge weight default is Quadrille.outlineWeight. Use 0 to discard all edges
outlinep5.Color representation: edge color default is Quadrille.outline
textColorp5.Color: text sampling color default is Quadrille.textColor
textZoomNumber:: text zoom level default is Quadrille.textZoom