How would I make a color Gradient with linear interpolation along with Linked list?

前端 未结 1 858
醉梦人生
醉梦人生 2020-12-06 21:20

I am currently trying to make a rainbow trail that follows your mouse. i used Linkedlist to plot the points of my mouse so the trail follows along. The trail itself looks pe

相关标签:
1条回答
  • 2020-12-06 22:23

    To get the effect you want, you are probably going to have to create a custom gradient paint that spans the gamut of hue along one axis and the range of alpha transparency along the other. As a related example, this KineticModel uses a RadialGradientPaint to create an array of GradientImage instances. In each image, the alpha varies radially from 0xff (1.0) at the center to 0x3f (0.25) at the periphery.

    Addendum: Based on your picture, just set the graphics context's Stroke to a suitable width, set the paint to the next hue from your color lookup table (clut), and drawLine(). You can vary the hue, keeping the the saturation and brightness constant.

    float N = 360;
    Queue<Color> clut = new LinkedList<Color>();
    for (int i = 0; i < N; i++) {
        clut.add(Color.getHSBColor(i / N, 1, 1));
    }
    

    You'll have to decide when to change colors based on space or time. For the latter, javax.swing.Timer is a good choice.

    0 讨论(0)
提交回复
热议问题