AbyssalLord
Member
# The length and height of the bar to be drawn.
bar_length, bar_height = 64, 8
# The colors to interpolate between.
color_left, color_right = Color.new(0,0,0), Color.new(255,0,0)
# Our sprite and bitmap object so we actually see something.
@test = Sprite.new
@test.bitmap = Bitmap.new(bar_length, bar_height)
# Loop through the bar 1 column at a time.
for i in 0...bar_length
# The percentage of the color to use from color_right.
right = i / bar_length.to_f
# The percentage of the color to use from color_left.
left = 1.0 - right
# Decide the color to draw at this particular column
color = Color.new(color_left.red * left + color_right.red * right,
color_left.green * left + color_right.green * right,
color_left.blue * left + color_right.blue * right)
# Draw the column of pixels with our interpolated color.
@test.bitmap.fill_rect(i, 0, 1, bar_height, color)
end
bar_length, bar_height = 64, 8
color_left, color_right = Color.new(0,0,0), Color.new(255,0,0)
@test = Sprite.new
@test.bitmap = Bitmap.new(bar_length, bar_height)
for i in 0...bar_length
right = i / bar_length.to_f
left = 1.0 - right
color = Color.new(color_left.red * left + color_right.red * right,
color_left.green * left + color_right.green * right,
color_left.blue * left + color_right.blue * right)
@test.bitmap.fill_rect(i, # The current column of pixels.
0, # The starting position of y to draw our column
1, # The width of the column, in this case 1
bar_height, # The height of the bar.
color) # The color of the column of pixels.
AbyssalLord":10puxa0n said:Ok, thanks khmp, that makes a lot more sense. I have one more question though. What do you mean by repeat the process? Do it over and over again? Loop?
Sounds tedious...of course, I may just be confused...
for i in 0..3
end # Then repeat