Reputation: 1720
I'm trying to generate with code a one dimensional array of Color in java with a gradient of color, how can I do this? I also want to be able to use multiple colors in the gradient.
I want it to be sort of like this:
Upvotes: 5
Views: 2803
Reputation: 16215
Let's break this down into some generic steps:
startColor
and endColor
are. For example, perhaps they are (64, 128, 192)
and (255, 255, 255)
(191, 127, 63)
.(191/100, 127/100, 63/100)
.startColor
, applies (rounded) change to the color values each iteration, adding each new Color
to your array. At the end of your loop, the last Color
added will end up being the endColor
Voila - there's your array of Color
objects representing your gradient.
If you want, you should be able to figure out how to extend this to a multi-color gradient (red -> yellow -> green) as well, simply by creating two loops that transition to each color.
Upvotes: 7