colorizeTriangle()
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.
colorizeTriangle(row0, col0, row1, col1, row2, col2, color0, [color1], [color2])
row0 | Number: vertex0 row coordinate |
col0 | Number: vertex0 col coordinate |
row1 | Number: vertex1 row coordinate |
col1 | Number: vertex1 col coordinate |
row2 | Number: vertex2 row coordinate |
col2 | Number: vertex2 col coordinate |
color0 | p5.Color : vertex0 color to be interpolated |
color1 | p5.Color : vertex1 color to be interpolated default is color0 |
color2 | p5.Color : vertex2 color to be interpolated default is color0 |