Star

Created With

linkcolorizeTriangle()

Colorize the triangle defined by vertices (vertex0=) (row0, col0), (vertex1=)(row1, col1), and (vertex2=)(row2, col2), using barycentric coordinates to interpolate color0, color1 and color2. Implemented as:

1linkcolorizeTriangle(row0, col0, row1, col1, row2, col2, color0, color1 = color0, color2 = color0) {

2link this.rasterizeTriangle(

3link row0, col0, row1, col1, row2, col2,

4link ({ pattern: xyza }) => color(xyza), // --> software "fragment shader" colorizes the (row0, col0), (row1, col1), (row2, col2) triangle

5link // vertex attributes to be interpolated (each encoded as an array):

6link [red(color0), green(color0), blue(color0), alpha(color0)], // --> vertex0 color

7link [red(color1), green(color1), blue(color1), alpha(color1)], // --> vertex1 color

8link [red(color2), green(color2), blue(color2), alpha(color2)] // --> vertex2 color

9link );

10link}

Refer to rasterizeTriangle() when in need to interpolate other vertex data.

linkSyntax

colorizeTriangle(row0, col0, row1, col1, row2, col2, color0, [color1], [color2])

linkParameters

row0Number: vertex0 row coordinate
col0Number: vertex0 col coordinate
row1Number: vertex1 row coordinate
col1Number: vertex1 col coordinate
row2Number: vertex2 row coordinate
col2Number: vertex2 col coordinate
color0p5.Color : vertex0 color to be interpolated
color1p5.Color : vertex1 color to be interpolated default is color0
color2p5.Color : vertex2 color to be interpolated default is color0
colorizeTriangle()SyntaxParameters

Home

p5.js functionschevron_right

Properties

I/Ochevron_right
Boolean operatorschevron_right
Geometry transformationschevron_right
Visual computingchevron_right
Other representationschevron_right

Demo