All pastes #10056 Raw Edit

RMXP Gradient Bars

public ruby v1 · immutable
#10056 ·published 2005-04-22 01:43 UTC
rendered paste body
class Window_Base  alias draw_actor_hp_original draw_actor_hp  def draw_actor_hp(actor, x, y, width = 144, height = 15)    bg = Color.new(  0,   0,   0, 160)    c1 = Color.new(255,   0,   0, 0)    c2 = Color.new(255, 255,   0, 160)    self.contents.fill_rect(x, y, width, height, bg)    width2 = width * actor.hp / actor.maxhp    gradient(x + 1, y + 1, width2 - 2, height - 2, c1, c2)    draw_actor_hp_original(actor, x, y, width)  end  alias draw_actor_sp_original draw_actor_sp  def draw_actor_sp(actor, x, y, width = 144, height = 15)    bg = Color.new(  0,   0,   0, 160)    c1 = Color.new(  0,   0, 255, 0)    c2 = Color.new(  0, 255, 255, 160)    self.contents.fill_rect(x, y, width, height, bg)    width2 = width * actor.sp / actor.maxsp    gradient(x + 1, y + 1, width2 - 2, height - 2, c1, c2)    draw_actor_sp_original(actor, x, y, width)  end  def gradient(x, y, width, height, c1, c2)    for i in 1..width      x2 = x + i - 1      r = c1.red * (width - i) / width + c2.red * i / width      g = c1.green * (width - i) / width + c2.green * i / width      b = c1.blue * (width - i) / width + c2.blue * i / width      a = c1.alpha * (width - i) / width + c2.alpha * i / width      self.contents.fill_rect(x2, y, 1, height, Color.new(r, g, b, a))    end  endend