We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Subject says it all. I'd like to draw a line that gradually changes color from one end to the other.
I'm thinking I should avoid points/pixels because I want the line to look smooth and when I zoom in on a line that's been drawn with smooth(), it looks complicated to replicate. I made a rough pass at drawing shorter and shorter lines (first line is full length at one color, then as they get shorter I lerpColor() the colors), .... but they didn't come out all that smooth.
Thanks for any suggestions-
Answers
I just tried out placing some number of line segments using the parametric line equation but unfortunately it causes the overall line segment to look a bit wiggly sometimes. From a math point of view, the values should be correct, but I'm guessing that some kind of rounding does not agree with Processing's built-in lines:
Edit: The rounding problem may be avoidable by using your own line function instead of Processing's built-in one.
I think lerpColor() is a very useful method for this. Another good solution may be to use the P2D renderer and per-vertex colors of a beginShape-endShape. Then OpenGL will take care of the color interpolation. Of course lerpColor() could be used then as well to determine the colors for each vertex.
Here is an example using lerpColor on line segments:
I used a bunch of circles with 1 pixel spacing between each! No openGL graphics card is required. I have had no issues with speed on my processor(an Intel Centrino). use drawRainbow() like line, except that the fifth parameter specifies the speed of the rainbow, 64 being one repeat and higher// use rainbowWeight() like strokeWeight(). code is as follows:
@processingRGB, that actually does not place one circle per pixel, it places 1000 circles no matter what. Try drawing a line that is 10000 units across and you'll see gaps.
The resulting line is very smooth though, I tried making another sketch that uses code from the ones posted here:
Thanks for this! The code that @asimes posted works perfectly.