Is it possible to make a gradient bar go backward? I have been working on this for a couple hours, but can't seem to solve it. The code I am using is:
Thanks,
Leon
EDIT: Found out how to do it. on the line:
self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
change the x + i + j to x - i + j
Code:
def draw_bar(x, y, min, max, width = 152, height = 6,
bar_color = Color.new(60, 130, 60, 255), end_color = Color.new(180, 250, 180, 255))
for i in 0..height
self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
end
for i in 1..(height - 1)
r = 100 * (height - i) / height + 0 * i / height
g = 100 * (height - i) / height + 0 * i / height
b = 100 * (height - i) / height + 0 * i / height
a = 255 * (height - i) / height + 255 * i / height
self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
end
for i in 1..( (min.to_f / max.to_f) * width - 1)
for j in 1..(height - 1)
r = bar_color.red * (width - i) / width + end_color.red * i / width
g = bar_color.green * (width - i) / width + end_color.green * i / width
b = bar_color.blue * (width - i) / width + end_color.blue * i / width
a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
end
end
end
Thanks,
Leon
EDIT: Found out how to do it. on the line:
self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
change the x + i + j to x - i + j