0
$\begingroup$

I need to draw some shapes filled with linear gradients starting from every point and blending smoothly between points, like an OpenGL standard shading (I guess it is called GL_LINEAR or VERTEX_COLOR), i.e. GIMP / Illustrator / Krita / Paint3D, etc. Something fast and simple.
required result:
enter image description here

$\endgroup$
1
$\begingroup$

Most 2D graphics programs are able to do linear gradients with arbitrary orientations. If you don't mind a little work, it is possible to set this up to imitate the 2D linear interpolation across a triangle.

Set up two layers:

  • Pick two of the colors, say red and green, and set up a linear gradient between those two colors along the red-green edge.
  • In a second layer, set up a linear gradient between blue and transparent-blue (i.e. the same color with alpha = 0). Orient it perpendicular to the red-green edge.
$\endgroup$
2
  • $\begingroup$ you've forgot to mention that i also need to account for the length of the edges in cases when the triangle is not regular $\endgroup$
    – ivan866
    Oct 20 '20 at 20:10
  • 1
    $\begingroup$ Not sure what you mean. If you put the linear gradient vertices at the right spots everything should be taken care of $\endgroup$ Oct 20 '20 at 20:15
0
$\begingroup$

a quick working wrapper for OpenGL from R:

require(rgl)
tr.points <- matrix(c(1,0,0, cos(60/180*pi),sin(60/180*pi),0, 0,0,0),
                    ncol=3, byrow=TRUE)
triangles3d(tr.points, col=c('red', 'green', 'blue'),
            lit=FALSE, smooth=TRUE, textype='rgb',
            lwd=1.0,
            depth_mask=TRUE, depth_test='always')
rgl.viewpoint(theta=0, phi=0,
              fov=0, zoom=1,
              interactive=FALSE)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.