Using a method I found on Dubealex to create a gradient, I created a method that allows you to create a gradient bar using 1 or more colors.
If using 1 color, it will obviously be a solid color.
But if you use 2 or more, it will automaticly calculate the width and gradient for each section creating a gradient using all the colors you supplied in order.
class Bitmap
def grade(x,y,width,height,start,finish)
for i in 0..width
r = start.red * (width - i) / width + finish.red * i / width
g = start.green * (width - i) / width + finish.green * i / width
b = start.blue * (width - i) / width + finish.blue * i / width
a = start.alpha * (width - i) / width + finish.alpha * i / width
fill_rect(x + i,y,1,height,Color.new(r, g, b, a))
end
end
def draw_gradient(x,y,width,height,colors)
gradient_width = ((width * 1.0) / (colors.size - 1))
if colors.size == 1
grade(x,y,width,height,colors[0],colors[0])
return
end
for i in 0..(colors.size - 2)
x_var = (x + (i * gradient_width))
grade(x_var,y,gradient_width,height,colors[i],colors[i + 1])
end
end
end
I created a simple hp bar using the above script as an example -
[code]class Window_Base < Window