This shows an example of how to create a two-color gradient along a THREE.js line:
Color Gradient for Three.js line
How do you implement a multi-stop color gradient along a line? It looks like attributes will only interpolate across two values (I tried passing in three, it only worked with the first two values).
This is the do-it-yourself color gradient approach:
Create a line geometry and add some vertices:
Use some helper functions for convenience:
jsfiddle: http://jsfiddle.net/L0rdzbej/276/
Explaination:
getColoredBufferLine
creates a new buffer geometry from the geometry, which is just for convenience. It then iterates the vertices, assigning each vertex a color. The color is calculated using another helper:color.set ( makeColorGradient( i, frequency, phase ) );
.Where basically
frequency
defines how many color changes you want the line to receive.And
phase
is a shift of the color spectrum (= what color does the line start with).I have added a dat.gui so you can play around with the parameters. If you want to change the color repetition or type, you can alter the
makeColorGradient
function to your needs. This page offers some good explaination how gradients are generated and where my example is based upon: http://krazydad.com/tutorials/makecolors.php.